Torch CUDA is not available

Aleksas: <p>Running following returns false:<br>
import torch<br>
torch.cuda.is_available()</p>
<p>nvidia-smi output: (driver version seems compatible with CUDA version)<br>
±----------------------------------------------------------------------------+<br>
| NVIDIA-SMI 442.19       Driver Version: 442.19       CUDA Version: 10.2     |<br>
|-------------------------------±---------------------±---------------------+<br>
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |<br>
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |<br>
|===============================+======================+======================|<br>
|   0  GeForce GTX 1650   WDDM  | 00000000:01:00.0 Off |                  N/A |<br>
| N/A   49C    P8     5W /  N/A |    132MiB /  4096MiB |      0%      Default |<br>
±------------------------------±---------------------±---------------------+</p>
<p>Using Python 3.7.6<br>
Windows 10 laptop with NVIDIA GeForce  GTX 1650<br>
Torch version 1.4.0</p>
<p>Running deviceQuery and bandwidthTest returns all tests PASS successfull</p>
<p>torch.version.cuda returns none.</p>
<p>torch.backends.cudnn.enabled returns true.</p>
<p>Could not find a solution, tried re-installing Conda, CUDA, drivers, Pytorch - did not help.</p>
<p>Solution found: conda remove cpuonly</p>

Tony-Y: <p>Did you do as the following?</p>
<pre><code class="lang-auto">conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
</code></pre>

Aleksas: <p>Yes, tried this exact command first and the same one with 10.2 as well</p>

peterjc123: <p>Please uninstall <code>cpuonly</code> in your conda environment. If torch.version.cuda returns none, then it means that you are using a CPU only binary.</p>

complexfilter: <p>What is the command line that unstalls cpuonly?</p>

peterjc123: <p>conda uninstall cpuonly</p>

Fang_Wu: <p>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.</p>

ptrblck: <p>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.</p>

Jack_Yoon: <p>I have the same issue (torch.version.cuda returns none) and I have tried uninstalling cpu only and it has not helped.</p>
<p>I have CUDA 11.2 and Pytorch 1.8.0 installed with GeForce MX150.</p>
<p>I am very new to coding in general so really confused as to why this is happening.</p>

Jack_Yoon: <p>When I type nvidia-smi this comes up<br>
-----------------------------------------------------------------------------+<br>
| NVIDIA-SMI 461.72       Driver Version: 461.72       CUDA Version: 11.2     |<br>
|-------------------------------±---------------------±---------------------+<br>
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |<br>
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |<br>
|                               |                      |               MIG M. |<br>
|===============================+======================+======================|<br>
|   0  GeForce MX150      WDDM  | 00000000:03:00.0 Off |                  N/A |<br>
| N/A   35C    P8    N/A /  N/A |    136MiB /  2048MiB |     16%      Default |<br>
|                               |                      |                  N/A |<br>
±------------------------------±---------------------±---------------------+</p>
<p>±----------------------------------------------------------------------------+<br>
| Processes:                                                                  |<br>
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |<br>
|        ID   ID                                                   Usage      |<br>
|=============================================================================|<br>
|    0   N/A  N/A      8984    C+G   …IA GeForce Experience.exe    N/A      |<br>
±----------------------------------------------------------------------------+</p>

ptrblck: <p>Your local toolkit won’t be used, if you’ve installed the conda binaries or pip wheels as <a href="https://discuss.pytorch.org/t/torch-cuda-is-not-available/74845/9">described before</a>.<br>
If <code>torch.version.cuda</code> 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.</p>

Jack_Yoon: <p>OK I created new environment and installed pytorch on new environment with the following command as recommended by the website.</p>
<p>conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c conda-forge</p>
<p>still torch.version.cuda returns None.</p>
<p>Any suggestions or anything else I can try to give you more information?</p>

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

Jack_Yoon: <aside class="quote no-group" data-username="Jack_Yoon" data-post="11" data-topic="74845">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/jack_yoon/48/32060_2.png" class="avatar"> Jack_Yoon:</div>
<blockquote>
<p>When I type nvidia-smi this comes up<br>
-----------------------------------------------------------------------------+<br>
| NVIDIA-SMI 461.72 Driver Version: 461.72 CUDA Version: 11.2 |<br>
|-------------------------------±---------------------±---------------------+<br>
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |<br>
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |<br>
| | | MIG M. |<br>
|===============================+======================+======================|<br>
| 0 GeForce MX150 WDDM | 00000000:03:00.0 Off | N/A |<br>
| N/A 35C P8 N/A / N/A | 136MiB / 2048MiB | 16% Default |<br>
| | | N/A |<br>
±------------------------------±---------------------±---------------------+</p>
<p>±----------------------------------------------------------------------------+<br>
| Processes: |<br>
| GPU GI CI PID Type Process name GPU Memory |<br>
| ID ID Usage |<br>
|=============================================================================|<br>
| 0 N/A N/A 8984 C+G …IA GeForce Experience.exe N/A |</p>
</blockquote>
</aside>
<p>This is what nvidia-smi show.</p>
<p>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 )</p>

