Ubuntu下PyTorch与CUDA是兼容的,但需注意版本匹配,具体如下:
pip show torch
或conda list | grep torch
查看已安装PyTorch的CUDA版本信息。nvidia-smi
查看驱动支持的CUDA最高版本)。pip install torch --index-url https://download.pytorch.org/whl/cu128
(CUDA 12.8)。import torch; print(torch.cuda.is_available())
,若返回True
则表示配置成功。