Install pytorch with CUDA 11

bear_sun: <p>Hi,</p>
<p>I am trying to install pytorch via anaconda in Ubuntu 20.04 with CUDA 11.</p>
<p>However, I didn’t find the installation option for CUDA 11 on the “Get started” webpage.</p>
<p>Does that mean I have to go back to CUDA 10.2?</p>
<p>Thx.</p>

Santhosh_Kumar1: <p>I am also facing the same dilemma. Let me know, if, you figured out a workaround solution.</p>

Baro_Kim: <p>me too.<br>
If not yet available, when planning to support CUDA 11?</p>

ptrblck: <p>The binaries are not built yet and you would have to install PyTorch from source at the moment.</p>
<p>CC <a class="mention" href="/u/santhosh_kumar1">@Santhosh_Kumar1</a>, <a class="mention" href="/u/bear_sun">@bear_sun</a></p>

peijason: <p><a class="mention" href="/u/ptrblck">@ptrblck</a><br>
I successfully build PyTorch from source with CUDA 11. However, I still got:</p>
<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>
<p>Clearly, the output of <code>torch.cuda.is_available()</code> returned <strong>False</strong>, which is <strong>incorrect</strong>.</p>
<p>Any further suggestions?</p>

ptrblck: <p>Your driver might be too old, as CUDA11 needs <code>&gt;= 450.36.06</code>.</p>

peijason: <p><a class="mention" href="/u/ptrblck">@ptrblck</a></p>
<pre><code class="lang-auto">⋊&gt; ~ nvidia-smi                                                                                                                                                                                       09:56:01
Wed Aug 19 09:56:04 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.57       Driver Version: 450.57       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  GeForce GTX 105...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   37C    P8    N/A /  N/A |   1439MiB /  4042MiB |     17%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
</code></pre>

ptrblck: <p>Could you post the install log, so that we can have a look, if CUDA was successfully detected?</p>

peijason: <p>Hi, <a class="mention" href="/u/ptrblck">@ptrblck</a></p>
<p>In fact, even now, I’m NOT sure how to install PyTorch correctly. For me, I’ve got to build twice, one using <strong>cmake</strong>, the other <code>python setup.py build</code> etc.</p>
<p>Under <strong>./build/CMakeFiles</strong>, there are 2 .log files:</p>
<ul>
<li><a href="https://pastebin.com/FM4aB9iz" rel="nofollow noopener">CMakeError.log</a></li>
<li><a href="https://pastebin.com/ijWzk78X" rel="nofollow noopener">CMakeOutput.log</a></li>
</ul>
<p>Any suggestions?</p>

ptrblck: <p>Unfortunately, I cannot access the files. The install log would be still helpful.<br>
The build instructions can be found <a href="https://github.com/pytorch/pytorch#from-source">here</a>.</p>

Krishna_Garg: <p>I tried running this command <code>conda install pytorch==1.6.0 cudatoolkit=11.0 -c pytorch</code> with <code>python v3.7.10</code>, Nvidia-driver <code>450.119.03</code> and CUDA version <code>11.0</code>.</p>
<p>But the problem is <code>torch.cuda.is_available()</code> is returning <code>False</code> and <code>torch.cuda.version</code> is returning <code>None</code>.</p>
<p>It showed me the following logs:</p>
<pre><code class="lang-auto">added / updated specs:                                                                                                                                      
    - cudatoolkit=11.0                                                                                                                                        
    - pytorch==1.6.0                                                                                                                                          
                                                                                                                                                              
                                                                                                                                                              
The following packages will be downloaded:                                                                                                                    
                                                                                                                                                              
    package                    |            build                                                                                                             
    ---------------------------|-----------------                                                                                                             
    cudatoolkit-11.0.3         |       h15472ef_8       951.9 MB  conda-forge                                                                                 
    ------------------------------------------------------------                                                                                              
                                           Total:       951.9 MB                                                                                              
                                                                                                                                                              
The following NEW packages will be INSTALLED:                                                                                                                 
                                                                                                                                                              
  cffi               conda-forge/linux-64::cffi-1.14.5-py37hc58025e_0                                                                                         
  cudatoolkit        conda-forge/linux-64::cudatoolkit-11.0.3-h15472ef_8
  future             conda-forge/linux-64::future-0.18.2-py37h89c1867_3
  libblas            conda-forge/linux-64::libblas-3.9.0-8_mkl
  libcblas           conda-forge/linux-64::libcblas-3.9.0-8_mkl
  liblapack          conda-forge/linux-64::liblapack-3.9.0-8_mkl
  llvm-openmp        conda-forge/linux-64::llvm-openmp-11.1.0-h4bd325d_1
  mkl                conda-forge/linux-64::mkl-2020.4-h726a3e6_304
  ninja              conda-forge/linux-64::ninja-1.10.2-h4bd325d_0
  numpy              conda-forge/linux-64::numpy-1.21.0-py37h038b26d_0
  pycparser          conda-forge/noarch::pycparser-2.20-pyh9f0ad1d_2
  pytorch            conda-forge/linux-64::pytorch-1.6.0-cpu_py37hf1c21f6_1
  typing_extensions  conda-forge/noarch::typing_extensions-3.10.0.0-pyha770c72_0

