本文主要是介绍pytorch [GPU版] 安装教程 torch is_available() false 解决,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
安装GPU torch 踩坑
基础环境
Python 3.12.0
CUDA Version: 12.2
验证
import torch
print(torch.cuda.is_available())
x = torch.rand(5, 3)
print(x)结果
True
tensor([[0.7078, 0.8994, 0.3168],[0.6900, 0.3825, 0.5802],[0.4335, 0.4132, 0.8746],[0.2967, 0.5088, 0.9595],[0.6018, 0.3640, 0.8309]])
本人环境 CUDA Version: 12.2
cmd.exe > nvidia-smi.exe
Sat Jun 22 19:42:21 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 536.67 Driver Version: 536.67 CUDA Version: 12.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 NVIDIA GeForce RTX 4060 Ti WDDM | 00000000:01:00.0 On | N/A |
| 33% 45C P8 6W / 160W | 938MiB / 8188MiB | 4% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------++---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 1304 C+G ...__8wekyb3d8bbwe\WindowsTerminal.exe N/A |
| 0 N/A N/A 2124 C+G ...CBS_cw5n1h2txyewy\TextInputHost.exe N/A |
| 0 N/A N/A 6948 C+G ...__8wekyb3d8bbwe\Notepad\Notepad.exe N/A |
| 0 N/A N/A 7372 C+G C:\Windows\explorer.exe N/A |
| 0 N/A N/A 7412 C+G C:\Windows\System32\ShellHost.exe N/A |
| 0 N/A N/A 8432 C+G ...nt.CBS_cw5n1h2txyewy\SearchHost.exe N/A |
| 0 N/A N/A 8456 C+G ...2txyewy\StartMenuExperienceHost.exe N/A |
| 0 N/A N/A 8528 C+G D:\vscode\Code.exe N/A |
| 0 N/A N/A 8952 C+G ...1.0_x64__8wekyb3d8bbwe\Video.UI.exe N/A |
| 0 N/A N/A 9312 C+G ...t.LockApp_cw5n1h2txyewy\LockApp.exe N/A |
| 0 N/A N/A 9740 C+G ...s\System32\ApplicationFrameHost.exe N/A |
| 0 N/A N/A 11004 C+G ...crosoft\Edge\Application\msedge.exe N/A |
| 0 N/A N/A 11376 C+G ....0_x64__84gz00a5z79wr\os_server.exe N/A |
| 0 N/A N/A 17452 C+G ...on\126.0.2592.61\msedgewebview2.exe N/A |
| 0 N/A N/A 19144 C+G ...siveControlPanel\SystemSettings.exe N/A |
| 0 N/A N/A 19864 C+G ...crosoft\Edge\Application\msedge.exe N/A |
+---------------------------------------------------------------------------------------+
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:41:10_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0
下载cudn,并安装
https://developer.nvidia.com/cudnn-downloads?target_os=Windows&target_arch=x86_64&target_version=Agnostic&cuda_version=11https://developer.nvidia.com/rdp/cudnn-archive
安装的两种方法
第一种
pip install torch==2.3.1+cu118 -f https://download.pytorch.org/whl/torch_stable.html
国内下载太慢 使用其他下载器下载
第二种
https://download.pytorch.org/whl/cu118/torch-2.3.1%2Bcu118-cp312-cp312-win_amd64.whl
下载后 pip install torch-2.3.1+cu118-cp312-cp312-win_amd64.whl
这篇关于pytorch [GPU版] 安装教程 torch is_available() false 解决的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!