Why GPU not detected?

username: laro
cooked: <p>'m running with the following environment:</p>
<pre><code class="lang-auto">Windows 10
python 3.8.10
CUDA Version: 11.3  (according to `nvidia-smi`)
torch: 1.12.1
CUDNN_MAJOR 8       (according to `cudnn_version`)
CUDNN_MINOR 1
</code></pre>
<p>I’m running the following code:</p>
<pre><code class="lang-auto">import torch
print(f"Version: {torch.__version__}, GPU: {torch.cuda.is_available()}, NUM_GPU: {torch.cuda.device_count()}")
</code></pre>
<p>And I’m getting:</p>
<pre><code class="lang-auto">Version: 1.12.1+cpu, GPU: False, NUM_GPU: 0
</code></pre>
<p>According to: <a href="https://pytorch.org/" rel="noopener nofollow ugc">https://pytorch.org/</a> it seems the right version.</p>
<ol>
<li>So, Why I can’t use GPU when using torch, What is wrong ?</li>
<li>Why torch version show CPU ? how can I install the GPU version of torch ?</li>
</ol>

username: ptrblck
cooked: <ol>
<li>You’ve installed the CPU-only binary as seen in <code>Version: 1.12.1+cpu</code>
</li>
<li>Select the right CUDA runtime from the install instructions and run the command in your terminal.</li>
</ol>

username: rigved
cooked: <p>I think the installation instruction on this page are incorrect: <a href="https://pytorch.org/get-started/locally/" class="inline-onebox" rel="noopener nofollow ugc">Start Locally | PyTorch</a> . I selected “Compute Platform: CUDA 11.8” and it still asked me to install the <code>pytorch</code> package, which is the CPU-only version, and that in turn forces the <code>torchaudio</code> and <code>torchvision</code> packages to be CPU-only as well. The correct way to install the GPU version is with this command (note the missing <code>pytorch</code> package from the command):</p>
<p><code>conda install torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia</code></p>

username: ptrblck
cooked: <p>I don’t think the command is wrong as a directly copy/paste works for me:</p>
<pre><code class="lang-python">conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
...
The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    cryptography-40.0.2        |   py38h3d167d9_0         1.4 MB  conda-forge
    filelock-3.12.0            |     pyhd8ed1ab_0          14 KB  conda-forge
    lcms2-2.15                 |       hfd0df8a_0         235 KB  conda-forge
    libcufile-1.6.1.9          |                0         764 KB  nvidia
    libcurand-10.3.2.106       |                0        51.7 MB  nvidia
    libhwloc-2.9.1             |       hd6dc26d_0         2.5 MB  conda-forge
    libwebp-base-1.3.0         |       h0b41bf4_0         348 KB  conda-forge
    libxml2-2.10.4             |       hfdac1af_0         697 KB  conda-forge
    llvm-openmp-16.0.2         |       h4dfa4b3_0        40.6 MB  conda-forge
    mpfr-4.2.0                 |       hb012696_0         616 KB  conda-forge
    mpmath-1.3.0               |     pyhd8ed1ab_0         428 KB  conda-forge
    networkx-3.1               |     pyhd8ed1ab_0         1.4 MB  conda-forge
    numpy-1.24.3               |   py38h59b608b_0         6.4 MB  conda-forge
    openssl-3.1.0              |       hd590300_2         2.5 MB  conda-forge
    pytorch-2.0.0              |py3.8_cuda11.8_cudnn8.7.0_0        1.41 GB  pytorch
    pytorch-cuda-11.8          |       h7e8668a_3           7 KB  pytorch
    pytorch-mutex-1.0          |             cuda           3 KB  pytorch
    sympy-1.11.1               | pypyh9d50eac_103         4.6 MB  conda-forge
    tbb-2021.9.0               |       hf52228f_0         1.5 MB  conda-forge
    torchaudio-2.0.0           |       py38_cu118         7.6 MB  pytorch
    torchtriton-2.0.0          |             py38        62.6 MB  pytorch
    torchvision-0.15.0         |       py38_cu118        38.9 MB  pytorch
    typing_extensions-4.5.0    |     pyha770c72_0          31 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        1.63 GB
</code></pre>
<p>As you can see the right packages with CUDA 11.8 are installed.</p>

username: rigved
cooked: <p>Interesting! There was probably another package that was forcing the install of <code>pytorch-1.13</code> (CPU-version) when I ran that command yesterday. I tried this command again in a fresh Anaconda environment and that’s working as you mentioned.</p>