Passer au contenu principal

Deep Learning

The training phase of your deep learning model may be very time consuming. To accelerate this process you may want to use GPUs and you will need to install the deep learning packages, such as Keras or PyTorch, properly. Here is a short documentation on how to install some well knowns deep learning packages in Python. If you encounter any problem during the installation or of you need to install other deep learning packages, please send an email to helpdesk@unil.ch with subject DCSR: Deep Learning package installation, and we will try to help you.

Keras

To install the packages in your home directory:

cd $HOME

Log into a GPU node:

Sinteractive -p interactive -m 4G -G 1

Check that the GPU is visible:

nvidia-smi

Load parallel modules and python:

module purge
module load gcc cuda cudnn python/3.8.8

Create a virtual environment. Here we will call it "venv_keras", but you may choose another name:

virtualenv -p python venv_keras

Activate the virtual environment:

source venv_keras/bin/activate

Install TensorFlow and Keras:

pip install tensorflow
pip install keras

Check that Keras was properly installed:

python -c 'import keras; print(keras.__version__)'

There might be a warning message and the output should be something like "2.5.0".

You may install extra packages that you deep learning code will use. For example:

pip install sklearn
pip install pandas
pip install matplotlib

Deactivate your virtual environment and logout from the GPU node:

deactivate
exit

Comment

If you want to make your installation more reproducible, you may proceed as follows:

1. Create a file called "requirements.txt" and write the package names inside. For example:

tensorflow==2.4.1
keras==2.4.0
sklearn==0.24.2
pandas==1.2.4
mathplotlib==3.4.2

2. Proceed as above, but instead of installing the packages individually, type 

pip install -r requirements.txt

Run your deep learning code

To test your deep learning code (maximum 1h), say "my_deep_learning_code.py", you may use the interactive mode:

cd /scratch/username/

Sinteractive -p interactive -m 4G -G 1

module load gcc cuda cudnn python/3.8.8

source $HOME/venv_keras/bin/activate

python

import keras

Once you have finished testing your code, you may send it over the cluster by using an "sbatch" script, say "my_sbatch_script.sh":

#!/bin/bash -l
#SBATCH --account your_account_id
#SBATCH --mail-type ALL
#SBATCH --mail-user firstname.surname@unil.ch

#SBATCH --workdir /scratch/username/
#SBATCH --job-name my_deep_learning_job
#SBATCH --output my_deep_learning_job.out

#SBATCH --partition gpu
#SBATCH --gres gpu:1
SBATCH --gres-flags enforce-binding
#SBATCH --nodes 1
#SBATCH --ntasks 1
#SBATCH --cpus-per-task 1
#SBATCH --mem 10G
#SBATCH --time 01:00:00

module load gcc cuda cudnn python/3.8.8

source $HOME/venv_keras/bin/activate
python my_deep_learning_code.py

To launch your job:

sbatch my_sbatch_script.sh

TensorFlow

The installation of TensorFlow is the same as for Keras (except that you do not need to install Keras), so please look at the above Keras installation documentation.

PyTorch