You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyTorch无法调用GPU(CUDA)的问题求助

PyTorch无法调用GPU(CUDA)的问题求助

大家好!我遇到了一个棘手的问题——尝试让PyTorch调用GPU(CUDA)但一直失败,折腾了好久都没解决,想请各位帮忙排查一下。

我已经安装了CUDA 12.6版本,也下载了标注为兼容CUDA 12.6的PyTorch,前后重装了好几次相关组件,但运行代码时Python始终提示找不到CUDA。我的设备配置是:RTX 3060显卡、24GB内存、AMD Ryzen 7处理器,Windows 11系统。

我运行的测试代码如下:

import torch

print(f"Is CUDA supported by this system?{torch.cuda.is_available()}")
print(f"CUDA version: {torch.version.cuda}")

# Storing ID of current CUDA device
cuda_id = torch.cuda.current_device()
print(f"ID of current CUDA device:{torch.cuda.current_device()}")

print(f"Name of current CUDA device:{torch.cuda.get_device_name(cuda_id)}")

得到的报错信息如下:

C:\Users\Valen\PycharmProjects\godhelpme.venv\Scripts\python.exe "D:\Programming shit\godhelpme\torchtest.py"
Traceback (most recent call last):
File "D:\Programming shit\godhelpme\torchtest.py", line 7, in <module>
cuda_id = torch.cuda.current_device()
File "C:\Users\Valen\PycharmProjects\godhelpme.venv\Lib\site-packages\torch\cuda\__init__.py", line 971, in current_device
_lazy_init()
~~~~~~~~~~^^
File "C:\Users\Valen\PycharmProjects\godhelpme.venv\Lib\site-packages\torch\cuda\__init__.py", line 310, in _lazy_init
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
Is CUDA supported by this system?False
CUDA version: None

Process finished with exit code 1

我自己试过的操作:

  • 多次重装CUDA 12.6
  • 重新下载安装标注兼容CUDA 12.6的PyTorch
  • 重启电脑和IDE

请问还有什么其他排查方向或者解决办法吗?

备注:内容来源于stack exchange,提问作者Валентин Прокопец

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 09:28:05