select a specific GPU to use in jupyter notebook
I'm coding on a .ipynb file on a linux server.
The linux server I use has multiple GPUs on it, but I should only use idle GPU so as not to accidentally abort others' programme.
I've already known that for common .py file we can add some instructions at the command line to choose a common GPU(e.g. export CUDA_VISIBLE_DEVICES=#), but will it work for jupyter notebook? If not, how can I specify a GPU to work on.

You have to choose its name correctly. For instance there may be 3 GPU devices available namely &quot;cuda:0&quot;,&quot;cuda:1&quot;,&quot;cuda:2&quot;. To choose the third one you need to run the following code:
if torch.cuda.is_available():
  dev = &quot;cuda:2&quot;
else:
  dev = &quot;cpu&quot;
device = torch.device(dev)

