错误信息:
RuntimeError: The detected CUDA version (12.4) mismatches the version that was used to compile PyTorch (11.6). Please make sure to use the same CUDA versions.
解决办法:
在conda环境中使用以下命令:安装CUDA 11.6、PyTorch 1.12.1、torchvision 0.13.1和torchaudio 0.12.1
pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 torchaudio==0.12.1+cu116 --index-url https://download.pytorch.org/whl/cu116
验证:
import torch
# 检查 PyTorch 版本
print(f"PyTorch 版本: {torch.__version__}")
# 检查 CUDA 是否可用
print(f"CUDA 是否可用: {torch.cuda.is_available()}")
# 检查 CUDA 版本
print(f"CUDA 版本: {torch.version.cuda}")
# 检查 GPU 名称
if torch.cuda.is_available():
print(f"GPU 名称: {torch.cuda.get_device_name(0)}")