98

On a Windows 10 PC with an NVidia GeForce 820M I installed CUDA 9.2 and cudnn 7.1 successfully, and then installed PyTorch using the instructions at pytorch.org:

pip install torch==1.4.0+cu92 torchvision==0.5.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html

But I get:

>>> import torch
>>> torch.cuda.is_available()
False
5
  • Because Gefore 820M only supports CUDA < 9
    – jodag
    Apr 2, 2020 at 9:55
  • 1
    You mean 9.0 ? So what should I do .. in pytorch web site there is only 2 options : Cuda 9.2 or 10.1 .. and also How can i know which Cuda is suppoted by Geforce 820M
    – mac179
    Apr 2, 2020 at 12:12
  • 1
    The only real alternatives are to upgrade your graphics card hardware, use the cpu-only version of pytorch, or try to use an older version of pytorch with CUDA 8 support.
    – jodag
    Apr 2, 2020 at 19:26
  • I deleted my previous comment which described how to check if your GPU is compatible with a particular version of CUDA and instead provided a more thorough answer below
    – jodag
    Apr 4, 2020 at 22:29
  • Have you created a new Python virtual environment or forcefully reinstalled pytorch and torchvision?
    – JP Ventura
    Feb 17, 2022 at 14:01

13 Answers 13

200

Your graphics card does not support CUDA 9.0.

Since I've seen a lot of questions that refer to issues like this I'm writing a broad answer on how to check if your system is compatible with CUDA, specifically targeted at using PyTorch with CUDA support. Various circumstance-dependent options for resolving issues are described in the last section of this answer.


The system requirements to use PyTorch with CUDA are as follows:

  • Your graphics card must support the required version of CUDA
  • Your graphics card driver must support the required version of CUDA
  • The PyTorch binaries must be built with support for the compute capability of your graphics card

Note: If you install pre-built binaries (using either pip or conda) then you do not need to install the CUDA toolkit or runtime on your system before installing PyTorch with CUDA support. This is because PyTorch, unless compiled from source, is always delivered with a copy of the CUDA library.


1. How to check if your GPU/graphics card supports a particular CUDA version

First, identify the model of your graphics card.

Before moving forward ensure that you've got an NVIDIA graphics card. AMD and Intel graphics cards do not support CUDA.

NVIDIA doesn't do a great job of providing CUDA compatibility information in a single location. The best resource is probably this section on the CUDA Wikipedia page. To determine which versions of CUDA are supported

  1. Locate your graphics card model in the big table and take note of the compute capability version. For example, the GeForce 820M compute capability is 2.1.
  2. In the bullet list preceding the table check to see if the required CUDA version is supported by the compute capability of your graphics card. For example, CUDA 9.2 is not supported for compute compatibility 2.1.

If your card doesn't support the required CUDA version then see the options in section 4 of this answer.

Note: Compute capability refers to the computational features supported by your graphics card. Newer versions of the CUDA library rely on newer hardware features, which is why we need to determine the compute capability in order to determine the supported versions of CUDA.


2. How to check if your GPU/graphics driver supports a particular CUDA version

The graphics driver is the software that allows your operating system to communicate with your graphics card. Since CUDA relies on low-level communication with the graphics card you need to have an up-to-date driver in order use the latest versions of CUDA.

First, make sure you have an NVIDIA graphics driver installed on your system. You can acquire the newest driver for your system from NVIDIA's website.

If you've installed the latest driver version then your graphics driver probably supports every CUDA version compatible with your graphics card (see section 1). To verify, you can check Table 2 in the CUDA release notes. In rare cases I've heard of the latest recommended graphics drivers not supporting the latest CUDA releases. You should be able to get around this by installing the CUDA toolkit for the required CUDA version and selecting the option to install compatible drivers, though this usually isn't required.

If you can't, or don't want to upgrade the graphics driver then you can check to see if your current driver supports the specific CUDA version as follows:

