Torch CUDA is not available

Running following returns false:
import torch
torch.cuda.is_available()

nvidia-smi output: (driver version seems compatible with CUDA version)
±----------------------------------------------------------------------------+
| NVIDIA-SMI 442.19 Driver Version: 442.19 CUDA Version: 10.2 |
|-------------------------------±---------------------±---------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1650 WDDM | 00000000:01:00.0 Off | N/A |
| N/A 49C P8 5W / N/A | 132MiB / 4096MiB | 0% Default |
±------------------------------±---------------------±---------------------+

Using Python 3.7.6
Windows 10 laptop with NVIDIA GeForce GTX 1650
Torch version 1.4.0

Running deviceQuery and bandwidthTest returns all tests PASS successfull

torch.version.cuda returns none.

torch.backends.cudnn.enabled returns true.

Could not find a solution, tried re-installing Conda, CUDA, drivers, Pytorch - did not help.

Solution found: conda remove cpuonly

Did you do as the following?

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

Yes, tried this exact command first and the same one with 10.2 as well

Please uninstall cpuonly in your conda environment. If torch.version.cuda returns none, then it means that you are using a CPU only binary.

What is the command line that unstalls cpuonly?

conda uninstall cpuonly

I think you might install an incompatible pytorch version with your cuda version. Your CUDA is 10.2 while you cannot install any version of pytorch with CUDA version higher or lower.

The PyTorch binaries ship with their own CUDA runtime, so you would only need to install the appropriate NVIDIA driver to run PyTorch workloads. Your local CUDA toolkit will be used, if you want to build a custom CUDA extension or PyTorch from source.

I have the same issue (torch.version.cuda returns none) and I have tried uninstalling cpu only and it has not helped.

I have CUDA 11.2 and Pytorch 1.8.0 installed with GeForce MX150.

I am very new to coding in general so really confused as to why this is happening.

When I type nvidia-smi this comes up
-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.72 Driver Version: 461.72 CUDA Version: 11.2 |
|-------------------------------±---------------------±---------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 GeForce MX150 WDDM | 00000000:03:00.0 Off | N/A |
| N/A 35C P8 N/A / N/A | 136MiB / 2048MiB | 16% Default |
| | | N/A |
±------------------------------±---------------------±---------------------+

±----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 8984 C+G …IA GeForce Experience.exe N/A |
±----------------------------------------------------------------------------+

Your local toolkit won’t be used, if you’ve installed the conda binaries or pip wheels as described before.
If torch.version.cuda doesn’t return a valid CUDA runtime, the package didn’t ship with it and you’ve most likely installed a CPU-only version. If you have trouble installing it in your current environment, create a new one and reinstall PyTorch.

OK I created new environment and installed pytorch on new environment with the following command as recommended by the website.

conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge

still torch.version.cuda returns None.

Any suggestions or anything else I can try to give you more information?

In that case your NVIDIA driver might not be installed correctly. What does nvidia-smi show?
Did you install the CUDA toolkit? If so, are you able to compile and run the CUDA samples?

This is what nvidia-smi show.

I’m too much of a beginner to understand what compile and run the cuda samples mean. (Don’t need to explain it to me I will look it up later )

Could you first uninstall PyTorch again in the new environment, reinstall it and post the install log here, please?
I.e. post the output from your terminal after running conda install ....

I deleted the new environment all together so I created a new one and installed pytorch with the command conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge

and this is the ‘log’

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

Package Plan

environment location: c:\Users\yoon-python\anaconda3\envs\deeplearning

added / updated specs:
- cudatoolkit=11.1
- pytorch
- torchaudio
- torchvision

