【软件环境安装与使用】GeForce RTX 3080 with CUDA capability sm_86 is not compatible with the current PyTorch installation.

前言

博主在运行edgeai_yolov5的时候,出现了一些意料之外的错误,记之。

问题

NVIDIA GeForce RTX 3080 Ti 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.
RuntimeError: CUDA error: no kernel image is available for execution on the device
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.

原因

NVIDIA GeForce RTX 3080 Ti with CUDA capability sm_86意思是RTX 3080 Ti的算力是8.6,而当前安装好的pytorch最高只支持到7.5算力的显卡,也就是说显卡算力和pytorch版本不匹配。

从log可以看出与pytorch、CUDA版本之间是否匹配有关;

通过以下代码不能确定cuda是否可用,只是检测CUDA是否正确安装并能否被pytorch检测到;

import torch
# 在python的命令环境测试该命令 返回是True的,但是在run torch程序的时候报错
torch.cuda.is_available()

要测试显卡算力与当前pytorch是否匹配,可以进入python命令行,依次输入如下两行代码:

如果想要测是你的cuda版本torch是否可以使用,使用以下命令测试可能会更好。

import torch
torch.zeros(1).cuda()
 根据对应算力的话,算力为8.x的显卡使用的cuda版本应该大于等于11.0。
上面表面上是说PyTorch,实际上是PyTorch依赖的CUDA版本的问题。
RTX 3080的算力是8.6,3080Ti只能适用CUDA11.0以上的版本;需要重新安装对应CUDA可用版本的pytorch版本;
具体的nvidia、CUDA以及和pytorch版本之间的关系,可以参考here,个人感觉总结的非常清晰到位,点个赞~
 
解决方法
出现这个问题主要是edgeai_yolov5中requirements.txt指定安装pytorch=1.9.0版本,
pip install -r requirements.txt

pip之后默认安装的环境是torch1.9.0+cuda10.2,而3080ti的算力是8.6,支持的cuda版本应该不小于11.0,所以出错。

解决办法是修改requirements.txt中的torch相关内容的版本,comment取消torch相关的pip安装,直接使用conda安装指定的torch和cuda版本即可;

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch  # 最新版本的pytorch,也可以指定pytorch版本
pip install -r requirements.txt

其中-c pytorch表示指定使用pytorch channel,这个服务器位于国外,下载速度很慢,使用清华镜像源可以得到一个较快的下载速度。

update 20230113

问题

使用conda安装pytorch,每次都是默认安装了cpuonly组件,卸载cpuonly也是不行;添加清华源,还是不行;重启,重装conda,尝试了多种方法还是没解决这个问题;

昨天试过这个方法,不行,今天按照anaconda3 | 使用中常见错误中的方法都试了还不行,就又试了这个方法,先安装pytorch,是cpu版本,然后conda uninstall cpuonly,之后可以使用pytorch的gpu版本;奇哉怪哉。。。
conda update -n base conda
conda -V
conda update -n base conda
conda update --all
# 修改频道 
conda config --add channels conda-forge
conda config --set channel_priority flexible
conda install pytorch==1.9 cudatoolkit=11.3
conda uninstall cpuonly
 运行./setup.sh脚本之后,竟然要安装pytorch1.13.1,不知道为什么,明明requirements.txt中已经取消torch的安装。。。之后重新conda install pytorch+torchvision,然后requirements.txt中的torchvision也取消;
conda install pytorch==1.9 torchvision cudatoolkit=11.3
./setup.sh

 安装之后发现还是无法使用cuda版本的pytorch,错误如下:

AssertionError:Torch not compiled with CUDA enabled

原因分析:

重新安装之后还是不行,问题到底出在哪里呢???

感觉根本原因是pytorch源中没有对应的pytorch和cuda版本的工具包,可以根据pytorch_stable_version更改二者的版本进行指定版本安装;
比如安装pytorch1.10.0+cu11.3或者pytorch1.9.0+cu11.1;
conda install pytorch==1.10.0 torchvision torchaudio cudatoolkit=11.3

解决问题;

参考

1. GeForce RTX 3080 with CUDA capability sm_86 is not compatible with the current PyTorch installation.

2. nvidia显卡和CUDA版本关系

3. pytorch_stable_version

posted on 2022-06-29 18:19  鹅要长大  阅读(3967)  评论(0编辑  收藏  举报

导航