ptrblck: <p>Could you first uninstall PyTorch again in the new environment, reinstall it and post the install log here, please?<br>
I.e. post the output from your terminal after running <code>conda install ...</code>.</p>

Jack_Yoon: <p>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</p>
<p>and this is the ‘log’</p>
<p>Collecting package metadata (current_repodata.json): done<br>
Solving environment: done</p>
<h2>Package Plan</h2>
<p>environment location: c:\Users\yoon-python\anaconda3\envs\deeplearning</p>
<p>added / updated specs:<br>
- cudatoolkit=11.1<br>
- pytorch<br>
- torchaudio<br>
- torchvision</p>
<p>The following packages will be downloaded:</p>
<pre><code>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
</code></pre>
<p>The following NEW packages will be INSTALLED:</p>
<p>blas               conda-forge/win-64::blas-2.108-mkl<br>
blas-devel         conda-forge/win-64::blas-devel-3.9.0-8_mkl<br>
ca-certificates    conda-forge/win-64::ca-certificates-2020.12.5-h5b45459_0<br>
certifi            conda-forge/win-64::certifi-2020.12.5-py39hcbf5309_1<br>
cudatoolkit        conda-forge/win-64::cudatoolkit-11.1.1-heb2d755_7<br>
freetype           conda-forge/win-64::freetype-2.10.4-h546665d_1<br>
intel-openmp       conda-forge/win-64::intel-openmp-2020.3-h57928b3_311<br>
jpeg               pkgs/main/win-64::jpeg-9b-hb83a4c4_2<br>
libblas            conda-forge/win-64::libblas-3.9.0-8_mkl<br>
libcblas           conda-forge/win-64::libcblas-3.9.0-8_mkl<br>
liblapack          conda-forge/win-64::liblapack-3.9.0-8_mkl<br>
liblapacke         conda-forge/win-64::liblapacke-3.9.0-8_mkl<br>
libpng             conda-forge/win-64::libpng-1.6.37-h1d00b33_2<br>
libtiff            pkgs/main/win-64::libtiff-4.1.0-h56a325e_1<br>
libuv              conda-forge/win-64::libuv-1.41.0-h8ffe710_0<br>
lz4-c              conda-forge/win-64::lz4-c-1.9.3-h8ffe710_0<br>
m2w64-gcc-libgfor~ conda-forge/win-64::m2w64-gcc-libgfortran-5.3.0-6<br>
m2w64-gcc-libs     conda-forge/win-64::m2w64-gcc-libs-5.3.0-7<br>
m2w64-gcc-libs-co~ conda-forge/win-64::m2w64-gcc-libs-core-5.3.0-7<br>
m2w64-gmp          conda-forge/win-64::m2w64-gmp-6.1.0-2<br>
m2w64-libwinpthre~ conda-forge/win-64::m2w64-libwinpthread-git-5.0.0.4634.697f757-2<br>
mkl                conda-forge/win-64::mkl-2020.4-hb70f87d_311<br>
mkl-devel          conda-forge/win-64::mkl-devel-2020.4-h57928b3_312<br>
mkl-include        conda-forge/win-64::mkl-include-2020.4-hb70f87d_311<br>
msys2-conda-epoch  conda-forge/win-64::msys2-conda-epoch-20160418-1<br>
ninja              conda-forge/win-64::ninja-1.10.2-h5362a0b_0<br>
numpy              conda-forge/win-64::numpy-1.20.1-py39h6635163_0<br>
olefile            conda-forge/noarch::olefile-0.46-pyh9f0ad1d_1<br>
openssl            conda-forge/win-64::openssl-1.1.1j-h8ffe710_0<br>
pillow             pkgs/main/win-64::pillow-8.1.2-py39h4fa10fc_0<br>
pip                conda-forge/noarch::pip-21.0.1-pyhd8ed1ab_0<br>
python             conda-forge/win-64::python-3.9.2-h7840368_0_cpython<br>
python_abi         conda-forge/win-64::python_abi-3.9-1_cp39<br>
pytorch            pytorch/win-64::pytorch-1.8.0-py3.9_cuda11.1_cudnn8_0<br>
setuptools         conda-forge/win-64::setuptools-49.6.0-py39hcbf5309_3<br>
sqlite             conda-forge/win-64::sqlite-3.34.0-h8ffe710_0<br>
tk                 conda-forge/win-64::tk-8.6.10-h8ffe710_1<br>
torchaudio         pytorch/win-64::torchaudio-0.8.0-py39<br>
torchvision        pytorch/win-64::torchvision-0.9.0-py39_cu111<br>
typing_extensions  conda-forge/noarch::typing_extensions-3.7.4.3-py_0<br>
tzdata             conda-forge/noarch::tzdata-2021a-he74cb21_0<br>
vc                 conda-forge/win-64::vc-14.2-hb210afc_4<br>
vs2015_runtime     conda-forge/win-64::vs2015_runtime-14.28.29325-h5e1d092_4<br>
wheel              conda-forge/noarch::wheel-0.36.2-pyhd3deb0d_0<br>
wincertstore       conda-forge/win-64::wincertstore-0.2-py39hcbf5309_1006<br>
xz                 conda-forge/win-64::xz-5.2.5-h62dcd97_1<br>
zlib               conda-forge/win-64::zlib-1.2.11-h62dcd97_1010<br>
zstd               conda-forge/win-64::zstd-1.4.9-h6255e5f_0</p>
<p>Proceed ([y]/n)? y</p>
<p>Downloading and Extracting Packages<br>
m2w64-libwinpthread- | 31 KB     | ####################################################################################### | 100%<br>
blas-devel-3.9.0     | 12 KB     | ####################################################################################### | 100%<br>
openssl-1.1.1j       | 5.8 MB    | ####################################################################################### | 100%<br>
wheel-0.36.2         | 31 KB     | ####################################################################################### | 100%<br>
m2w64-gmp-6.1.0      | 726 KB    | ####################################################################################### | 100%<br>
liblapacke-3.9.0     | 3.9 MB    | ####################################################################################### | 100%<br>
m2w64-gcc-libs-core- | 214 KB    | ####################################################################################### | 100%<br>
liblapack-3.9.0      | 3.9 MB    | ####################################################################################### | 100%<br>
python_abi-3.9       | 4 KB      | ####################################################################################### | 100%<br>
xz-5.2.5             | 211 KB    | ####################################################################################### | 100%<br>
libuv-1.41.0         | 341 KB    | ####################################################################################### | 100%<br>
mkl-2020.4           | 172.4 MB  | ####################################################################################### | 100%<br>
numpy-1.20.1         | 5.3 MB    | ####################################################################################### | 100%<br>
setuptools-49.6.0    | 954 KB    | ####################################################################################### | 100%<br>
tk-8.6.10            | 3.2 MB    | ####################################################################################### | 100%<br>
m2w64-gcc-libgfortra | 342 KB    | ####################################################################################### | 100%<br>
vc-14.2              | 13 KB     | ####################################################################################### | 100%<br>
mkl-devel-2020.4     | 5.6 MB    | ####################################################################################### | 100%<br>
vs2015_runtime-14.28 | 2.3 MB    | ####################################################################################### | 100%<br>
python-3.9.2         | 19.9 MB   | ####################################################################################### | 100%<br>
zstd-1.4.9           | 915 KB    | ####################################################################################### | 100%<br>
mkl-include-2020.4   | 696 KB    | ####################################################################################### | 100%<br>
torchvision-0.9.0    | 7.5 MB    | ####################################################################################### | 100%<br>
typing_extensions-3. | 25 KB     | ####################################################################################### | 100%<br>
m2w64-gcc-libs-5.3.0 | 520 KB    | ####################################################################################### | 100%<br>
zlib-1.2.11          | 126 KB    | ####################################################################################### | 100%<br>
pillow-8.1.2         | 670 KB    | ####################################################################################### | 100%<br>
freetype-2.10.4      | 489 KB    | ####################################################################################### | 100%<br>
msys2-conda-epoch-20 | 3 KB      | ####################################################################################### | 100%<br>
ca-certificates-2020 | 173 KB    | ####################################################################################### | 100%<br>
tzdata-2021a         | 121 KB    | ####################################################################################### | 100%<br>
libblas-3.9.0        | 3.9 MB    | ####################################################################################### | 100%<br>
done</p>
<p>Thank you very much!!</p>

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

Jack_Yoon: <p>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.</p>
<p>It returns the wanted value! (ie torch.version.cuda returns 11.1 and torch.cuda.is_available() returns true)</p>
<p>However if I run the file which only has</p>
<p>import torch<br>
print(torch.version.cuda)<br>
print(torch.cuda.is_available())</p>
<p>it returns<br>
None<br>
False</p>
<p>Clearly I am too much of a newbie to understand what is going on?!</p>

Valerio_Biscione: <p>How are you running the file? Apparently when you run the file you are using a different environment than when you run <code>python</code> in the terminal <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

Jack_Yoon: <p>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…)</p>
<p>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.</p>