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?
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.
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.
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\
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.You are good to go.
The original answer is posted here: https://stackoverflow.com/a/72650265/10468354. This is just for quick reference:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With