gpt4 book ai didi

python - 即使安装了 CUDA 和带有 cuda 的 pytorch,Pytorch cuda 也不可用。怎么修?

转载 作者:行者123 更新时间:2023-12-05 05:58:25 25 4
gpt4 key购买 nike

我正在尝试在使用 WSL2 的 Windows 机器上将 pytorch 与我的 GPU (RTX 3070) 结合使用,但即使我遵循了 Nvidia 指南 (https://docs.nvidia.com/cuda/wsl-user-guide/index.html#abstract),我也无法让它工作。

nvidia-smi.exe 输出:

+-----------------------------------------------------------------------------+
| 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 输出:

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 输出:

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 输出:

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

我安装的pytorch版本:

torch             1.9.0+cu111
torchaudio 0.9.0
torchvision 0.10.0+cu111

但是pytorch告诉我cuda不可用:

Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
False

有谁知道我是否安装了我需要的所有软件包?我尝试了互联网上发布的许多解决方案,但仍然无效。

最佳答案

我的环境是(带有 NVIDIA GTX 1080Ti 的 Ubuntu 20.04):

$ 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

安装 CUDAcuDNN 后,我运行了从 https://pytorch.org/get-started/locally/ 获取的 followwing 命令带有选项(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

查找包:

(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 <pip>
torchaudio 0.9.1 <pip>
torchvision 0.10.1+cu111 <pip>

然后:

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

关于python - 即使安装了 CUDA 和带有 cuda 的 pytorch,Pytorch cuda 也不可用。怎么修?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68493965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com