Tensorflow

TensorFlow is a open-source machine learning framework mainly developed by Google. It can be used for verious machine learning tasks, e.g. deep learning. TensorFlow provides a high level API in python and other languages and it can run on CPUs as well as GPUs.

Installing TensorFlow

It is recommended to use Conda to create a virtual python environment and install the desired version of tensorflow within that environment.

module load miniforge3
conda create -n myenv python=3.12
source activate myenv
python3 -m pip install 'tensorflow[and-cuda]'

If you do not want to use GPUs simply use python3 -m pip install tensorflow-cpu

Testing the installation

To run TensorFlow on GPUs, load the correct modules and submit a job to the gpu partition.

#!/bin/bash
#SBATCH -p scc-gpu
#SBATCH -t 1
#SBATCH --gpus-per-node 1
 
module load miniforge3

source activate myenv
 
python tftest.py
import tensorflow as tf
print("TensorFlow version:", tf.__version__)

for x in tf.config.list_physical_devices('GPU'):
    print(tf.config.experimental.get_device_details(x))

And then submit the job using Slurm:

sbatch jobscript.sh

The output file (slurm-{jobid}.out ) should contain:

TensorFlow version: 2.19.0
{'compute_capability': (7, 0), 'device_name': 'Tesla V100S-PCIE-32GB'}

and also information about the GPUs selected.

Testing CPU only installation

If you want to test a CPU only installation, you can just run the tftest.py on a login node.

Using Tensorflow

You can now use TensorFlow in your python scripts. Please read gpu_selection for more information about GPU usage.