VS Code and Jupyter with GPU
This is a quick guide on how to combine slurm on the PICSL GPU workstations with VSCode and Jupyter. We should all switch to working this way to ensure that GPUs are shared fairly and consistently.
Login to one of the lambda machines and use a terminal manager like
tmuxorscreento ensure a permanent sessionYou should always use slurm to request GPU on the lambda machines
srun --gres gpu:1 --nodelist lambda-picsl --pty /bin/bash # if you want to land on a particular machine
srun --gres gpu:1 --pty /bin/bash # if you don’t care which machine
After this, you will get a terminal to the machine you requested, and
CUDA_VISIBLE_DEVICESwill be setSelect your conda environment and run the Jupyter server (you may need a unique port):
conda activate myenv
$CONDA_ROOT/bin/jupyter notebook --no-browser --port 8891
The notebook server will start and print a URL. Copy the
http://127.0.0.1…URL to clipboardConnect to the machine using VSCode SSH mode <https://code.visualstudio.com/docs/remote/ssh>.
Open/create a
.ipynbfileWhen selecting a Kernel, choose ‘Existing Jupyter Kernel’ and paste your URL
PyTorch should respect the setting of
CUDA_VISIBLE_DEVICESwhen you set the device to cudaNow you can run your notebook, and if you lose connection, you can reconnect to the running kernel with its state preserved.