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则表示配置成功。