The following packages will be DOWNGRADED:

  _openmp_mutex                                   4.5-1_gnu --&gt; 4.5-1_llvm


Proceed ([y]/n)? y
</code></pre>
<p>Any suggestions?</p>

ptrblck: <p>You are installing the CPU version as shown in the logs, since <code>1.6.0</code> didn’t ship with <code>cudatoolkit=11.0</code>.</p>

Krishna_Garg: <p>Yeah, I had to install pytorch <code>1.7.0</code> which worked fine.</p>
<p>Command I used:</p>
<p><code>conda install pytorch==1.7.0 cudatoolkit=11.0 -c pytorch</code></p>

wyh196646: <p>I meet the same problem ,just using mmdetection, the terminal shows :    The detected CUDA version (11.0) mismatches the version that was used to compile<br>
PyTorch (10.2). Please make sure to use the same CUDA versions.</p>

ptrblck: <p>To build custom CUDA extensions your local CUDA toolkit will be used and should match the used CUDA runtime shipped in the pip wheels / conda binaries. Install the CUDA11 wheels and it should work.</p>

wyh196646: <p>Thank you! I just want to learn the relation of the cuda，pytorch，cudann，cudatoolkit,where can I see that?</p>

ptrblck: <p>You can print the different versions using <code>print(torch.__config__.show())</code> and would see the used CUDA runtime, cuDNN etc.</p>

pascal_notsawo: <p>Although the original question is on Ubuntu, I had this problem on windows 11.</p>
<blockquote>
<p>nvidia-smi</p>
</blockquote>
<pre><code class="lang-auto">Tue May 24 21:51:38 2022       
+-----------------------------------------------------------------------------+     
| NVIDIA-SMI 516.01       Driver Version: 516.01       CUDA Version: 11.7     |     
|-------------------------------+----------------------+----------------------+     
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |     
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |     
|                               |                      |               MIG M. |     
|===============================+======================+======================|     
|   0  NVIDIA GeForce ... WDDM  | 00000000:01:00.0 Off |                  N/A |
| N/A   33C    P5    17W /  N/A |      0MiB /  6144MiB |      0%      Default |     
|                               |                      |                  N/A |     
+-------------------------------+----------------------+----------------------+     

+-----------------------------------------------------------------------------+     
| Processes:                                                                  |     
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |     
|        ID   ID                                                   Usage      |     
|=============================================================================|     
|  No running processes found                                                 |
</code></pre>
<blockquote>
<p>nvcc --version</p>
</blockquote>
<pre><code class="lang-auto">nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_May__3_19:00:59_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.7, V11.7.64
Build cuda_11.7.r11.7/compiler.31294372_0
</code></pre>
<p>Here is how I solved the problem:</p>
<ul>
<li>I updated Anaconda : I switched to the latest version, and rebooted my computer after the installation.</li>
<li>I chose the last version of pytorch <a href="https://pytorch.org/" rel="noopener nofollow ugc">here</a></li>
</ul>
<pre data-code-wrap="bash"><code class="lang-bash">conda create -n global_env
conda activate global_env
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
</code></pre>
<pre data-code-wrap="pytorch"><code class="lang-pytorch">import torch
print(torch.cuda.is_available(), torch.version.cuda, torch.backends.cudnn.enabled)
</code></pre>
<blockquote>
<p>True 11.3 True</p>
</blockquote>
<pre data-code-wrap="pytorch"><code class="lang-pytorch">torch.__version__
</code></pre>
<blockquote>
<p>‘1.11.0’</p>
</blockquote>

VIGHNESH1521: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a> ,</p>
<p>I am trying to install pytorch via cmd in windows 10 with CUDA 11.4.2<br>
How to install pytorch which is compatible with this CUDA version?<br>
Thanks</p>

ptrblck: <p>We did not build PyTorch binaries shipping with CUDA 11.4, if I’m not mistaken. You could install the latest PyTorch release with CUDA 11.8 or 12.1 instead.</p>