Example Container (TensorFlow)

There are multiple ways to install and run TensorFlow. Our recommended approach is via NGC containers. The containers are available via NGC Registry. In this example we will pull TensorFlow NGC container

  1. Build the container:

apptainer build tensorflow-24.03-tf2-py3.simg docker://nvcr.io/nvidia/tensorflow:24.03-tf2-py3

This process will take some time, and once it completes, you should see a .simg file.

  1. Once the container is ready, request an interactive session with a GPU:

interact -q gpu -g 1 -f ampere -m 20g -n 4
  1. To run a container with GPU support:

export APPTAINER_BINDPATH="/oscar/home/$USER,/oscar/scratch/$USER,/oscar/data"
# Run a container with GPU support
apptainer run --nv tensorflow-24.03-tf2-py3.simg
  1. Or, if you're executing a specific command inside the container:

# Execute a command inside the container with GPU support
$ apptainer exec --nv tensorflow-24.03-tf2-py3.simg nvidia-smi
  1. Make sure your Tensorflow image is able to detect GPUs

$ python
>>> import tensorflow as tf
>>> tf.test.is_gpu_available(cuda_only=False, min_cuda_compute_capability=None)
True
  1. If you need to install additional custom packages, note that the containers themselves are non-writable. However, you can use the --user flag to install packages inside .local. For example:

Slurm Script:

Here's how you can submit a SLURM job script using the srun command to run your container. Below is a basic example:

Last updated

Was this helpful?