Yun_Lee:

I am curious why sometimes os.environ call do not work in pytorch program


If I understand you correctly, setting CUDA_VISIBLE_DEVICES in the terminal works correctly, but doesn’t work if you try to set it inside the script via os.environ.
This is a commonly met issue, if you are not making sure that the env var is set before importing any CUDA related libraries, which is why I’m recommending to set it in the terminal.