Installing TensorFlow
Setting up a GPU-accelerated environment can be challenging due to driver dependencies, version conflicts, and other complexities. Apptainer simplifies this process by encapsulating all these details
Apptainer Using NGC Containers (Our #1 Recommendation)
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
Build the container:
apptainer build tensorflow-24.03-tf2-py3.simg docker://nvcr.io/nvidia/tensorflow:24.03-tf2-py3This will take some time, and once it completes you should see a .simg file.
Working with Apptainer images requires lots of storage space. By default Apptainer will use ~/.apptainer as a cache directory which can cause you to go over your Home quota.
export APPTAINER_CACHEDIR=/tmp
export APPTAINER_TMPDIR=/tmpOnce the container is ready, request an interactive session with a GPU
interact -q gpu -g 1 -f ampere -m 20g -n 4Run a container wih 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.simgthe --nv flag is important. As it enables the NVIDA sub-system
Or, if you're executing a specific command inside the container:
Make sure your Tensorflow image is able to detect GPUs
If you need to install more custom packages, the containers itself are non-writable but we can use the
--userflag to install packages inside.localExample:
Slurm Script:
Here is how you can submit a SLURM job script by using the srun command to run your container. Here is a basic example:
Last updated
Was this helpful?