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

pasawaya: <p>Just created a new deep learning server and am running into an issue running PyTorch code using CUDA. <code>nvidia-smi</code> gives seemingly correct output (below):</p>
<pre><code class="lang-auto">+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.145                Driver Version: 384.145                   |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  TITAN Xp            Off  | 00000000:01:00.0 Off |                  N/A |
|  0%   38C    P0    58W / 250W |      0MiB / 12187MiB |      2%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+
</code></pre>
<p>However, when I run <code>torch.cuda.is_available()</code>, I get the following output:</p>
<pre><code class="lang-auto">Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 17:14:51) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import torch
&gt;&gt;&gt; torch.cuda.is_available()
False
</code></pre>
<p>Any ideas as to what’s wrong? System information is below.</p>
<ul>
<li>
<p>OS: Ubuntu 16.04</p>
</li>
<li>
<p>PyTorch Version: 0.4</p>
</li>
<li>
<p>PyTorch Installation Method: Conda</p>
</li>
<li>
<p>Python Version: 3.6.6</p>
</li>
<li>
<p>CUDA/cuDNN Version: 9.2/7.1</p>
</li>
<li>
<p>GPU Model: 1 NVIDIA Titan XP</p>
</li>
</ul>

Chun_Li: <p>The problem is most likely that your display driver version 384.145 is too old compare to<br>
cuda 9.2 you are using. Update the display driver to version 396.xx (cuda 9.2 comes with<br>
396.26) may help solve the problem (that torch.cuda.is_available() is False).</p>

pasawaya: <p><a class="mention" href="/u/chun_li">@Chun_Li</a> Thanks, downgraded to CUDA 9.1 and upgraded display driver to 3.96 and all works now.</p>

Chun_Li: <p>Why downgraded to CUDA 9.1? As long as you updated the display driver to 396.xx,<br>
CUDA 9.2 should work and better than CUDA 9.1 (especially on the compatibility with gcc 7.x.x).</p>

pasawaya: <p>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.</p>

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

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

gsgbills: <p>I am getting the same problem now, after upgrading to pytorch 1, CUDA 92.<br>
(Was working fine with earlier versions of pytorch and CUDA)</p>
<p>torch.cuda.is_available()  is FALSE<br>
but torch.backends.cudnn.enabled is TRUE.<br>
Nvidia-smi working fine, reports:<br>
NVIDIA-SMI 396.37                 Driver Version: 396.37</p>
<p>Any suggestions?</p>

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

ptrblck: <p>Which CUDA version are you using?<br>
Based on the driver, you could only use CUDA&lt;=9.2 as shown <a href="https://docs.nvidia.com/deploy/cuda-compatibility/#binary-compatibility" rel="nofollow noopener">here</a>.<br>
I would recommend to update the driver and the CUDA version (if you are using an older one).</p>

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

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

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

markorei94: <p>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:</p>
<ol>
<li>What to update to make it work?</li>
<li>How to do it in a safest possible way?</li>
<li>How to proceed in future so that things get updated accordingly to latest demands?</li>
</ol>

mniju: <p>Hi every one,<br>
Torch.cuda.is_available()  is returning False.<br>
It used to work well until recently. I have tried to reboot the machine multiple times<br>
I don’t remember changing the drivers in the PC anytime in between. I am on Windows 10 64 bit</p>
<pre><code class="lang-auto">C:\Program Files\NVIDIA Corporation\NVSMI&gt;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      |
+-----------------------------------------------------------------------------+

</code></pre>
<pre><code class="lang-auto">C:\Program Files\NVIDIA Corporation\NVSMI&gt;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
</code></pre>

ptrblck: <p>Did you update PyTorch or could it have been updated/downgraded accidentally by another package?<br>
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.</p>

mniju: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> 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.</p>

tengerye: <p>Hi, may I ask how to upgrade the display driver? And why the display driver will hurts the pytorch?</p>

saurrav: <p><strong>/home/kash/pytorch/lib/python3.8/site-packages/torch/cuda/<strong>init</strong>.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.)<br>
return torch._C._cuda_getDeviceCount() &gt; 0</strong></p>
<p>why is this  error showing…i dont know im beginner<br>
CUDA Version: 11.0<br>
Driver Version: 450.80.02</p>

ptrblck: <p>Your system might be in a bad state, e.g. after a driver update without a restart.<br>
Reboot the machine and retry importing PyTorch.</p>