AssertionError: CUDA unavailable, invalid device 0 requested

在尝试使用GPU进行yolov5训练时遇到CUDA错误,nvcc -V显示命令不可用。即使在Linux下成功安装CUDA后,nvcc命令仍无法执行。尽管后续解决了nvcc的问题,torch.cuda.is_available()依然返回false。问题在于本地CUDA版本为10.1,而安装的PyTorch需要与CUDA 10.2兼容。解决方案包括检查并升级NVIDIA驱动至至少440.33.01版本,并确保CUDA工具包与PyTorch版本匹配。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

yolov5用gpu训练时报错了,nvcc -V一看,no command

Linux下安装好了cuda之后nvcc -V仍然无法执行

操作一番后,nvcc -V OK, but 问题依旧

How to Install PyTorch with CUDA 10.2

torch.cuda.is_available()返回false的解决办法

进入python查看当前pytorch是否可用gpu,发现是false

>>> import torch
>>> torch.cuda.is_available()
/home/ubuntu/anaconda3/envs/wby_py38/lib/python3.8/site-packages/torch/cuda/__init__.py:52: UserWarning: CUDA initialization: The NVIDIA driver on your system is too old (found version 10010). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver. (Triggered internally at  /pytorch/c10/cuda/CUDAFunctions.cpp:109.)
  return torch._C._cuda_getDeviceCount() > 0
False

再查看pytorch版本,可以看到pytorch版本是18,需要对应的cuda10.2,通过 "nvidia_smi" 看到本地的cuda是10.1,问题出在这里。

>>> torch.__version__
'1.8.1+cu102'

CUDA Toolkit Archive

通过cuda_10.2.89_440.33.01_linux.run确认下载显卡驱动版本大于等于440.33.01

NVIDIA Driver Downloads

torch.cuda.is_available()返回false——解决办法

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值