1. 在Anaconda中创建相关虚拟环境
注:Torch2.8需要python版本大于等于3.9
我这里直接3.10版本创建(py310cuda128torch28是我起的环境名称,但其实torch装了2.7版本)
conda create --name py310cuda128torch28 python=3.10
2.Pytorch安装
直接官网上最高版本
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128

放心cuda版本自己就安装好了
5. 试验一下显卡可不可以用
import torch
print(f"PyTorch 版本: {torch.version}")
print(f"CUDA 是否可用: {torch.cuda.is_available()}")
print(f"CUDA 版本: {torch.version.cuda}")
print(f"GPU 设备: {torch.cuda.get_device_name(0)}")
ok完成