Pytorch cuda is unavailable even installed CUDA and pytorch with cuda. How to fix?
I'm trying to use pytorch with my GPU (RTX 3070) on my Windows machine using WSL2, but I couldn't get it work even though I followed the Nvidia guide (https://docs.nvidia.com/cuda/wsl-user-guide/index.html#abstract).
nvidia-smi.exe output:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 471.41       Driver Version: 471.41       CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| 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  NVIDIA GeForce ... WDDM  | 00000000:0A:00.0  On |                  N/A |
|  0%   40C    P5    12W / 220W |   1815MiB /  8192MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1384    C+G   Insufficient Permissions        N/A      |
|    0   N/A  N/A      1628    C+G   ...dows\System32\WWAHost.exe    N/A      |
|    0   N/A  N/A      3172    C+G   ...y\ShellExperienceHost.exe    N/A      |
|    0   N/A  N/A      5940    C+G   ...lPanel\SystemSettings.exe    N/A      |
|    0   N/A  N/A      6360    C+G   C:\Windows\explorer.exe         N/A      |
|    0   N/A  N/A      7280    C+G   ...artMenuExperienceHost.exe    N/A      |
|    0   N/A  N/A      7732    C+G   ...5n1h2txyewy\SearchApp.exe    N/A      |
|    0   N/A  N/A      8256    C+G   ...ekyb3d8bbwe\YourPhone.exe    N/A      |
|    0   N/A  N/A      8780    C+G   ...nputApp\TextInputHost.exe    N/A      |
|    0   N/A  N/A     10032    C+G   ...perience\NVIDIA Share.exe    N/A      |
|    0   N/A  N/A     10732    C+G   ...hyper\app-3.0.2\Hyper.exe    N/A      |
|    0   N/A  N/A     10804    C+G   ...kyb3d8bbwe\Calculator.exe    N/A      |
|    0   N/A  N/A     10852    C+G   ...in7x64\steamwebhelper.exe    N/A      |
|    0   N/A  N/A     12180    C+G   ...ge\Application\msedge.exe    N/A      |
|    0   N/A  N/A     13880    C+G   ...icrosoft VS Code\Code.exe    N/A      |
|    0   N/A  N/A     14724    C+G   ...b3d8bbwe\WinStore.App.exe    N/A      |
+-----------------------------------------------------------------------------+

nvcc -v output:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Wed_Jun__2_19:15:15_PDT_2021
Cuda compilation tools, release 11.4, V11.4.48
Build cuda_11.4.r11.4/compiler.30033411_0

dpkg -l | grep nvidia output:
ii  libnvidia-cfg1-470:amd64             470.57.02-0ubuntu0.20.04.1        amd64        NVIDIA binary OpenGL/GLX configuration library
ii  libnvidia-common-470                 470.57.02-0ubuntu0.20.04.1        all          Shared files used by the NVIDIA libraries  
rc  libnvidia-compute-450:amd64          450.51.05-0ubuntu1                amd64        NVIDIA libcompute package
rc  libnvidia-compute-465:amd64          465.27-0ubuntu0.20.04.2           amd64        NVIDIA libcompute package
ii  libnvidia-compute-470:amd64          470.57.02-0ubuntu0.20.04.1        amd64        NVIDIA libcompute package
ii  libnvidia-decode-470:amd64           470.57.02-0ubuntu0.20.04.1        amd64        NVIDIA Video Decoding runtime libraries    
ii  libnvidia-encode-470:amd64           470.57.02-0ubuntu0.20.04.1        amd64        NVENC Video Encoding runtime library       
ii  libnvidia-extra-470:amd64            470.57.02-0ubuntu0.20.04.1        amd64        Extra libraries for the NVIDIA driver      
ii  libnvidia-fbc1-470:amd64             470.57.02-0ubuntu0.20.04.1        amd64        NVIDIA OpenGL-based Framebuffer Capture runtime library
ii  libnvidia-gl-470:amd64               470.57.02-0ubuntu0.20.04.1        amd64        NVIDIA OpenGL/GLX/EGL/GLES GLVND libraries 
and Vulkan ICD
ii  libnvidia-ifr1-470:amd64             470.57.02-0ubuntu0.20.04.1        amd64        NVIDIA OpenGL-based Inband Frame Readback runtime library
ii  libnvidia-ml-dev                     10.1.243-3                        amd64        NVIDIA Management Library (NVML) development files
rc  nvidia-compute-utils-450             450.51.05-0ubuntu1                amd64        NVIDIA compute utilities
ii  nvidia-compute-utils-470             470.57.02-0ubuntu0.20.04.1        amd64        NVIDIA compute utilities
ii  nvidia-cuda-dev                      10.1.243-3                        amd64        NVIDIA CUDA development files
ii  nvidia-cuda-doc                      10.1.243-3                        all          NVIDIA CUDA and OpenCL documentation       
ii  nvidia-cuda-gdb                      10.1.243-3                        amd64        NVIDIA CUDA Debugger (GDB)
ii  nvidia-cuda-toolkit                  10.1.243-3                        amd64        NVIDIA CUDA development toolkit
rc  nvidia-dkms-450                      450.51.05-0ubuntu1                amd64        NVIDIA DKMS package
ii  nvidia-dkms-470                      470.57.02-0ubuntu0.20.04.1        amd64        NVIDIA DKMS package
ii  nvidia-driver-470                    470.57.02-0ubuntu0.20.04.1        amd64        NVIDIA driver metapackage
rc  nvidia-kernel-common-450             450.51.05-0ubuntu1                amd64        Shared files used with the kernel module   
ii  nvidia-kernel-common-470             470.57.02-0ubuntu0.20.04.1        amd64        Shared files used with the kernel module   
ii  nvidia-kernel-source-470             470.57.02-0ubuntu0.20.04.1        amd64        NVIDIA kernel source package
ii  nvidia-opencl-dev:amd64              10.1.243-3                        amd64        NVIDIA OpenCL development files
ii  nvidia-prime                         0.8.16~0.20.04.1                  all          Tools to enable NVIDIA's Prime
ii  nvidia-profiler                      10.1.243-3                        amd64        NVIDIA Profiler for CUDA and OpenCL        
ii  nvidia-settings                      450.51.05-0ubuntu1                amd64        Tool for configuring the NVIDIA graphics driver
ii  nvidia-utils-470                     470.57.02-0ubuntu0.20.04.1        amd64        NVIDIA driver support binaries
ii  nvidia-visual-profiler               10.1.243-3                        amd64        NVIDIA Visual Profiler for CUDA and OpenCL 
ii  screen-resolution-extra              0.18build1                        all          Extension for the nvidia-settings control panel
ii  xserver-xorg-video-nvidia-470        470.57.02-0ubuntu0.20.04.1        amd64        NVIDIA binary Xorg driver

dpkg -l | grep cuda output:
ii  cuda                                 11.4.0-1                          amd64        CUDA meta-package
ii  cuda-11-4                            11.4.0-1                          amd64        CUDA 11.4 meta-package
ii  cuda-cccl-11-4                       11.4.43-1                         amd64        CUDA CCCL
ii  cuda-command-line-tools-11-4         11.4.0-1                          amd64        CUDA command-line tools
ii  cuda-compiler-11-4                   11.4.0-1                          amd64        CUDA compiler
rc  cuda-cudart-11-0                     11.0.194-1                        amd64        CUDA Runtime native Libraries
ii  cuda-cudart-11-4                     11.4.43-1                         amd64        CUDA Runtime native Libraries
ii  cuda-cudart-dev-11-4                 11.4.43-1                         amd64        CUDA Runtime native dev links, headers     
ii  cuda-cuobjdump-11-4                  11.4.43-1                         amd64        CUDA cuobjdump
ii  cuda-cupti-11-4                      11.4.65-1                         amd64        CUDA profiling tools runtime libs.
ii  cuda-cupti-dev-11-4                  11.4.65-1                         amd64        CUDA profiling tools interface.
ii  cuda-cuxxfilt-11-4                   11.4.43-1                         amd64        CUDA cuxxfilt
ii  cuda-demo-suite-11-4                 11.4.43-1                         amd64        Demo suite for CUDA
ii  cuda-documentation-11-4              11.4.43-1                         amd64        CUDA documentation
ii  cuda-driver-dev-11-4                 11.4.43-1                         amd64        CUDA Driver native dev stub library        
ii  cuda-gdb-11-4                        11.4.55-1                         amd64        CUDA-GDB
ii  cuda-libraries-11-4                  11.4.0-1                          amd64        CUDA Libraries 11.4 meta-package
ii  cuda-libraries-dev-11-4              11.4.0-1                          amd64        CUDA Libraries 11.4 development meta-package
ii  cuda-memcheck-11-4                   11.4.43-1                         amd64        CUDA-MEMCHECK
ii  cuda-nsight-11-4                     11.4.43-1                         amd64        CUDA nsight
ii  cuda-nsight-compute-11-4             11.4.0-1                          amd64        NVIDIA Nsight Compute
ii  cuda-nsight-systems-11-4             11.4.0-1                          amd64        NVIDIA Nsight Systems
ii  cuda-nvcc-11-4                       11.4.48-1                         amd64        CUDA nvcc
ii  cuda-nvdisasm-11-4                   11.4.43-1                         amd64        CUDA disassembler
ii  cuda-nvml-dev-11-4                   11.4.43-1                         amd64        NVML native dev links, headers
ii  cuda-nvprof-11-4                     11.4.43-1                         amd64        CUDA Profiler tools
ii  cuda-nvprune-11-4                    11.4.43-1                         amd64        CUDA nvprune
ii  cuda-nvrtc-11-4                      11.4.50-1                         amd64        NVRTC native runtime libraries
ii  cuda-nvrtc-dev-11-4                  11.4.50-1                         amd64        NVRTC native dev links, headers
ii  cuda-nvtx-11-4                       11.4.43-1                         amd64        NVIDIA Tools Extension
ii  cuda-nvvp-11-4                       11.4.43-1                         amd64        CUDA Profiler tools
ii  cuda-repo-ubuntu2004-11-0-local      11.0.2-450.51.05-1                amd64        cuda repository configuration files        
ii  cuda-repo-wsl-ubuntu-11-4-local      11.4.0-1                          amd64        cuda repository configuration files        
ii  cuda-runtime-11-4                    11.4.0-1                          amd64        CUDA Runtime 11.4 meta-package
ii  cuda-samples-11-4                    11.4.43-1                         amd64        CUDA example applications
ii  cuda-sanitizer-11-4                  11.4.54-1                         amd64        CUDA Sanitizer
rc  cuda-toolkit-11-0                    11.0.2-1                          amd64        CUDA Toolkit 11.0 meta-package
ii  cuda-toolkit-11-4                    11.4.0-1                          amd64        CUDA Toolkit 11.4 meta-package
ii  cuda-toolkit-11-4-config-common      11.4.43-1                         all          Common config package for CUDA Toolkit 11.4.
ii  cuda-toolkit-11-config-common        11.4.43-1                         all          Common config package for CUDA Toolkit 11.
ii  cuda-toolkit-config-common           11.4.43-1                         all          Common config package for CUDA Toolkit.    
ii  cuda-tools-11-4                      11.4.0-1                          amd64        CUDA Tools meta-package
rc  cuda-visual-tools-11-0               11.0.2-1                          amd64        CUDA visual tools
ii  cuda-visual-tools-11-4               11.4.0-1                          amd64        CUDA visual tools
ii  libcudart10.1:amd64                  10.1.243-3                        amd64        NVIDIA CUDA Runtime Library
ii  nvidia-cuda-dev                      10.1.243-3                        amd64        NVIDIA CUDA development files
ii  nvidia-cuda-doc                      10.1.243-3                        all          NVIDIA CUDA and OpenCL documentation       
ii  nvidia-cuda-gdb                      10.1.243-3                        amd64        NVIDIA CUDA Debugger (GDB)
ii  nvidia-cuda-toolkit                  10.1.243-3                        amd64        NVIDIA CUDA development toolkit

The pytorch version I installed:
torch             1.9.0+cu111
torchaudio        0.9.0
torchvision       0.10.0+cu111

But pytorch tells me that cuda is not available:
Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0] on linux
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import torch
&gt;&gt;&gt; torch.cuda.is_available()
False