On Windows

  1. Determine your current graphics driver version (Source https://www.nvidia.com/en-gb/drivers/drivers-faq/)

Right-click on your desktop and select NVIDIA Control Panel. From the NVIDIA Control Panel menu, select Help > System Information. The driver version is listed at the top of the Details window. For more advanced users, you can also get the driver version number from the Windows Device Manager. Right-click on your graphics device under display adapters and then select Properties. Select the Driver tab and read the Driver version. The last 5 digits are the NVIDIA driver version number.

  1. Visit the CUDA release notes and scroll down to Table 2. Use this table to verify your graphics driver is new enough to support the required version of CUDA.

On Linux/OS X

Run the following command in a terminal window

nvidia-smi

This should result in something like the following

Sat Apr  4 15:31:57 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 435.21       Driver Version: 435.21       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce RTX 206...  Off  | 00000000:01:00.0  On |                  N/A |
|  0%   35C    P8    16W / 175W |    502MiB /  7974MiB |      1%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1138      G   /usr/lib/xorg/Xorg                           300MiB |
|    0      2550      G   /usr/bin/compiz                              189MiB |
|    0      5735      G   /usr/lib/firefox/firefox                       5MiB |
|    0      7073      G   /usr/lib/firefox/firefox                       5MiB |
+-----------------------------------------------------------------------------+

Driver Version: ###.## is your graphic driver version. In the example above the driver version is 435.21.

CUDA Version: ##.# is the latest version of CUDA supported by your graphics driver. In the example above the graphics driver supports CUDA 10.1 as well as all compatible CUDA versions before 10.1.

Note: The CUDA Version displayed in this table does not indicate that the CUDA toolkit or runtime are actually installed on your system. This just indicates the latest version of CUDA your graphics driver is compatible with.

To be extra sure that your driver supports the desired CUDA version you can visit Table 2 on the CUDA release notes page.


3. How to check if a particular version of PyTorch is compatible with your GPU/graphics card compute capability

Even if your graphics card supports the required version of CUDA then it's possible that the pre-compiled PyTorch binaries were not compiled with support for your compute capability. For example, in PyTorch 0.3.1 support for compute capability <= 5.0 was dropped.

First, verify that your graphics card and driver both support the required CUDA version (see Sections 1 and 2 above), the information in this section assumes that this is the case.

The easiest way to check if PyTorch supports your compute capability is to install the desired version of PyTorch with CUDA support and run the following from a python interpreter

>>> import torch
>>> torch.zeros(1).cuda()

If you get an error message that reads

Found GPU0 XXXXX which is of cuda capability #.#.
PyTorch no longer supports this GPU because it is too old.

then that means PyTorch was not compiled with support for your compute capability. If this runs without issue then you should be good to go.

Update If you're installing an old version of PyTorch on a system with a newer GPU then it's possible that the old PyTorch release wasn't compiled with support for your compute capability. Assuming your GPU supports the version of CUDA used by PyTorch, then you should be able to rebuild PyTorch from source with the desired CUDA version or upgrade to a more recent version of PyTorch that was compiled with support for the newer compute capabilities.


4. Conclusion

If your graphics card and driver support the required version of CUDA (section 1 and 2) but the PyTorch binaries don't support your compute capability (section 3) then your options are

  • Compile PyTorch from source with support for your compute capability (see here)
  • Install PyTorch without CUDA support (CPU-only)
  • Install an older version of the PyTorch binaries that support your compute capability (not recommended as PyTorch 0.3.1 is very outdated at this point). AFAIK compute capability older than 3.X has never been supported in the pre-built binaries
  • Upgrade your graphics card

If your graphics card doesn't support the required version of CUDA (section 1) then your options are

  • Install PyTorch without CUDA support (CPU-only)
  • Install an older version of PyTorch that supports a CUDA version supported by your graphics card (still may require compiling from source if the binaries don't support your compute capability)
  • Upgrade your graphics card
6
  • torch.zeros(1).cuda() returns nothing for me. Just a blank line. I've got a 2070 SUPER and CUDA 11.1
    – Paze
    Sep 20, 2020 at 11:20
  • 2
    Great answer! This helped me to pinpoint the issue very easily
    – code
    Oct 30, 2020 at 14:35
  • @jodag, thank you for the detailed information. I have been trying to test installing GPU-Pytorch, and listed my observation in stackoverflow.com/questions/69517271/… I tried to follow your notes on understanding why I cannot choose cuda11.1, but I am still not clear why I cannot, would you like to take a look at my question, thank you very much.
    – user288609
    Oct 10, 2021 at 17:10
  • 1
    Here's NVIDIA's listing of compute capabilities per GPU model, if you don't want to rely on Wikipedia's info: developer.nvidia.com/cuda-gpus. You'll still have to look at the Wikipedia page to link the compute capabilities to CUDA version support though.
    – jurrdb
    Jan 19, 2022 at 14:57
  • Great answer! This helped me to pinpoint the issue very easily also. Now I just need to replace the PyTorch-CPU package with the PyTorch-GPU package compiled against the CUDA driver. Nov 14, 2022 at 2:06
6

To solve this issue, the following method answered for me:

1- First you have to update Anaconda.

2- In your notebook, select the following based on your system.

https://pytorch.org/

enter image description here

example for Windows:(This may take some time. Be patient)

conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch

3- Find and install the latest graphics card for your system through the following site:

https://www.nvidia.com/Download/index.aspx

enter image description here

4- Supported CUDA level of GPU and card. see this

1
  • 1
    I did all of that & still pytorch doesnt find my card
    – DrBwts
    Sep 29, 2022 at 19:49
3

Step 1.) Check your cuda and GPU DRIVER version using nvidia-smi . This will be helpful in downloading the correct version of pytorch with this hardware

Step 2.) Check if you have installed gpu version of pytorch by using conda list pytorch If you get "cpu_" version of pytorch then you need to uninstall pytorch and reinstall it by below command

    ```` conda uninstall pytorch 
     conda install pytorch torchvision cudatoolkit=11.3 -c pytorch -c conda-forge ````
