Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have a GPU and CUDA installed in Windows 10 but Pytorch's torch.cuda.is_available() returns false; how can I correct this?

I have PyTorch installed on a Windows 10 machine with a Nvidia GTX 1050 GPU. I have installed the CUDA Toolkit and tested it using Nvidia instructions and that has gone smoothly, including execution of the suggested tests.

However, torch.cuda.is_available() returns False. How can I fix this?

like image 941
user118967 Avatar asked Jul 28 '19 05:07

user118967


People also ask

Does torch include CUDA?

cuda. This package adds support for CUDA tensor types, that implement the same function as CPU tensors, but they utilize GPUs for computation. It is lazily initialized, so you can always import it, and use is_available() to determine if your system supports CUDA.


3 Answers

I also had the same issue. And running this => a=torch.cuda.FloatTensor(), gave the assertion error AssertionError: Torch not compiled with CUDA enabled . ...which kind of cleared that i was running pytorch without cuda.

Steps:

  1. Make sure you have un-installed Pytorch by invoking the following command:

    pip uninstall torch

  2. Go to https://pytorch.org/get-started/locally/ and select your system configurations(as shown in the figure).

  3. Copy the exact command from the Run this command dialog and run it on your terminal.

enter image description here

like image 175
sarjit07 Avatar answered Oct 16 '22 13:10

sarjit07


I had the same issue, and it turned out that I installed a CPU-only version by running the command provided by https://pytorch.org/get-started/locally/.

If you have CUDA 10.2 installed like me, the website would likely give you pip install torch===1.7.1 torchvision===0.8.2 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html, which doesn't explicitly specify CPU or GPU.

wrong command to install

In my case, it routed me to cpu/torch-1.7.1%2Bcpu-cp38-cp38-win_amd64.whl, which is a CPU version, instead of cu102/torch-1.7.1-cp38-cp38-win_amd64.whl for my CUDA 10.2.

My workaround is that, directly go to https://download.pytorch.org/whl/torch_stable.html and download the binary file matching your environment, and simply install from downloads folder:

pip install --no-cache-dir --force-reinstall torch===1.7.1 torchvision===0.8.2 -f .\Downloads\

like image 29
Ted Shaowang Avatar answered Oct 16 '22 12:10

Ted Shaowang


The reason for torch.cuda.is_available() resulting False is the incompatibility between the versions of pytorch and cudatoolkit.

As on Jun-2022, the current version of pytorch is compatible with cudatoolkit=11.3 whereas the current cuda toolkit version = 11.7. Source

Solution:

  1. Run conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch to install pytorch.
  2. Install CUDA 11.3 version from https://developer.nvidia.com/cuda-11.3.0-download-archive.

You are good to go. torch.cuda.is_available() --> True

The original answer is posted here: https://stackoverflow.com/a/72650265/10468354. This is just for quick reference:

like image 4
Chandan Avatar answered Oct 16 '22 12:10

Chandan