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=11

https://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
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值