3

After a couple hours of reinstalling drivers on my system, what actually solved it for me was using a fresh conda environment:

# Create conda environment
conda create --name cuda_venv
conda activate cuda_venv

# Install pytorch following commands from https://pytorch.org/get-started/locally/ 
conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia

then the following should print true

import torch
print(torch.cuda.is_available()) 

The above (i.e. CUDA 11.6) works for me even though I have CUDA 11.7 installed on my system, as I believe the system installation is unnecessary if using conda.

Output of nvidia-smi:

NVIDIA-SMI 515.86.01 Driver Version: 515.86.01 CUDA Version: 11.7

1
  • save my 2 days , you are the hero
    – wkm
    Jul 27 at 13:06
2

The same error can appear when the version of your Pytorch supports different CUDA. For example, my Pytorch version was with CUDA 8.0 support, but I had CUDA 9.0 installed. To fix that I had to upgrade my Pytorch to cu90 like this:

pip install torch_nightly -f https://download.pytorch.org/whl/nightly/cu90/torch_nightly.html

Reference: here

0
1

I want to share also my experience, especially in the WSL2 environment. See my post here.

Despite I had installed the correct and latest drivers following the guide provided by NVidia here, my WSL was not able to detect any GPU both in PyTorch and in the whole environment.

My GPU is Nvidia GeForce RTX 1650 Ti, which is not listed in the Wiki link above but is actually shown in the NVidia page.

Downgrading to an older driver version found at this NVidia link, namely Driver Version: 472.39 helped me out. Now PyTorch can correctly detect the driver, as well as I can run containers that require GPU access since it is correctly found and used.

Hoping this will help someone in my situation.

2
  • I have the same problem (WSL2+nvidia), when I downgraded to 472.39, I found that torch.version.cuda returns a different (older) version of cuda than what's shown in nvidia-smi, Do you know what possibly causes this. EDIT: it seems the nvidia-smi version is just the latest version that is supported by my gpu not the toolkit installed, so my problem is still unsolved/unrelated to this issue Feb 12, 2022 at 13:43
  • Okay for me downgrading torch version to LTS version fixed the issue, thanks to this SO comment Feb 12, 2022 at 21:44
1

ok here's my experience my system is ubuntu 20.4, gpu - nvidi gtx 1060

when i go and change run the 'Nvidia X Server Settings' application i found under the PRIME Profiles Nvidia On-Demand or Inter(power saving mode) is selected

giving torch.cuda.is_available() to False

i changed the GPU Mode to 'NVIDIA(Performance Mode) then i got True

