GPU version of Pytorch cannot be enabled

wine_lover: <p>Hello, I was installing pytorch GPU version on linux, and used the following command given on Pytorch site</p>
<blockquote>
<p>conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia</p>
</blockquote>
<p>I also have installed cuda tool using</p>
<blockquote>
<p>conda install -c “nvidia/label/cuda-11.7.0” cuda-toolkit</p>
</blockquote>
<p>Using conda list, the following packages are installed</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/7/e/7ed99ba726b708d5547ab631c4f90793cd659ade.png" data-download-href="https://discuss.pytorch.org/uploads/default/7ed99ba726b708d5547ab631c4f90793cd659ade" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/7/e/7ed99ba726b708d5547ab631c4f90793cd659ade_2_572x500.png" alt="image" data-base62-sha1="i6anPhhpM8zd8WRwJNQxZokOkto" width="572" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/7/e/7ed99ba726b708d5547ab631c4f90793cd659ade_2_572x500.png, https://discuss.pytorch.org/uploads/default/original/3X/7/e/7ed99ba726b708d5547ab631c4f90793cd659ade.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/7/e/7ed99ba726b708d5547ab631c4f90793cd659ade.png 2x" data-dominant-color="090909"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">837×731 114 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<blockquote>
<p>pytorch                   1.4.0           py3.8_cuda10.1.243_cudnn7.6.3_0    pytorch<br>
pytorch-cuda              11.7                 h67b0de4_1    pytorch</p>
</blockquote>
<p>However, the test result of whether CUDA is available still failed</p>
<blockquote>
<p>(torch_test1) bash-4.2$ python<br>
Python 3.8.16 (default, Jan 17 2023, 23:13:24)<br>
[GCC 11.2.0] :: Anaconda, Inc. on linux<br>
Type “help”, “copyright”, “credits” or “license” for more information.</p>
<blockquote>
<blockquote>
<blockquote>
<p>import torch<br>
torch.cuda.is_available()<br>
False</p>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<p>Any suggestions or advice will be highly appreciated!</p>

ptrblck: <p>You might be mixing the current release with this older one:</p>
<pre><code class="lang-auto">pytorch 1.4.0 py3.8_cuda10.1.243_cudnn7.6.3_0 pytorch
</code></pre>
<p>so make sure to install a single binary in your current environment only.</p>

wine_lover: <aside class="quote no-group" data-username="wine_lover" data-post="1" data-topic="173283">
<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/wine_lover/48/15986_2.png" class="avatar"> wine_lover:</div>
<blockquote>
<p>orch.cuda.is_available()</p>
</blockquote>
</aside>
<p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a>, I tried to re-install the virtual environment,<br>
1)</p>
<blockquote>
<p>conda install -c “nvidia/label/cuda-11.6.0” cuda-toolkit</p>
</blockquote>
<p>The nvcc --version verifies that<br>
bash-4.2$ nvcc --version</p>
<blockquote>
<p>nvcc: NVIDIA (R) Cuda compiler driver<br>
Copyright (c) 2005-2021 NVIDIA Corporation<br>
Built on Fri_Dec_17_18:16:03_PST_2021<br>
Cuda compilation tools, release 11.6, V11.6.55<br>
Build cuda_11.6.r11.6/compiler.30794723_0</p>
</blockquote>
<p>Then I followed the command line given by <a href="https://pytorch.org/get-started/locally/" rel="noopener nofollow ugc">pytorch website</a></p>
<blockquote>
<p>conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia</p>
</blockquote>
<p>But</p>
<blockquote>
<p>torch.cuda.is_available()</p>
</blockquote>
<p>still outputs</p>
<blockquote>
<p>False</p>
</blockquote>
<p>I am not sure which step is wrong, and what do you mean <strong>install  a single binary</strong>  Thank you for the the help!</p>

wine_lover: <p>I also tried <a href="https://anaconda.org/conda-forge/pytorch-gpu" rel="noopener nofollow ugc">conda install -c conda-forge pytorch-gpu</a>, and torch.cuda.is_available() still outputs  False as well.</p>

ptrblck: <p>Assuming your <code>conda list</code> outputs the desired PyTorch version showing the corresponding CUDA 11.6 runtime, you should see the CUDA version via <code>print(torch.version.cuda)</code>. Is this the case?</p>

