TensorFlow is an end-to-end open source platform for machine learning. It has a comprehensive, flexible ecosystem of tools, libraries and community resources that lets researchers push the state-of-the-art in ML and developers easily build and deploy ML powered applications.
As TensorFlow leverages GPU, it is available in the 'allnodes' optimization tree. Use the 'module avail' command to see the current list of versions (Output from 4 Nov 22):
----------------------- /usr/local/easybuild_allnodes/modules/all -----------------------
TensorFlow/2.6.0-foss-2021a-CUDA-11.3.1 TensorFlow/2.7.1-foss-2021b-CUDA-11.4.1 (D)
Copy the python script "mnist.py" from /usr/local/doc/TENSORFLOW/ to your home directory. It is adapted from TensorFlow 2 quickstart for beginners.
cp /usr/local/doc/TENSORFLOW/mnist.py .
Request an appropriate GPU node. In this sample, gpu2v100 is used
srun -p gpu -C gpu2v100 --gres=gpu:1 --mem=8gb --pty bash
Load Python module if you have not already loaded it along with appropriate CUDA and cuDNN modules.
module load TensorFlow/2.7.1-foss-2021b-CUDA-11.4.1
Run Python script:
python mnist.py
output:
9 MB memory: -> device: 0, name: Tesla V100-PCIE-32GB, pci bus id: 0000:3b:00.0, compute capability: 7.0
Epoch 1/5
1875/1875 [==============================] - 3s 1ms/step - loss: 0.2964 - accuracy: 0.9145
Epoch 2/5
1875/1875 [==============================] - 2s 1ms/step - loss: 0.1416 - accuracy: 0.9580
Epoch 3/5
1875/1875 [==============================] - 2s 1ms/step - loss: 0.1071 - accuracy: 0.9675
Epoch 4/5
1875/1875 [==============================] - 2s 1ms/step - loss: 0.0870 - accuracy: 0.9731
Epoch 5/5
1875/1875 [==============================] - 2s 1ms/step - loss: 0.0742 - accuracy: 0.9769
313/313 - 0s - loss: 0.0733 - accuracy: 0.9777 - 413ms/epoch - 1ms/step
For batch submission, follow the instruction at HPC Batch & Interactive Job submission, and be aware of the specifics of Working with Modules on Pioneer
Please visit our HPC Guide to Singularity.
Tensorflow can also be installed using python virtual environment and pip install.
The instruction is given on this page: https://www.tensorflow.org/install/pip
If you want to run tensorflow with GPU, you would need to install it on a GPU node
srun -p gpu --gres=gpu:1 --mem=16gb --pty bash
nvidia-smi
module load Python
python3 -m venv tf
source tf/bin/activate
pip install --upgrade pip
# For GPU users
pip install tensorflow[and-cuda]
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
The last part of the output:
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]