Torch的Bug处理:CUDA error:No kernel image is available..

Torch的Bug处理:CUDA error:No kernel image is available..

现象

在使用Torch时报错RuntimeError: CUDA error: no kernel image is available for execution on the device,具体代码如下:

import torch
torch.cuda.is_availabel()	# 显示:True
torch.ones(1).cuda()

打印信息如下:

/xx/xx/anaconda3/envs/xx/lib/python3.8/site-packages/torch/cuda/__init__.py:146: UserWarning: 
NVIDIA GeForce RTX 3060 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_61 sm_70 sm_75 compute_37.

If you want to use the NVIDIA GeForce RTX 3060 GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/

原因

打印信息的字面意思是PyTorch版本不支持当前显卡的算力。

我的显卡是GTX3060,算力8.6(可以在nvidia官网查询)

我的PyTorch版本是1.12.1,显然是老版本了。

解决

Step1. 卸载torch

pip uninstall torch torchvision torchaudio

Step2. 在torch官网下载更高或更低的版本,以匹配显卡(CUDA)算力

pip install torch==2.0.0+cu117 torchvision==0.15.1+cu117 torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cu117
# 我的情况是选择安装torch2.0,因为不匹配CUDA10.2,先重新安装了更高版本的nvidia显卡驱动与CUDA11.7,然后再安装了torch2.0。

最后解决了该问题。

PS:关于如何在Ubuntu上安装nvidia显卡驱动、CUDA、cudnn,请移步我的其他文章。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值