Neural network training with TensorFlow on CPU

From ScientificComputing
Revision as of 14:24, 8 December 2020 by Jarunanp (talk | contribs)

Jump to: navigation, search

Load Python with TensorFlow module

We will use the new software stack in this tutorial:

 $ env2lmod  

Load the Python module which contains TensorFlow 2.0.0 package

 $ module load gcc/6.3.0 python/3.7.4 hdf5
 The following have been reloaded with a version change:
   1) gcc/4.8.5 => gcc/6.3.0

Check if we could import the TensorFlow package

 $ python -c "import tensorflow as tf; print(tf.__version__)"

To run on CPU only, define the number of threads in the environment variable OMP_NUM_THREADS, for example, we would like to run here on 4 processors.

 $ export OMP_NUM_THREADS=4

The value of this environment variable is then used to configure the threading in a TensorFlow script:

 nthreads = int(os.environ['OMP_NUM_THREADS'])

These two lines are already included in our example script

Create a neural network model

The script contains a neural network model which is trained on MNIST dataset. This example is taken from TensorFlow beginner tutorials.

Submit a batch job

Submit a job to the compute node

 $ bsub -n 4 -W 01:00 python
 Generic job.
 Job <153279665> is submitted to queue <normal.4h>.

Check the job status

 $ bjobs
 153279665  jarunan PEND  normal.4h  eu-login-02             *  Nov 25 14:12