Torch CUDA is not available

It looks correct, so I don’t know why torch.version.cuda returns None.
The torch.version.cuda tag would be automatically generated in torch/version.py and should return the shipped CUDA runtime regardless, if you can actually use the GPU or would be facing a driver issue etc.
You could check it at e.g. CONDA_PATH/envs/ENV_NAME/site-packages/torch/version.py.
Since it’s returning None I guess the installation isn’t successful or you are using another conda env.

OK. It is getting very confusing to me. Since you told me I could be using another conda environment (I activated the new environment… besides, my base environment also has correct pytorch installed anyways) I tried running the code in terminal instead of running it on the file.

It returns the wanted value! (ie torch.version.cuda returns 11.1 and torch.cuda.is_available() returns true)

However if I run the file which only has

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

it returns
None
False

Clearly I am too much of a newbie to understand what is going on?!

How are you running the file? Apparently when you run the file you are using a different environment than when you run python in the terminal :slight_smile:

I am using visual studio code and pressing the ‘green arrow’ button which the description says ‘run Python file in Terminal’ (which in my eye looks like I should be in the correct new environment…)

I had no idea the environment could be different… Very confusing… What could be done to fix this issue? My googling skill doesn’t seem to be good enough to find out.

Hi Jack, in this case almost surely the problem is due to different environments.
In the command line (where it works) run
where python
You should get the location of the binary for the environment. For example, in my case (I regrettably use the base env for everything) I get:
C:\Users\valer\anaconda3\python.exe
I don’t use Visual Studio Code but you should find your answer here:
Using Python Environments in Visual Studio Code. Your VScode interpreter should be the same as the one outputted by the command line.
Let me know if it works :slight_smile:

OK the issue has been resolved and I think the reason this all happened is because I have conda installed in different user’s directory. (This is due to the fact that my initial user name is in Non-English language so it was impossible to install conda so I created a dummy user to install conda)

So thank you ptrblack and Valerio_Biscione. I don’t think I would have solved issue anytime soon without your help!!

1 Like

Hi,
when I run “conda install torch”, I got this:
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  • torch

Current channels:

To search for alternate channels that may provide the conda package you’re
looking for, navigate to

https://anaconda.org

and use the search bar at the top of the page.

As given in the install instructions you would have to use conda install pytorch instead of torch.

Thanks ptrblck.
Actually, I have tried both already. I got this

Collecting package metadata (repodata.json): done
Solving environment: done

Package Plan

environment location: /home/sol/anaconda3/envs/concat1

added / updated specs:
- pytorch

The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
pytorch-0.4.0              |   py36hdf912b8_0       224.9 MB  defaults
------------------------------------------------------------
                                       Total:       224.9 MB

The following NEW packages will be INSTALLED:

intel-openmp pkgs/main/linux-64::intel-openmp-2021.2.0-h06a4308_610
nccl pkgs/main/linux-64::nccl-1.3.5-cuda9.0_0
pytorch pkgs/main/linux-64::pytorch-0.4.0-py36hdf912b8_0

The following packages will be SUPERSEDED by a higher-priority channel:

mkl conda-forge::mkl-2021.2.0-h726a3e6_389 → pkgs/main::mkl-2018.0.3-1

Proceed ([y]/n)? y

Downloading and Extracting Packages
pytorch-0.4.0 | 224.9 MB | ##################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

But still can’t import torch. And got: Torch CUDA is not Available

It seems conda is trying to download the old 0.4.0 release, so you might need to update conda to be able to use the current nightly.

I observe the following problem:

conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c nvidia
pytorch                       1.8.1  py3.9_cuda11.1_cudnn8.0.5_0
conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch -c nvidia
pytorch                       1.8.1  py3.9_cpu_0

can you help me figure out why the CPU only version is installed when using version 11.0 of the cudatoolkit?

PyTorch 1.8.1 wasn’t built with cudatoolkit=11.0 (the last PyTorch release with this CUDA runtime was 1.7.1), so you could install the release with cudatoolkit 11.1 or 10.2 as described in the install instructions.

