问题描述

当使用比较新的显卡(比如NVIDIA GeForce RTX 3090)时,由于显卡的架构比较新,可能旧版本的pytorch库没有支持到。这时候就会出现capability sm_86 is not compatible的问题,同时根据输出可以看到 The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_70 sm_75当前pytorch只能支持上面几种架构。

问题解决

最常见的解决方式是升级Pytorch版本,新的版本增加了对新显卡架构的支持。但是有时候升级到1.10.0问题仍然没有解决,其实1.7.1版本的pytorch就已经支持3090,问题没有解决的原因大概率是CUDA版本的问题。3090显卡一般使用CUDA11+,而直接pip安装的pytorch可能是cuda10.2版本的,所以只依靠升级pytorch版本是不行的,还需要安装对应cuda版本的pytorch。

pip安装

直接使用pip安装 pip install torch==1.7.1+cu110 会报错,提示如下

Could not find a version that satisfies the requirement torch==1.7.1+cu110 (from versions: 1.4.0, 1.5.0, 1.5.1, 1.6.0, 1.7.0, 1.7.1, 1.8.0, 1.8.1, 1.9.0, 1.9.1, 1.10.0)
ERROR: No matching distribution found for torch==1.7.1+cu110

原因是在pip使用的镜像网站中没有指定cuda版本的torch链接,这时候需要去官网上找,可以看到pip 安装cuda11.3版本pytorch的命令

pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio==0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

我们可以去-f后面的网站找到对应的pytorch版本,也可以将cu113替换为其他版本的cuda,比如想要安装pytorch1.7.1+cuda11.0,可以使用下面的命令

pip3 install torch==1.7.1+cu110 torchvision==0.8.2+cu110 -f https://download.pytorch.org/whl/cu110/torch_stable.html

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