Reputation: 5722
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?
Upvotes: 38
Views: 67463
Reputation: 8019
I just spent about an hour fighting this problem, breaking down and building up at least four different conda environments. I finally got something to work using the same matrix selector at their web site but selected conda
, because conda seems to be working hard on getting a conda installation to work. And it worked! Here is the command that worked in my conda command line:
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
Obviously these details may change, but the command generated worked! Such a great feeling to see that True
after all this time.
Upvotes: 0
Reputation: 314
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.
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\
Upvotes: 12
Reputation: 37
Restarting your runtime is advisable, if it appears as if the other solutions did not work.
Upvotes: -1
Reputation: 530
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:
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
to install pytorch.The original answer is posted here: https://stackoverflow.com/a/72650265/10468354. This is just for quick reference:
Upvotes: 8
Reputation: 10559
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:
Make sure you have un-installed Pytorch by invoking the following command:
pip uninstall torch
Go to https://pytorch.org/get-started/locally/ and select your system configurations(as shown in the figure).
Copy the exact command from the Run this command
dialog and run it on your terminal.
Upvotes: 65