Torch.cuda.is_available() returns False, nvidia-smi is working

I assumed that I had to build PyTorch from source for CUDA 9.2 compatibility and ran into issues during the build process. I downgraded to 9.1 so that I could just use Anaconda to install the CUDA 9.1 compatible binary.

I see. Yes, if you just use Anaconda to install the CUDA 9.1 compatible binary, then use CUDA 9.1.
If you want to compile pytorch from source, using CUDA 9.2 is a better choice.

I got the same problem after suspending my ubuntu 16.04. I restart it then the “torch.cuda.is_available()” return “True”. Hahaha

I am getting the same problem now, after upgrading to pytorch 1, CUDA 92.
(Was working fine with earlier versions of pytorch and CUDA)

torch.cuda.is_available() is FALSE
but torch.backends.cudnn.enabled is TRUE.
Nvidia-smi working fine, reports:
NVIDIA-SMI 396.37 Driver Version: 396.37

Any suggestions?

1 Like

I get the same problem, too
“torch.cuda.is_available() is FALSE
but torch.backends.cudnn.enabled is TRUE”
Driver Version is 396.82
Have you solved this problem?

Which CUDA version are you using?
Based on the driver, you could only use CUDA<=9.2 as shown here.
I would recommend to update the driver and the CUDA version (if you are using an older one).

1 Like

Thank you
The CUDA version is 9.0
But according to this link, driver version 396.82 seems to be OK
Additionally, when print(torch.version.cuda), the result is 9.0.176

Could you check, if nvidia-smi and nvidia-settings is working on your system and show all installed GPUs?
If so, could you create a new environment and try to install a PyTorch again?

Thank you for your assistance!
We have solved the problem.
There are two nvidia drivers.
So we delete one and reinstall pytorch, and then torch.cuda.is_available() becomes true.
Hope it’s helpful to others.

Sorry for reopening but I have the same problem. I am on Windows 10, nvidia-smi gives 417.98 and the driver version is the same, while CUDA version is 10.0 and cudnn is 7.0. It used to work properly till recently, so I suppose that something should be updated. My questions are:

  1. What to update to make it work?
  2. How to do it in a safest possible way?
  3. How to proceed in future so that things get updated accordingly to latest demands?

Hi every one,
Torch.cuda.is_available() is returning False.
It used to work well until recently. I have tried to reboot the machine multiple times
I don’t remember changing the drivers in the PC anytime in between. I am on Windows 10 64 bit

C:\Program Files\NVIDIA Corporation\NVSMI>nvidia-smi
Sat Jul 04 11:23:40 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 432.00       Driver Version: 432.00       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce RTX 2080   WDDM  | 00000000:01:00.0  On |                  N/A |
| 24%   28C    P8    19W / 215W |    542MiB /  8192MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1312    C+G   Insufficient Permissions                   N/A      |
|    0      2316    C+G   ...r\Anaconda3\envs\tensorflow\pythonw.exe N/A      |
|    0      3904    C+G   ...Screen Control\bin\OnScreen Control.exe N/A      |
|    0      4248    C+G   ...AppData\Local\slack\app-4.6.0\slack.exe N/A      |
|    0      4388    C+G   ...)\Microsoft\Edge\Application\msedge.exe N/A      |
|    0      5312    C+G   C:\Windows\explorer.exe                    N/A      |
|    0      5632    C+G   ...1.0_x64__8wekyb3d8bbwe\WinStore.App.exe N/A      |
|    0      7024    C+G   ...dows.Cortana_cw5n1h2txyewy\SearchUI.exe N/A      |
|    0      8136    C+G   ...osoft.LockApp_cw5n1h2txyewy\LockApp.exe N/A      |
|    0      8412    C+G   ...DIA GeForce Experience\NVIDIA Share.exe N/A      |
|    0      9884    C+G   ....110.0_x64__8wekyb3d8bbwe\YourPhone.exe N/A      |
|    0     10544    C+G   ...hell.Experiences.TextInput.InputApp.exe N/A      |
|    0     11004    C+G   ...0.0.0_x64__8wekyb3d8bbwe\Calculator.exe N/A      |
|    0     11184    C+G   ...mmersiveControlPanel\SystemSettings.exe N/A      |
+-----------------------------------------------------------------------------+