The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
blas-2.108                 |              mkl          13 KB  conda-forge
blas-devel-3.9.0           |            8_mkl          12 KB  conda-forge
ca-certificates-2020.12.5  |       h5b45459_0         173 KB  conda-forge
certifi-2020.12.5          |   py39hcbf5309_1         144 KB  conda-forge
freetype-2.10.4            |       h546665d_1         489 KB  conda-forge
intel-openmp-2020.3        |     h57928b3_311         2.0 MB  conda-forge
libblas-3.9.0              |            8_mkl         3.9 MB  conda-forge
libcblas-3.9.0             |            8_mkl         3.9 MB  conda-forge
liblapack-3.9.0            |            8_mkl         3.9 MB  conda-forge
liblapacke-3.9.0           |            8_mkl         3.9 MB  conda-forge
libpng-1.6.37              |       h1d00b33_2         724 KB  conda-forge
libuv-1.41.0               |       h8ffe710_0         341 KB  conda-forge
lz4-c-1.9.3                |       h8ffe710_0         134 KB  conda-forge
m2w64-gcc-libgfortran-5.3.0|                6         342 KB  conda-forge
m2w64-gcc-libs-5.3.0       |                7         520 KB  conda-forge
m2w64-gcc-libs-core-5.3.0  |                7         214 KB  conda-forge
m2w64-gmp-6.1.0            |                2         726 KB  conda-forge
m2w64-libwinpthread-git-5.0.0.4634.697f757|                2          31 KB  conda-forge
mkl-2020.4                 |     hb70f87d_311       172.4 MB  conda-forge
mkl-devel-2020.4           |     h57928b3_312         5.6 MB  conda-forge
mkl-include-2020.4         |     hb70f87d_311         696 KB  conda-forge
msys2-conda-epoch-20160418 |                1           3 KB  conda-forge
ninja-1.10.2               |       h5362a0b_0         273 KB  conda-forge
numpy-1.20.1               |   py39h6635163_0         5.3 MB  conda-forge
olefile-0.46               |     pyh9f0ad1d_1          32 KB  conda-forge
openssl-1.1.1j             |       h8ffe710_0         5.8 MB  conda-forge
pillow-8.1.2               |   py39h4fa10fc_0         670 KB
pip-21.0.1                 |     pyhd8ed1ab_0         1.1 MB  conda-forge
python-3.9.2               |h7840368_0_cpython        19.9 MB  conda-forge
python_abi-3.9             |           1_cp39           4 KB  conda-forge
pytorch-1.8.0              |py3.9_cuda11.1_cudnn8_0        1.53 GB  pytorch
setuptools-49.6.0          |   py39hcbf5309_3         954 KB  conda-forge
sqlite-3.34.0              |       h8ffe710_0         1.2 MB  conda-forge
tk-8.6.10                  |       h8ffe710_1         3.2 MB  conda-forge
torchaudio-0.8.0           |             py39         2.7 MB  pytorch
torchvision-0.9.0          |       py39_cu111         7.5 MB  pytorch
typing_extensions-3.7.4.3  |             py_0          25 KB  conda-forge
tzdata-2021a               |       he74cb21_0         121 KB  conda-forge
vc-14.2                    |       hb210afc_4          13 KB  conda-forge
vs2015_runtime-14.28.29325 |       h5e1d092_4         2.3 MB  conda-forge
wheel-0.36.2               |     pyhd3deb0d_0          31 KB  conda-forge
wincertstore-0.2           |py39hcbf5309_1006          15 KB  conda-forge
xz-5.2.5                   |       h62dcd97_1         211 KB  conda-forge
zlib-1.2.11                |    h62dcd97_1010         126 KB  conda-forge
zstd-1.4.9                 |       h6255e5f_0         915 KB  conda-forge
------------------------------------------------------------
                                       Total:        1.77 GB

The following NEW packages will be INSTALLED:

