Great answer !!! It helps me a lot.
CUDA_VISIBLE_DEVICES=3 python test.py
and it doesn’t work for me.
export CUDA_VISIBLE_DEVICES=3 python test.py
does work for me.
The following works properly.
import os os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" os.environ["CUDA_VISIBLE_DEVICES"]=<YOUR_GPU_NUMBER_HERE>
Usually GPU numbers start from 0. Since you have issue with the default device, try anything other that 0.
Thanks a lot for this solution!
Thank you, life saver
Just want to add to this answer, this environment variable should be set at the top of the program ideally. Changing the
CUDA_VISIBLE_DEVICES var will not work if it is called after setting
This might also be true for other torch/cuda related calls as well so it’s better to set the environment vars at the program start or use
export CUDA_VISIBLE_DEVICES="NUM" before starting the program.