torch.cuda.is_available() is false after CUDA 9.0.176 installed. Could anyone help me with this? Thanks!

Dee_Ma: <p>Hi,</p>
<p>I just got a very strange problem:</p>
<p>I used the commands: “print(torch. <strong>version</strong> )<br>
print(torch.version.cuda)<br>
print(torch.backends.cudnn.version())”, the output were:</p>
<p>0.4.1.post2 (PyTorch version)<br>
9.0.176 (CUDA version)<br>
7.1.2 (cuDNN version)</p>
<p>I also used the “nvcc --version”, the results were:<br>
<img src="https://discuss.pytorch.org/uploads/default/original/2X/8/8d9cc497380040f88798dfdfff4a0a63ded6a075.png" alt="Capture4" data-base62-sha1="kcLcdzyEyQOgRFMAxpcIDuyZyjr" width="367" height="62"></p>
<p>It was very strange, it seems that the CUDA version installed in Linux system is 9.0.176, and the CUDA that the PyTorch needed is also 9.0.176, but, the “cuda.is_available()” still returns " <strong>False</strong> ".</p>
<p>Could anyone help me with this? Many thanks!</p>
<h2><a name="environment-1" class="anchor" href="#environment-1"></a>Environment</h2>
<ul>
<li>PyTorch Version (e.g., 1.0): 0.4.1.post2</li>
<li>OS (e.g., Linux): Linux</li>
<li>Python version: 3.6.5 : : Anaconda, Inc.</li>
<li>CUDA/cuDNN version: 9.0.176 (CUDA version); 7.1.2 (cuDNN version)</li>
</ul>

TMY: <p>Hello,<br>
I am facing the same problem and tried all the options discussed here, But did not work. Can somebody please help me to solve this problem.</p>
<p>OS: linux<br>
pytorchVesion: 1.0.1<br>
Python version : 3.7.3<br>
Cuda : 9.0.176<br>
Driver vesion: 396.24</p>
<p>Thank you</p>

ptrblck: <p>Did you install the PyTorch binaries? If so, you don’t need a system CUDA installation, since CUDA already ships with PyTorch?<br>
You can check if with <code>print(torch.version.cuda)</code>.</p>
<p>I think your driver might be too old, if your PyTorch binaries shipped with a newer CUDA version than <code>9.1</code> (which is most likely the case). Have a look at <a href="https://docs.nvidia.com/deploy/cuda-compatibility/index.html#binary-compatibility__table-toolkit-driver" rel="nofollow noopener">this table</a> to see the compatibility, and try to update your driver.</p>

Neda: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> Could you please kindly share the link for the PyTorch binaries installation?</p>

ptrblck: <p>Sure! You can find the command to install the binaries <a href="https://pytorch.org/get-started/locally/" rel="nofollow noopener">here</a>.</p>

Pritesh_Gohil: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a>,<br>
Thank you for your comments. I was facing similar issue. Can you please suggest what might be wrong for the following setting?</p>
<pre><code class="lang-auto">&gt;&gt;torch.version.cuda
10.2
&gt;&gt;&gt; torch.cuda.is_available()
False
&gt;&gt;&gt; torch.backends.cudnn.enabled
True
$ cat /usr/local/cuda/version.txt 
CUDA Version 10.0.130

</code></pre>
<p>pytorch version <strong>1.6.0</strong></p>
<p>Can’t play with the main system because Its remote PC and I don’t have rights to upgrade or install NVIDIA driver.</p>
<p>Thank you <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>
<p><strong>Edit:</strong><br>
I solved this problem by installing cudatoolkit 10.0<br>
I use .yml file with to create conda environment. Now I added following line,</p>
<pre><code class="lang-auto">- cudatoolkit=10.0
</code></pre>
<p>Conda will select dependency according to this cuda version and hence my pytorch version is also changed, which is ok for me.<br>
Current environment,</p>
<pre><code class="lang-auto">&gt;&gt;torch.version.cuda
10.0
&gt;&gt;&gt; torch.cuda.is_available()
True
&gt;&gt;&gt; torch.backends.cudnn.enabled
True
$ cat /usr/local/cuda/version.txt 
CUDA Version 10.0.130

