报错信息如下:
NVIDIA GeForce RTX 3090 with CUDA capability sm_86 is not compatible with the current PyTorch installation.
The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_70.
If you want to use the NVIDIA GeForce RTX 3090 GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/
查了一下百度翻译:
NVIDIA GeForce RTX 3090与CUDA功能sm_86不兼容当前的PyTorch安装。
当前的PyTorch安装支持CUDA功能sm_37 sm_50 sm_60 sm_70。
如果您想使用NVIDIA GeForce RTX 3090 GPU与PyTorch,请查看https://pytorch.org/get-started/locally/的说明
简单来说,就是说pytorch版本和cuda不匹配
查看一下显卡信息:nvidia-smi,显示11.6版本
11.6版本的cuda需要安装1.12.0或者1.12.1版本的pytorch
torchvision也需要安装相应的版本0.13.0
执行这条pip命令安装:
pip install torch==1.12.0+cu116 torchvision==0.13.0+cu116 torchaudio==0.12.0 --extra-index-url https://download.pytorch.org/whl/cu116
安装成功就不再报错,可以正常跑代码了!