How to change the default device of GPU? device_ids[0]

Great answer !!! It helps me a lot.

I tried

CUDA_VISIBLE_DEVICES=3 python test.py

and it doesn’t work for me.

But

export CUDA_VISIBLE_DEVICES=3
python test.py

does work for me.

@lynnea718
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!