首页 > 其他分享 >AssertionError CUDA unavailable, invalid device 0 requested

AssertionError CUDA unavailable, invalid device 0 requested

时间:2023-06-05 20:33:07浏览次数:48  
标签:AssertionError requested unavailable torch meshgrid 报错 CUDA device type

报错信息

UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling warnings.warn('User provided device_type of \'cuda\', but CUDA is not available. Disabling')

AssertionError: CUDA unavailable, invalid device 0 requested

image-20230519112623478

报错原因

原因是运行的环境与 torch 的版本不匹配

报错解决

查看硬件信息

nvidia-smi

# 我这里的CUDA是11.1

image-20230519112358613

在Pytorch官网找到合适CUDA的版本。

也可以重新下载CUDA,再安装匹配的包(11.7版本示例:https://developer.nvidia.com/cuda-11-7-0-download-archive)

官网:https://pytorch.org/get-started/previous-versions/

在网页中搜索CUDA 11.1(我这里电脑是11.1版本),执行查找到的命令

# 先卸载之前的包
pip uninstall torch torchvision torchaudio

# 找到的命令
pip install torch==1.10.1+cu111 torchvision==0.11.2 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html

image-20230519112902409

检测

import torch

print(torch.__version__)
print(torch.cuda.is_available())  # 返回True则表示安装成功

"""
1.10.1+cu111
True
"""

注意

一定要找到合适版本的CUDAtorch,建议最好在虚拟环境中操作,以免造成其他影响。

扩展

解决报错

D:\Virtualenvs\gesture_recognition\lib\site-packages\torch\functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  ..\aten\src\ATen\native\TensorShape.cpp:2157.)
	return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]

点进去源码,修改

# return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
# 改为
return _VF.meshgrid(tensors, **kwargs, indexing = "ij") # type: ignore[attr-defined]

标签:AssertionError,requested,unavailable,torch,meshgrid,报错,CUDA,device,type
From: https://www.cnblogs.com/hkwJsxl/p/17458872.html

相关文章

  • unable to find valid certification path to requested target
    发生这种情况时,很有可能与证书无关,而是某个第三方类库获取不到了我的解决方案,找到原版本的AAR文件放到工程的LIBs目录中,引用到工程中 unabletofindvalidcertificationpathtorequestedtarget最新解决方案(更新于2023-04-08)置顶da_caoyuan已于 2023-04-0811......
  • 【随手记录】Unable to create requested service [org.hibernate.engine.jdbc.env.sp
    链接数据库报错 Unabletocreaterequestedservice[org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]出现这个问题基本是数据库的方言dialect或者驱动driver_class有问题,可以确认下dialect或者driver_class的配置和自己要链接的库、库版本是否一致,比如:spring.jpa......
  • X-Requested-With
    原文:https://www.jianshu.com/p/2828d2d137e7x-requested-with的作用以及用法详解x-requested-with请求头区分ajax请求还是普通请求在服务器端判断request来自Ajax请求(异步)还是传统请求(同步): 两种请求在请求的Header不同,Ajax异步请求比传统的同步请求多了一个头参数......
  • chatGP问答 - elasticsearch ,这个报错memory locking requested for elasticsearch p
    问:elasticsearch,这个报错memorylockingrequestedforelasticsearchprocessbutmemoryisnotlocked答:是的,我理解你的问题。当你在配置Elasticsearch时,如果遇到"memorylockingrequestedforelasticsearchprocessbutmemoryisnotlocked"错误,这通常表示El......
  • 爬虫案例 X-Requested-With 异步请求
    importrequestsfromcopyheadersimportheaders_raw_to_dicturl='https://eregpublicsecure.ksrzis.cz/Registr/RZPRO/Osoba'post_url=url+"/GetOsobaList"#headers信息X-Requested-With异步请求的时候需要headers_raw=b"""X-Req......
  • KEIL5--Error: L6915E: Library reports error: __use_no_semihosting was requested
    __use_no_semihostingwasrequested:要求不使用半主机模式。 比较简单的一个解决方法就是点击“魔术棒”,在Target标签下有个UseMicroLIB,勾选UseMicroLIB,再编译就不会报错了。”Use MicroLIB”,这是KEIL自带的一个简易的库,使用Use MicroLIB微库不需要强调不使用半主机(nos......
  • Unable to tunnel through proxy. Proxy returns "HTTP/1.1 503 Service Unavailable
    背景:某日,一正常项目迁移到新的服务器新的服务器,需要使用代理来访问之前能直接访问的接口,加完代理之后,发现无法获取数据了报错:org.springframework.web.client.ResourceAccessException:I/OerroronGETrequestfor"https://xxxxxxxxxx/xxxx":Unabletotunne......
  • Run Configuration Error: Broken configuration due to unavailable plugin or inval
    解决RunConfigurationError:Brokenconfigurationduetounavailablepluginorinvalidconfigurationdat这个问题:不知道在哪里设置的原因,本人瞎点了几处设置,结果导致tomcat不可以运行了,后来经多方博客指导,终于得出结论,是插件那里有问题了,更改很简单,点击file->settings->pl......
  • springcloud gateway根据服务名称进行路由失败There was an unexpected error (type=S
    出现错误,如下图:解决办法:检查自己的yaml文件:server:port:88spring:application:name:applicationNamecloud:nacos:discovery:server-addr:127.0.0.1:8848gateway:#开启服务发现路由(不开启跨域问题可能无法解决)disco......
  • python 报错AssertionError: process has already started
    python报错AssertionError:processhasalreadystarted现象  原因在Python中设置守护进程daemon,一定要放在start方法上面才会有效解决方法 ......