Does anyone know if I installed all the packages I need? I tried many solutions posted on the internet but still doesn't work.

My environment is (Ubuntu 20.04 with NVIDIA GTX 1080Ti):
$ nvidia-smi | grep CUDA
| NVIDIA-SMI 470.74       Driver Version: 470.74       CUDA Version: 11.4     |

$ nvcc -V               
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Aug_15_21:14:11_PDT_2021
Cuda compilation tools, release 11.4, V11.4.120
Build cuda_11.4.r11.4/compiler.30300941_0

After the installation of CUDA and cuDNN, I run this followwing command getting from https://pytorch.org/get-started/locally/ with options (PyTorch Stable 1.9.1, Linux, Pip, Python, CUDA 11.1).
pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

Find packages:
(test-py38) ➜  ~ conda list | grep torch
_pytorch_select           0.1                       cpu_0    defaults
pytorch                   1.8.1           cpu_py38h60491be_0    defaults
torch                     1.9.1+cu111               &lt;pip&gt;
torchaudio                0.9.1                     &lt;pip&gt;
torchvision               0.10.1+cu111              &lt;pip&gt;

Then:
$ python           
Python 3.8.11 (default, Aug  3 2021, 15:09:35) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import torch
&gt;&gt;&gt; torch.cuda.is_available()
True