</code></pre>
<p>pytorch version <strong>1.3.1</strong></p>

ptrblck: <p>Which GPU(s) are you using and how did you install PyTorch <code>1.6.0</code>?<br>
If you’ve installed the conda binaries or pip wheels, your local CUDA installation will not be used, but binary (or wheel) will ship with their own CUDA, cudnn, (NCCL etc.) libs.<br>
Good to hear you can install PyTorch <code>1.3.1</code> with CUDA10.0, but that’s not a proper solution as you would be missing all the new features and bug fixes.</p>

Pritesh_Gohil: <p>GPU is <strong>GeForce GTX 1080 Ti</strong> and PyTorch was installed using conda.<br>
Yes I’m using virtual environment, so everything is installed using conda.<br>
Do you mean that conda will install CUDA10.0 that will not disturb the local CUDA installation? In such cases, is it possible to select local CUDA version and bypass conda’s CUDA binary?</p>
<p>I tried PyTorch <code>1.5</code> or higher with <code>cudatoolkit=10.0</code>, but there are conflicts with many other packages.</p>

ptrblck: <aside class="quote no-group" data-username="Pritesh_Gohil" data-post="8" data-topic="33360">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/pritesh_gohil/48/14828_2.png" class="avatar"> Pritesh_Gohil:</div>
<blockquote>
<p>Do you mean that conda will install CUDA10.0 that will not disturb the local CUDA installation? In such cases, is it possible to select local CUDA version and bypass conda’s CUDA binary?</p>
</blockquote>
</aside>
<p>Yes, exactly. The <a href="https://pytorch.org/get-started/locally/">install instructions</a> set you select the CUDA version, which will be installed only in your current environment (conda or pip).<br>
If you get conflicts with other packages, I would recommend to create a new virtual environment, if that’s possible, and reinstall PyTorch as well as all other packages, which are needed.</p>

peijason: <p><a class="mention" href="/u/pritesh_gohil">@Pritesh_Gohil</a></p>
<p>Thank you very much. It’s the same here. <strong>PyTorch</strong> is good but is clearly messy…</p>
<ol>
<li>My <strong>ENV</strong>:</li>
</ol>
<pre><code class="lang-auto">Device 0: "GeForce GTX 1050 Ti"
NVIDIA-SMI 450.57       Driver Version: 450.57       CUDA Version: 11.0
</code></pre>
<ol start="2">
<li>PyTorch Configuration</li>
</ol>
<pre><code class="lang-python">➜  pytorch python
Python 3.8.2 (default, Jul 16 2020, 14:00:26) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import torch
&gt;&gt;&gt; torch.cuda
&lt;module 'torch.cuda' from '/home/jiapei/.local/lib/python3.8/site-packages/torch/cuda/__init__.py'&gt;
&gt;&gt;&gt; torch.cuda.is_available()
False
&gt;&gt;&gt; print(torch.version.cuda)
11.0
&gt;&gt;&gt; torch.backends.cudnn.enabled
True
&gt;&gt;&gt; 
</code></pre>
<ol start="3">
<li>Cuda</li>
</ol>
<p>and:</p>
<pre><code class="lang-auto">➜  ~ cat /usr/local/cuda/version.txt 
CUDA Version 11.0.228
</code></pre>
<p>It is unbelievably weird that <code>torch.cuda.is_available()</code> failed to return a reasonable value…</p>
<p>I’m actually testing <strong>yolov5</strong>, which has the following line:<br>
<code>assert torch.cuda.is_available(), 'CUDA unavailable, invalid device %s requested' % device  # check availablity</code>. Clearly, it’s going to fail the <strong>assertion</strong>.</p>
<p>It seems <strong>PyTorch supporting CUDA 11</strong> should be the solution?<br>
hmmmmm any further suggestions?</p>
<p>Pei</p>

Pritesh_Gohil: <p><a class="mention" href="/u/peijason">@peijason</a> As discussed <a href="https://discuss.pytorch.org/t/install-pytorch-with-cuda-11/89219/4">here</a>, I hope PyTorch community will be able to help.</p>

Krishna_Garg: <p>In my case, it turned out that I installed Pytorch without cudatoolkit and <code>print(torch.version.cuda)</code> returned <code>False</code>.</p>