C:\Program Files\NVIDIA Corporation\NVSMI>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:04_Central_Daylight_Time_2018
Cuda compilation tools, release 10.0, V10.0.130

Did you update PyTorch or could it have been updated/downgraded accidentally by another package?
I would recommend to create a new virtual environment and reinstall the latest PyTorch + CUDA package to check, if your current Python environment might have been broken somehow.

@ptrblck Thanks for dropping by . Its working in my dual booted Ubuntu in the same machine. As you mentioned it should work in a new virtual env. Yet to check that … Thank You.

Hi, may I ask how to upgrade the display driver? And why the display driver will hurts the pytorch?

/home/kash/pytorch/lib/python3.8/site-packages/torch/cuda/init.py:52: UserWarning: CUDA initialization: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the available devices to be zero. (Triggered internally at /pytorch/c10/cuda/CUDAFunctions.cpp:100.)
return torch._C._cuda_getDeviceCount() > 0

why is this error showing…i dont know im beginner
CUDA Version: 11.0
Driver Version: 450.80.02

Your system might be in a bad state, e.g. after a driver update without a restart.
Reboot the machine and retry importing PyTorch.

Same problem here:
I had torch working for Cuda 11.0. Then upgraded to 11.1 (system update) and I am getting the exact error.

“/usr/lib/python3.8/site-packages/torch/cuda/init.py:52: UserWarning: CUDA initialization: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the available devices to be zero. (Triggered internally at …/c10/cuda/CUDAFunctions.cpp:100.)
return torch._C._cuda_getDeviceCount() > 0”

Here is some info which might help you figure out the problem:

[kc@kc-manjaro Projects]$ nvcc --version
nvcc: NVIDIA ® Cuda compiler driver
Copyright © 2005-2020 NVIDIA Corporation
Built on Mon_Oct_12_20:09:46_PDT_2020
Cuda compilation tools, release 11.1, V11.1.105
Build cuda_11.1.TC455_06.29190527_0
[kc@kc-manjaro Projects]$ which nvcc
/opt/cuda/bin/nvcc
[kc@kc-manjaro Projects]$ echo $CUDA_HOME
/opt/cuda
[kc@kc-manjaro Projects]$ echo $LD_LIBRARY_PATH
:/opt/cuda/lib64/:/opt/cuda/lib/:/opt/cuda/extras/CUPTI/lib64

PyTorch version: 1.7.0
Is debug build: Yes
CUDA used to build PyTorch: 11.1
OS: Manjaro Linux
GCC version: (GCC) 10.2.0
CMake version: version 3.18.4
Python version: 3.8
Is CUDA available: No
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: GeForce RTX 2070
Nvidia driver version: 450.80.02
cuDNN version: Probably one of the following:
/usr/lib/libcudnn.so.8.0.5
/usr/lib/libcudnn_adv_infer.so.8.0.5
/usr/lib/libcudnn_adv_train.so.8.0.5
/usr/lib/libcudnn_cnn_infer.so.8.0.5
/usr/lib/libcudnn_cnn_train.so.8.0.5
/usr/lib/libcudnn_ops_infer.so.8.0.5
/usr/lib/libcudnn_ops_train.so.8.0.5
/usr/lib/libcudnn_static.a
Versions of relevant libraries:
[pip] Could not collect
[conda] Could not collect

Having the same issue. Any update how to solve it?
I am having CUDA 11.0 and Nvidia driver 450.80.02.
±----------------------------------------------------------------------------+
| NVIDIA-SMI 450.80.02 Driver Version: 450.80.02 CUDA Version: 11.0 |
|-------------------------------±---------------------±---------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 Tesla T4 Off | 00000000:3B:00.0 Off | 0 |
| N/A 22C P8 9W / 70W | 0MiB / 15109MiB | 0% Default |
| | | N/A |
±------------------------------±---------------------±---------------------+

±----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
±----------------------------------------------------------------------------+
Cuda.available is returning False. Any help would be appreciated!!!

you can see how the cuda version compiles with the nvidia driver version from here.
https://docs.nvidia.com/deploy/cuda-compatibility/index.html

How to know there is two nvidia driver ?