TensorFlow for GPUs
Introduction
TensorFlow is an open-source software library and end-to-end platform developed by Google for machine learning and artificial intelligence. Originally released in 2015, it is widely used to build, train, and deploy deep neural networks across a variety of hardware environments.
Installing TensorFlow with GPU support
Before submitting a job using TensorFlow in our V100 GPU partition (Matador), make sure TensorFlow is properly installed in a conda environment (preferably) and that it can detect the physical GPU devices.
Step 1:
Log in to login.hpcc.ttu.edu and start an interactive session to the gpu-build partition.
# Interactive session with 4 cores dedicated to you
interactive -c 4 -p gpu-build
The gpu-build partition mimics Matador and is set up for GPU/CUDA testing and development purposes.
Please make sure no Python module is loaded before proceeding to the next step to avoid conflicts.
Step 2:
Have conda/miniconda installed and ready. Further instructions for installing conda on HPCC resources can be found at this link.
Step 3:
Create a conda environment and install TensorFlow:
conda create --name tf-gpu -c conda-forge tensorflow-gpu
conda activate tf-gpu
The commands above will create a new Conda environment with the latest version of TensorFlow-gpu available in the condo. Alternatively, you can specify the the exact version of Tensorflow you want to use, as follows:
conda create --name tf-gpu -c conda-forge tensorflow-gpu=<version> \
cudatoolkit=<version> cudnn=<version> python=<version>
conda activate tf-gpu
You will need to replace the <version> with in the first command above. Please note that the versions of cudatoolkit, cudnn
and python have to be compatible with the version of the TensorFlow and I chose them
very carefully. (Please check version compatibility here)
Note:
- Installing
tensorflow-gpuin Conda will also installcudatoolkit, making the installation independent of the default CUDA version available on the partition.- The latest CUDA version supported by the Matador partition is 12.x.
Step 4:
Test whether the installed TensorFlow can detect GPUs:
python3 <<'EOF'
import tensorflow as tf
gpus = tf.config.list_physical_devices("GPU")
print("Num GPUs Available:", len(gpus))
EOF
If you see at least one available GPU device in the output, your TensorFlow GPU installation is working.
Running TensorFlow On GPUs:
Submitting a TensorFlow job to Matador
Create a job submission script with the following content as a reference:
#!/bin/bash
#SBATCH --job-name=tensr_job
#SBATCH --output=%x.o%j
#SBATCB --error=%x.e%j
#SBATCH --partition=matador
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=40
#SBATCH --time=10:00:00
#SBATCH --gpus-per-node=2
. $HOME/conda/etc/profile.d/conda.sh
conda activate tf-gpu
python my_tf_model.py
Then submit this job using the sbatch command. Please make sure to edit:
- Number of GPUS (
--gpu-per-node): If your code works efficiently with 2 GPUs, leave it as it is. Otherwise, please set the number of GPUs to 1 and the number of tasks per node (--ntasks-per-node) to less then 20 to allow other jobs to run on the node. - Wall time (
--time): If your job wont take longer than 10 hours, leave it as it is. Adjust the wall time based on how long you estimate your job will take.
Please contact HPCC support at hpccsupport@ttu.edu if you have any questions.
High Performance Computing Center
-
Phone
806.742.4350 -
Email
hpccsupport@ttu.edu