1 Like

I am getting the same error for some Python/PyTorch combinations, for example, py3.9 and pt1.7

I’m unsure what “the same” error is referring to, but in case you are seeing @geoHeil’s error, note that 1.8.1 wasn’t built with cudatoolkit=11.0 as already mentioned and you would thus have to use 11.1 or 10.2.

@ptrblck
Hello ptrblck,

Do we need to explicitly install cudnn after running following command?

conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch-lts -c nvidia

Thanks ans regards,
sudhir

No, cudnn8.0.5 will be installed using your posted command and you can check it via:

torch.backends.cudnn.is_available()
torch.backends.cudnn.version()

@ptrblck

Thank you pytoch works like charm on my rtx 3080 now

Thanks and regards,
Sudhir

@ptrblck -

I know this thread seems to have run on forever, and please forgive me for asking, but I’m seemingly having the same issue on my Ubuntu 18.04 machine. I have followed what instructions I can above, but I’m also getting a CUDA Available = False result. Below is the output of environment, can you please provide guidance? thanks

(base) grbman@Zidane:~/GFPGAN$ nvidia-smi
Thu Jan 6 15:33:35 2022
±----------------------------------------------------------------------------+
| NVIDIA-SMI 418.226.00 Driver Version: 418.226.00 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 Quadro K1100M Off | 00000000:01:00.0 On | N/A |
| N/A 45C P0 N/A / N/A | 410MiB / 1991MiB | 1% Default |
±------------------------------±---------------------±---------------------+

±----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1117 G /usr/lib/xorg/Xorg 55MiB |
| 0 1233 G /usr/bin/gnome-shell 53MiB |
| 0 1533 G /usr/lib/xorg/Xorg 163MiB |
| 0 1661 G /usr/bin/gnome-shell 100MiB |
| 0 2713 G …AAgAAAAAAAAACAAAAAAAAAA= --shared-files 31MiB |
±----------------------------------------------------------------------------+

(base) grbman@Zidane:~/GFPGAN$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

(base) grbman@Zidane:~/GFPGAN$ gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

(base) grbman@Zidane:~/Downloads$ python3 collect_env.py
Collecting environment information…
PyTorch version: 1.10.1
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.6 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.27

Python version: 3.9.7 (default, Sep 16 2021, 13:09:58) [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.0-92-generic-x86_64-with-glibc2.27
Is CUDA available: False
CUDA runtime version: 9.1.85
GPU models and configuration: GPU 0: Quadro K1100M
Nvidia driver version: 418.226.00
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.20.3
[pip3] numpydoc==1.1.0
[pip3] torch==1.10.1
[pip3] torchaudio==0.10.1
[pip3] torchvision==0.11.2
[conda] blas 1.0 mkl
[conda] cpuonly 2.0 0 pytorch
[conda] cudatoolkit 10.2.89 hfd86e86_1
[conda] mkl 2021.4.0 h06a4308_640
[conda] mkl-service 2.4.0 py39h7f8727e_0
[conda] mkl_fft 1.3.1 py39hd3c417c_0
[conda] mkl_random 1.2.2 py39h51133e4_0
[conda] mypy_extensions 0.4.3 py39h06a4308_0
[conda] numpy 1.20.3 py39hf144106_0
[conda] numpy-base 1.20.3 py39h74d4b33_0
[conda] numpydoc 1.1.0 pyhd3eb1b0_1
[conda] pytorch 1.10.1 py3.9_cpu_0 pytorch
[conda] pytorch-mutex 1.0 cpu pytorch
[conda] torchaudio 0.10.1 py39_cpu [cpuonly] pytorch
[conda] torchvision 0.11.2 py39_cpu [cpuonly] pytorch

Please uninstall this.

As @Tony-Y already pointed out, you have installed the CPU-only version of the PyTorch binary, so CUDA won’t be available. However, your K1100M has a compute capability of 3.0, which is not supported in the current binaries anymore.