我在复现论文的代码时反复出现这个错误,终于在今天被我解决了,特此立帖记录

环境配置:

  • python 3.7.0
  • torch 1.7.0
  • cuda10.1
  • GPU: GeForce 3090*2
  • docker:nvidia/cuda:11.1.1-cudnn8-devel-ubuntu18.04 

出现这个错误“RuntimeError: CUDA error: no kernel image is available for execution on the device”是因为CUDA的版本和Torch版本不一致

进入docker输入以下代码:

>>python ##enter python
>>import torch
>>torch.cuda.is_available() #True
>>a=torch.Tensor([1,2])
>>a=a.cuda()

出现报错:

/root/anaconda3/envs/moreformer/lib/python3.7/site-packages/torch/cuda/__init__.py:104: UserWarning: 
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 sm_75.
If you want to use the NVIDIA GeForce RTX 3090 GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/

  warnings.warn(incompatible_device_warn.format(device_name, capability, " ".join(arch_list), device_name))

这里报错很清楚:,3090显卡所装的cuda版本与当前安装的pytorch版本不适配,或者说目前安装的pytorch不支持3090的算力

在NVIDIA官网:CUDA GPUs - Compute Capability | NVIDIA Developer

可以看到:3090对应的算力是sm_86

解决方案

更新CUDA版本,再匹配对应的Pytorch版本

可以参考下表:

pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