首先创建一个新环境,可以基于python3.10

conda create -n 新环境名称 python=3.10 -y
conda activate 新环境名称
# 安装 PyTorch 2.8.0 + CUDA 12.8
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
# 官方 CUDA 12.8 索引
pip install --index-url https://download.pytorch.org/whl/cu128 \
  torch torchvision torchaudio
  • 【2025年9月】无法使用conda安装,使用以下命令报错

conda install pytorch torchvision torchaudio pytorch-cuda=12.8 -c pytorch -c nvidia

PackagesNotFoundError: The following packages are not available from current channels:
pytorch-cuda=12.8

chatgpt:这个报错说明 pytorch-cuda=12.8 目前还没有在 Anaconda 官方 channel 放出来
(PyTorch 官网和 CondaForge 通常只提供到 pytorch-cuda=12.4,CUDA 12.8 版本目前只有 pip wheel 方式发布。)

验证是否安装成功

python - <<'PY'
import torch
print("torch =", torch.__version__)
print("cuda  =", torch.version.cuda)
print("avail =", torch.cuda.is_available())
print("device name =", torch.cuda.get_device_name(0))
print("capability =", torch.cuda.get_device_capability(0))
PY

输出

torch = 2.8.0+cu128
cuda  = 12.8
avail = True
device name = NVIDIA GeForce RTX 5060 Ti
capability = (12, 0)

为什么其他版本不可以

RuntimeError: CUDA error: no kernel image is available for execution on the device
...
NVIDIA GeForce RTX 5060 Ti with CUDA capability sm_120 ...
The current PyTorch install supports ... sm_50 sm_60 sm_70 sm_75 sm_80 sm_86 sm_90

你的显卡被识别为 sm_120(Compute Capability 12.0),而你当前安装的是 torch 2.1.2+cu121,它没有为 sm_120 编译内核或包含可 JIT 的 PTX,因此连最基础的 ReLU kernel 都起不来,就触发了 “no kernel image”。

Logo

中国智能体开发者社区,聚焦智能体与大模型开发,提供前沿资讯、实用工具链、开源项目及行业案例。通过技术沙龙、开发者大赛等活动,促进经验交流与协作,助力开发者快速构建创新智能应用。

更多推荐