Skip to content

TensorFlow

A powerful library used for Deep Learning. It is one of the most popular tools for Machine Learning.


TensorFlow has a simple and user-friendly API. TensorFlow has language bindings available for Python, Java, JavaScript, C++ and many others.

Using TensorFlow on the HPC#

There are two ways to use TensorFlow on the HPC systems:

  1. Use the installation provided with the pre-installed Anaconda distribution
  2. Install in your home directory using conda

Using the default TensorFlow provided with Anaconda#

To use the default TensorFlow that is installed with Anaconda, load the Anaconda module, and then import the TensorFlow Python module into your app code:

In the shell and/or submit script:

$ module load anaconda

In Python:

1
2
3
import tensorflow as tf

# ... your code here ...

Installing TensorFlow in your home directory using conda#

You can install TensorFlow in your home directory without any administrative privileges using Conda. This provides the benefit of being able to run the latest version TensorFlow and keep it up-to-date.

Warning

In order to install TensorFlow in your home directory, you must have already configured your shell for conda using the conda init command. If you haven't already done so, please see our instructions for how to intialize conda.

Then, follow the instructions below.

1
2
3
4
5
6
7
8
# Create conda environment
$ conda create -n tf_app

# Activate conda environment
$ conda activate tf_app

# Install TensorFlow
$ conda install tensorflow

Running TensorFlow on GPUs#

The version of TensorFlow on the HPC systems includes support for GPU devices and CUDA. For detailed information about GPU resources available on our systems, and which Slurm Accounts provide GPU access, refer to our GPU documentation page.

For a detailed guide on how to program TensorFlow code for GPUs, refer to the official documentation.

When submitting a GPU job for TensorFlow on the HPC, you must include the cuda module.

Example GPU job using built-in Anaconda#

#!/bin/bash

#SBATCH -A backfill2   # Submit to backfill2 (note, this account has a four-hour walltime limit)
#SBATCH -n 12          # Request resources for 12 tasks
#SBATCH --gres=gpu:1   # Request a single GPU card

module load cuda
module load anaconda

srun python MYCODE.py

Example GPU job using conda-installed environment#

#!/bin/bash

#SBATCH -A backfill2   # Submit to backfill2 (note, this account has a four-hour walltime limit)
#SBATCH -n 12          # Request resources for 12 tasks
#SBATCH --gres=gpu:1   # Request a single GPU card

module load cuda
conda activate tf_app      # Substitute your conda environment for 'tf_app'

srun python MYCODE.py