I believe this problem is Windows specific, as I have run the same test on Ubuntu 18.04 without problem.
os.environ['CUDA_VISIBLE_DEVICES'] = '', torch still uses CUDA GPU.
RuntimeError: No CUDA GPUs are available with the following command:
python -c "import os; os.environ['CUDA_VISIBLE_DEVICES']=''; import torch; torch.randn(5).cuda()"
However, the command exists without error.
On the other hand, setting CUDA_VISIBLE_DEVICES in
cmd works properly:
set CUDA_VISIBLE_DEVICES="" & python -c "import torch; torch.randn(5).cuda()" -> RuntimeError: No CUDA GPUs are available
Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
The problem occurred to me when I tried pytest’s
os.putenv directly which seems to be used internally by
os.environ, still unsuccessful.
Then I followed through Python on Windows documentation without solution.
I found no help on PyTorch Windows FAQ either.