Torch. Cuda. Is_Available() Keeps Switching to False
I Have Tried Several Solutions Which Hinted at What to Do When the Cuda Gpu Is Available and Cuda Is Installed but the Torch. Cuda. Is_Available() Returns...
I have tried several solutions which hinted at what to do when the CUDA GPU is available and CUDA is installed but the Torch.cuda.is_available() returns False. They did help but only temporarily, meaning torch.cuda-is_available() reported True but after some time, it switched back to False. I use CUDA 9.0.176 and GTX 1080. What should I do to get the permanent effect?
I tried the following methods:
Note: When torch.cuda.is_available() works fine but then at some point switches to False, then I have to restart the computer and then it works again (for some time).
3 Answers
Also with torch.cuda.is_available () had false.
But when installing the Nvidia driver to the most updated version 436.48, True is displayed. I previously updated Pytorch to 1.2.0.
I have windows 10 and Anaconda.
- Install CUDA 9.1 using apt-get, following the instructions in this link:
Installed PyTorch using pip:
pip install torchvision ( this will install both torch and torchvision )Rebooted
Now try it:
~$ python -c 'import torch; print torch.cuda.is_available()'
I saw this issue as well. The reason was the CUDA version used by Pytorch being out of sync with the installed Nvidia driver. As in Joe's answer, the solution was updating the Nvidia drivers. Some other important background info to be aware of:
- Each release of CUDA requires a minimum Nvidia driver version (see here for a compatibility table).
- You can check your Nvidia driver version with
nvidia-smi. - Pytorch comes pre-packaged with a version of CUDA that may be different from the version you installed on your computer.
- The CUDA version that you installed manually is the one shows up when you run
nvidia-smi. Even if your driver version is compatible with this CUDA version, it may be incompatible with the Pytorch CUDA version. - You can get the Pytorch CUDA version by printing the
torch.version.cudavariable in ipython or in a Python program. This is the version that determines the needed Nvidia driver version.