NVIDIA X Server Setting-GUI

1
  • This fixed my issue aswell. nvidia-smi printed, i had the correct driver, and my card supports the cuda version that followed with the torch installation. This is what i needed for torch to utilize cuda
    – S.MC.
    Dec 6, 2022 at 13:41
1

Just faced the same with my GPU (last available driver installed), none of above helped, searching for hours over Google also no luck. Here's what worked out for me:

  1. Delete all environments that were created in Anaconda. Uninstall Anaconda and delete all related folders in "user" folder

  2. Install Anaconda

  3. Add conda-forge to channels https://conda-forge.org/docs/user/introduction.html

  4. Run through installation Guide from NVIDIA https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html

  5. Choose proper configuration and run conda installation https://pytorch.org/get-started/locally/ IF installation failed with well-known failed with initial frozen solve. Retrying with flexible solve. go with pip3 install instead of conda

  6. Enjoy your GPU in Jupyter Notebook:

    import torch torch.cuda.is_available() True

1

I had a similar issue with a GPU with MIG mode. I had to disable the MIG mode:

>> nvidia-smi -mig 0

As pointed out by ptrblck, it was enable by default but I didn't create any MIG devices. You can try to create them (user guide).

1

I encountered a problem when using Conda to set up the environment. I followed the documentation and used the following command to install the packages:

$ conda install pytorch torchvision torchaudio cudatoolkit=11.1

However, I got False. I tried many methods, but I didn't question the correctness of the documentation, which took me a lot of time.

Then, I checked the corresponding pytorch version as follows:

$ conda list pytorch
pytorch                   2.0.0               py3.9_cpu_0    pytorch
pytorch-mutex             1.0                         cpu    pytorch
cudatoolkit               11.1.1              heb2d755_10    conda-forge

I noticed that PyTorch has the word "cpu", so I uninstalled all pytorch packages and reinstalled them using the following commands:

$ conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
$ conda install -c anaconda cudatoolkit

I checked the version again:

$ conda list pytorch
pytorch                   2.0.0           py3.9_cuda11.8_cudnn8_0    pytorch
pytorch-cuda              11.8                 h24eeafa_3    pytorch
pytorch-mutex             1.0                        cuda    pytorch
cudatoolkit               11.3.1               h59b6b97_2    anaconda

Finally, I got True.

0

In my case, I had CUDA 12.0, torch==1.10.0 and torchvision==0.11.1 packages installed. I uninstalled CUDA 12.0 and installed CUDA 11.3

torch and torchvision packages must be compatible with the CUDA. Anyone having this problem can check the below site for compatibility.

https://pytorch.org/get-started/previous-versions/

0

I had this issue, at first I thought it could be hardware/physical connection issues, NVIDIA driver, CUDA version, pytorch version, or a system wide issue.

I checked the hardware was fine in device manager, and then checked the software versions, all fine. So i had to check the system wide application control aspect...

I saw my laptop was using the smaller AMD GPU instead of the more powerful NVIDIA GPU for some or all applications. I was told to

  • Check your NVIDIA Control Panel settings
  • Check your laptop's power settings.
  • Check your application settings.

From this I realised the power options were at fault.

  • Look for the "Graphics settings" section and expand it.
    • Make sure that the "Maximum processor state" for both "On battery" and "Plugged in" is set to 100%. If it's set to a lower value, your laptop may be using the smaller GPU to save power.
  • Look for the "PCI Express" section and expand it.
    • Make sure that "Link State Power Management" is set to "Off" for both "On battery" and "Plugged in". If it's set to "Moderate power savings" or "Maximum power savings", your laptop may be throttling the NVIDIA GPU to save power.

For me the link state was trying to conserve power and hence putting my NVIDIA GPU in an idle mode... ta da.

0

In my case, the problem was Python version itself. I tried installing torch with CUDA 11.8 and conda somehow installed it on Python=3.7.4 which is not supported. I just needed Python=3.8.10 and everything worked fine. You can check if python version is compatible in release notes like this one:

https://pytorch.org/blog/deprecation-cuda-python-support/

The website that led me to this conclusion:

https://discuss.pytorch.org/t/not-able-to-download-pytorch/173624/5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.