wine_lover: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a>, when I use <a href="https://anaconda.org/conda-forge/pytorch-gpu" rel="noopener nofollow ugc">conda install -c conda-forge pytorch-gpu</a> to install, the output of  print(torch.version.cuda) is 11.2. The conda list result is</p>
<blockquote>
<p>python                    3.10.9          he550d4f_0_cpython    conda-forge<br>
python_abi                3.10                    3_cp310    conda-forge<br>
pytorch                   1.11.0          cuda112py310h51fe464_1    conda-forge<br>
pytorch-gpu               1.11.0          cuda112py310h68407e5_1    conda-forge<br>
cudatoolkit               11.8.0              h37601d7_11    conda-forge<br>
cudnn                     8.4.1.50             hed8a83a_0    conda-forge</p>
</blockquote>

wine_lover: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a>, comparing to the above installation approach, as I mentioned, I also tried <a href="https://pytorch.org/get-started/locally/" rel="noopener nofollow ugc">conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia</a>,<br>
For this one, the output of  <strong>print(torch.version.cuda)</strong> is <strong>None</strong>, the <strong>conda list</strong> result is<br>
python                    3.10.9               h7a1cb2a_2<br>
pytorch                   2.0.0              py3.10_cpu_0    pytorch<br>
pytorch-cuda              11.6                 h867d48c_1    pytorch<br>
pytorch-mutex             1.0                         cpu    pytorch<br>
cuda                      11.6.0                        0    nvidia<br>
cuda-cccl                 11.6.55              hf6102b2_0    nvidia/label/cuda-11.6.0<br>
cuda-command-line-tools   11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-compiler             11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-cudart               11.6.55              he381448_0    nvidia/label/cuda-11.6.0<br>
cuda-cudart-dev           11.6.55              h42ad0f4_0    nvidia/label/cuda-11.6.0<br>
cuda-cuobjdump            11.6.55              h9dd2d0c_0    nvidia/label/cuda-11.6.0<br>
cuda-cupti                11.6.55              h43c5c43_0    nvidia/label/cuda-11.6.0<br>
cuda-cuxxfilt             11.6.55              h69de05d_0    nvidia/label/cuda-11.6.0<br>
cuda-driver-dev           11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-gdb                  11.6.55              hff0b7d4_0    nvidia/label/cuda-11.6.0<br>
cuda-libraries            11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-libraries-dev        11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-memcheck             11.6.55              h0288dce_0    nvidia/label/cuda-11.6.0<br>
cuda-nsight               11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-nsight-compute       11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-nvcc                 11.6.55              h5758ece_0    nvidia/label/cuda-11.6.0<br>
cuda-nvdisasm             11.6.55              h5556c0d_0    nvidia/label/cuda-11.6.0<br>
cuda-nvml-dev             11.6.55              haa9ef22_0    nvidia/label/cuda-11.6.0<br>
cuda-nvprof               11.6.55              h30b2dac_0    nvidia/label/cuda-11.6.0<br>
cuda-nvprune              11.6.55              h3791f62_0    nvidia/label/cuda-11.6.0<br>
cuda-nvrtc                11.6.55              hc54fff9_0    nvidia/label/cuda-11.6.0<br>
cuda-nvrtc-dev            11.6.55              h42ad0f4_0    nvidia/label/cuda-11.6.0<br>
cuda-nvtx                 11.6.55              h99d0529_0    nvidia/label/cuda-11.6.0<br>
cuda-nvvp                 11.6.58              h67ee751_0    nvidia/label/cuda-11.6.0<br>
cuda-runtime              11.6.0                        0    nvidia<br>
cuda-samples              11.6.101             h8efea70_0    nvidia/label/cuda-11.6.0<br>
cuda-sanitizer-api        11.6.55              h4716e2e_0    nvidia/label/cuda-11.6.0<br>
cuda-toolkit              11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-tools                11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-visual-tools         11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cudatoolkit               11.3.1               h2bc3f7f_2    anaconda<br>
cudnn                     8.2.1                cuda11.3_0    anaconda</p>

ptrblck: <aside class="quote no-group" data-username="wine_lover" data-post="6" data-topic="173283">
<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/wine_lover/48/15986_2.png" class="avatar"> wine_lover:</div>
<blockquote>
<p>when I use <a href="https://anaconda.org/conda-forge/pytorch-gpu">conda install -c conda-forge pytorch-gpu</a> to install</p>
</blockquote>
</aside>
<p>I don’t know who is building this <code>conda-forge</code> binary, but it’s not supported by us.</p>
<aside class="quote no-group" data-username="wine_lover" data-post="7" data-topic="173283">
<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/wine_lover/48/15986_2.png" class="avatar"> wine_lover:</div>
<blockquote>
<p>For this one, the output of <strong>print(torch.version.cuda)</strong> is <strong>None</strong>, the <strong>conda list</strong> result is</p>
</blockquote>
</aside>
<p>Based on your output you are still installing the CPU-only binary:</p>
<pre><code class="lang-auto">pytorch 2.0.0 py3.10_cpu_0 pytorch
</code></pre>
<p>I would recommend to uninstall all PyTorch installs in your base environment by executing</p>
<pre><code class="lang-auto">conda uninstall pytorch torchvision -y
pip uninstall torch torchvision -y
</code></pre>
<p>a few times, then create a new and empty virtual environment, and install the pip wheels or conda binaries using the install command from our website.</p>