blas conda-forge/win-64::blas-2.108-mkl
blas-devel conda-forge/win-64::blas-devel-3.9.0-8_mkl
ca-certificates conda-forge/win-64::ca-certificates-2020.12.5-h5b45459_0
certifi conda-forge/win-64::certifi-2020.12.5-py39hcbf5309_1
cudatoolkit conda-forge/win-64::cudatoolkit-11.1.1-heb2d755_7
freetype conda-forge/win-64::freetype-2.10.4-h546665d_1
intel-openmp conda-forge/win-64::intel-openmp-2020.3-h57928b3_311
jpeg pkgs/main/win-64::jpeg-9b-hb83a4c4_2
libblas conda-forge/win-64::libblas-3.9.0-8_mkl
libcblas conda-forge/win-64::libcblas-3.9.0-8_mkl
liblapack conda-forge/win-64::liblapack-3.9.0-8_mkl
liblapacke conda-forge/win-64::liblapacke-3.9.0-8_mkl
libpng conda-forge/win-64::libpng-1.6.37-h1d00b33_2
libtiff pkgs/main/win-64::libtiff-4.1.0-h56a325e_1
libuv conda-forge/win-64::libuv-1.41.0-h8ffe710_0
lz4-c conda-forge/win-64::lz4-c-1.9.3-h8ffe710_0
m2w64-gcc-libgfor~ conda-forge/win-64::m2w64-gcc-libgfortran-5.3.0-6
m2w64-gcc-libs conda-forge/win-64::m2w64-gcc-libs-5.3.0-7
m2w64-gcc-libs-co~ conda-forge/win-64::m2w64-gcc-libs-core-5.3.0-7
m2w64-gmp conda-forge/win-64::m2w64-gmp-6.1.0-2
m2w64-libwinpthre~ conda-forge/win-64::m2w64-libwinpthread-git-5.0.0.4634.697f757-2
mkl conda-forge/win-64::mkl-2020.4-hb70f87d_311
mkl-devel conda-forge/win-64::mkl-devel-2020.4-h57928b3_312
mkl-include conda-forge/win-64::mkl-include-2020.4-hb70f87d_311
msys2-conda-epoch conda-forge/win-64::msys2-conda-epoch-20160418-1
ninja conda-forge/win-64::ninja-1.10.2-h5362a0b_0
numpy conda-forge/win-64::numpy-1.20.1-py39h6635163_0
olefile conda-forge/noarch::olefile-0.46-pyh9f0ad1d_1
openssl conda-forge/win-64::openssl-1.1.1j-h8ffe710_0
pillow pkgs/main/win-64::pillow-8.1.2-py39h4fa10fc_0
pip conda-forge/noarch::pip-21.0.1-pyhd8ed1ab_0
python conda-forge/win-64::python-3.9.2-h7840368_0_cpython
python_abi conda-forge/win-64::python_abi-3.9-1_cp39
pytorch pytorch/win-64::pytorch-1.8.0-py3.9_cuda11.1_cudnn8_0
setuptools conda-forge/win-64::setuptools-49.6.0-py39hcbf5309_3
sqlite conda-forge/win-64::sqlite-3.34.0-h8ffe710_0
tk conda-forge/win-64::tk-8.6.10-h8ffe710_1
torchaudio pytorch/win-64::torchaudio-0.8.0-py39
torchvision pytorch/win-64::torchvision-0.9.0-py39_cu111
typing_extensions conda-forge/noarch::typing_extensions-3.7.4.3-py_0
tzdata conda-forge/noarch::tzdata-2021a-he74cb21_0
vc conda-forge/win-64::vc-14.2-hb210afc_4
vs2015_runtime conda-forge/win-64::vs2015_runtime-14.28.29325-h5e1d092_4
wheel conda-forge/noarch::wheel-0.36.2-pyhd3deb0d_0
wincertstore conda-forge/win-64::wincertstore-0.2-py39hcbf5309_1006
xz conda-forge/win-64::xz-5.2.5-h62dcd97_1
zlib conda-forge/win-64::zlib-1.2.11-h62dcd97_1010
zstd conda-forge/win-64::zstd-1.4.9-h6255e5f_0

Proceed ([y]/n)? y

Downloading and Extracting Packages
m2w64-libwinpthread- | 31 KB | ####################################################################################### | 100%
blas-devel-3.9.0 | 12 KB | ####################################################################################### | 100%
openssl-1.1.1j | 5.8 MB | ####################################################################################### | 100%
wheel-0.36.2 | 31 KB | ####################################################################################### | 100%
m2w64-gmp-6.1.0 | 726 KB | ####################################################################################### | 100%
liblapacke-3.9.0 | 3.9 MB | ####################################################################################### | 100%
m2w64-gcc-libs-core- | 214 KB | ####################################################################################### | 100%
liblapack-3.9.0 | 3.9 MB | ####################################################################################### | 100%
python_abi-3.9 | 4 KB | ####################################################################################### | 100%
xz-5.2.5 | 211 KB | ####################################################################################### | 100%
libuv-1.41.0 | 341 KB | ####################################################################################### | 100%
mkl-2020.4 | 172.4 MB | ####################################################################################### | 100%
numpy-1.20.1 | 5.3 MB | ####################################################################################### | 100%
setuptools-49.6.0 | 954 KB | ####################################################################################### | 100%
tk-8.6.10 | 3.2 MB | ####################################################################################### | 100%
m2w64-gcc-libgfortra | 342 KB | ####################################################################################### | 100%
vc-14.2 | 13 KB | ####################################################################################### | 100%
mkl-devel-2020.4 | 5.6 MB | ####################################################################################### | 100%
vs2015_runtime-14.28 | 2.3 MB | ####################################################################################### | 100%
python-3.9.2 | 19.9 MB | ####################################################################################### | 100%
zstd-1.4.9 | 915 KB | ####################################################################################### | 100%
mkl-include-2020.4 | 696 KB | ####################################################################################### | 100%
torchvision-0.9.0 | 7.5 MB | ####################################################################################### | 100%
typing_extensions-3. | 25 KB | ####################################################################################### | 100%
m2w64-gcc-libs-5.3.0 | 520 KB | ####################################################################################### | 100%
zlib-1.2.11 | 126 KB | ####################################################################################### | 100%
pillow-8.1.2 | 670 KB | ####################################################################################### | 100%
freetype-2.10.4 | 489 KB | ####################################################################################### | 100%
msys2-conda-epoch-20 | 3 KB | ####################################################################################### | 100%
ca-certificates-2020 | 173 KB | ####################################################################################### | 100%
tzdata-2021a | 121 KB | ####################################################################################### | 100%
libblas-3.9.0 | 3.9 MB | ####################################################################################### | 100%
done

Thank you very much!!

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.