Skip to content

TensorFlow

TensorFlow

TensorFlow is a free and open-source software library for dataflow and differentiable programming across a range of tasks. It is a symbolic math library, and is also used for machine learning applications such as neural networks.

Usage

Environment modules

To set the environment ready for TensorFlow you need to load its modulefile:

$ module load TensorFlow

You can list all available versions with Lmod's spider option:

$ module spider TensorFlow
------------------------------------------------------
  TensorFlow: TensorFlow/2.1.0-mkl_py37h80a91df_0
------------------------------------------------------

    This module can be loaded directly: 

    module load TensorFlow/2.1.0-mkl_py37h80a91df_0

    Help:

      Description
      ===========
      An open-source software library for Machine Intelligence


      More information
      ================
       - Homepage: https://www.tensorflow.org
Batch script for Torque: TensorFlow
#!/bin/bash
#SBATCH --qos=regular
#SBATCH --job-name=TensorFlow_job
#SBATCH --mem=200gb
#SBATCH --cpus-per-task=1
#SBATCH --nodes=1
#SBATCH --gres=gpu:p40:1
#SBATCH --ntasks-per-node=1
#SBATCH --output=%x-%j.out
#SBATCH --error=%x-%j.err

module load TensorFlow

python tensorflow_program.py

Conda environments

Instead of loading the TensorFlow module, you can also use the conda environment directly.

Batch script for Torque: TensorFlow with conda envs
#!/bin/bash
#SBATCH --qos=regular
#SBATCH --job-name=TensorFlow_job
#SBATCH --mem=200gb
#SBATCH --cpus-per-task=1
#SBATCH --nodes=1
#SBATCH --gres=gpu:p40:1
#SBATCH --ntasks-per-node=1
#SBATCH --output=%x-%j.out
#SBATCH --error=%x-%j.err

module load Python
conda activate tensorflow-2.1.0-mkl_py37h80a91df_0 

python tensorflow_program.py 

Singularity

You can also pull the latest GPU enabled Docker image and run it with Singularity.

Batch script for SLURM: TensorFlow with Singularity
#!/bin/bash
#SBATCH --qos=regular
#SBATCH --job-name=TensorFlow
#SBATCH --cpus-per-task=1
#SBATCH --gres=gpu:p40:1
#SBATCH --mem=40gb
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1

# Load the Singularity  module (you might want to specify the version)
module load Singularity

# Pull the reference TensorFlow image from Docker hub
singularity pull docker://tensorflow/tensorflow:latest-gpu

# Run the TensorFlow container
singularity exec --nv tensorflow-latest-gpu.simg python your-tf-model.py