wine_lover: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a>, thank you for the suggestions,  I just created a new library from scratch. I performed two experiments:</p>
<ol>
<li>just installing the pip wheels using the command from your <a href="https://pytorch.org/get-started/locally/" rel="noopener nofollow ugc">website</a></li>
</ol>
<blockquote>
<p>pip3 install torch torchvision torchaudio --extra-index-url <a href="https://download.pytorch.org/whl/cu116" rel="noopener nofollow ugc">https://download.pytorch.org/whl/cu116</a></p>
</blockquote>
<p>The <strong>torch.version.cuda</strong> still outputs <strong>None</strong>. I checked the result of <strong>conda list</strong>, it does not cuda and cudnn library. I am not sure whether it is the cause, so I performed the second experiment</p>
<ol start="2">
<li>I first install cuda and cudnn using conda in a fresh new environment</li>
</ol>
<blockquote>
<p>conda install -c anaconda cudnn<br>
conda install -c “nvidia/label/cuda-11.6.0” cuda-toolkit<br>
Then I installed pytorch using pip again</p>
</blockquote>
<blockquote>
<p>pip3 install torch torchvision torchaudio --extra-index-url <a href="https://download.pytorch.org/whl/cu116" rel="noopener nofollow ugc">https://download.pytorch.org/whl/cu116</a></p>
</blockquote>
<p>However, the <strong>torch.version.cuda</strong> still outputs <strong>None</strong>.  Here is the conda list result for this environment</p>
<blockquote>
<p>torch                     2.0.0                    pypi_0    pypi<br>
torchaudio                2.0.1                    pypi_0    pypi<br>
torchvision               0.15.1                   pypi_0    pypi<br>
cuda-cccl                 11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-command-line-tools   11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-compiler             11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-cudart               11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-cudart-dev           11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-cuobjdump            11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-cupti                11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-cuxxfilt             11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-libraries            11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-libraries-dev        11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-memcheck             11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-nsight-compute       11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-nvcc                 11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-nvdisasm             11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-nvml-dev             11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-nvprof               11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-nvprune              11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-nvrtc                11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-nvrtc-dev            11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-nvtx                 11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-nvvp                 11.6.58                       0    nvidia/label/cuda-11.6.0<br>
cuda-sanitizer-api        11.6.55                       0    nvidia/label/cuda-11.6.0<br>
cuda-toolkit              11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-tools                11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cuda-visual-tools         11.6.0                        0    nvidia/label/cuda-11.6.0<br>
cudatoolkit               11.3.1               h59b6b97_2    anaconda<br>
cudnn                     8.2.1                cuda11.3_0    anaconda</p>
</blockquote>

wine_lover: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a>, just want to give you some update, it seems to me that the <a href="https://pytorch.org/get-started/locally/" rel="noopener nofollow ugc">pytorch office site</a> happens to have some update today. I just re-install the pytorch, and found that they already update the stable version from 13.1 to 2.0, and it seems that the updated pip   installation also works,</p>
<blockquote>
<p>pip3 install torch torchvision torchaudio --extra-index-url <a href="https://download.pytorch.org/whl/cu116" rel="noopener nofollow ugc">https://download.pytorch.org/whl/cu116</a></p>
</blockquote>
<p>Here is my current test result</p>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<p>import torch<br>
print(torch.version.cuda)<br>
11.7</p>
</blockquote>
</blockquote>
</blockquote>
<blockquote>
<blockquote>
<blockquote>
<p>print(torch.cuda.is_available())<br>
True</p>
</blockquote>
</blockquote>
</blockquote>
</blockquote>

ptrblck: <p>Thanks for the update and it’s good to hear the binaries work now!<br>
There seems to be still some issue in your environment, since you have specified <code>cu116</code> in the <code>--extra-index-url</code> while the 11.7 runtime is installed, but at least it seems to be working now for you.</p>