Why GPU not detected?

'm running with the following environment:

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

I’m running the following code:

import torch
print(f"Version: {torch.__version__}, GPU: {torch.cuda.is_available()}, NUM_GPU: {torch.cuda.device_count()}")

And I’m getting:

Version: 1.12.1+cpu, GPU: False, NUM_GPU: 0

According to: https://pytorch.org/ it seems the right version.

  1. So, Why I can’t use GPU when using torch, What is wrong ?
  2. Why torch version show CPU ? how can I install the GPU version of torch ?
  1. You’ve installed the CPU-only binary as seen in Version: 1.12.1+cpu
  2. Select the right CUDA runtime from the install instructions and run the command in your terminal.

I think the installation instruction on this page are incorrect: Start Locally | PyTorch . I selected “Compute Platform: CUDA 11.8” and it still asked me to install the pytorch package, which is the CPU-only version, and that in turn forces the torchaudio and torchvision packages to be CPU-only as well. The correct way to install the GPU version is with this command (note the missing pytorch package from the command):

conda install torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

I don’t think the command is wrong as a directly copy/paste works for me:

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

As you can see the right packages with CUDA 11.8 are installed.

Interesting! There was probably another package that was forcing the install of pytorch-1.13 (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.