Thank you for answering to the question.
yes the actual issue is first one.
and this is not working correctly using os.environ call.
the program worked well with second case. If I specify available gpus with torch.device(), it worked well and can see it is allocated well when I see nvidia-smi.
I am curious why sometimes os.environ call do not work in pytorch program
I am sorry for changing the word.
when I tried
CUDA_VISIBLE_DEVICES=4 python script.py again
I can see certain gpu is allocated well…
(I saw… setting CUDA_VISIBLE_DEVICES in terminal didn’t work …and couldn’t find the answer here and that’s why I made new question
but now maybe I need to change the question or delete it)
can I ask you why os.environ does not work in some cases?
I put this on top of the code (after importing) before main function and until now it worked well.
after I declared visible devices with os.environ.
[object].cuda() was allocated well with visible devices.
but for this program, it keeps assigning to only first gpu when I use [object].cuda()