RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Fal

这篇具有很好参考价值的文章主要介绍了RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Fal。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

今天在跑yolov7的时候遇见,模型加载问题,因为我是使用CPU来加载pt模型的,但是出现了错误;

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

模型是使用CUDA跑的,但是加载是使用CPU加载的,报错的意思就是需要是需要反序列化加载,就是在加载模型的后面,加一个参数map_location,这个当时还以为是OS出现问题了(当时看见网上说是
1、CUDA版本不匹配
2、pytorch版本不对
3、OS模块出问题了),但是这个其实也都有可能,每个运行环境都不一样

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Fal

原始加载方式:

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Fal
报错:
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

解决方法:

在加载模型的时候加上map_location=‘cpu’

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
weigths = torch.load('yolov.pt',map_location='cpu')
model = weigths['model']
model = model.half().to(device)
_ = model.eval()

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Fal
希望这个对你有用!

谢谢点赞评论!文章来源地址https://www.toymoban.com/news/detail-509407.html

到了这里,关于RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Fal的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • 当出现RuntimeError:CUDA error:no kernel image is available for execution on the device 问题时候的pytorch安装方法

    当出现RuntimeError:CUDA error:no kernel image is available for execution on the device 问题时候的pytorch安装方法

    当出现一个明显的特征就是出现: RuntimeError:CUDA error:no kernel image is av ailable for execution on the device 这就说明你的显卡太低了 可以到这个路径下C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.1extrasdemo_suite, 找到deviceQuenry.exe这个文件拖到cmd命令窗口运行可以看到自身电脑的算力  从

    2024年02月01日
    浏览(38)
  • 解决:RuntimeError: CUDA error: device-side assert triggered

    @[TOC]解决办法:RuntimeError: CUDA error: device-side assert triggered 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. RuntimeError: CUDA error: device-side assert triggered CUDA kernel errors might be asynchronously reported at

    2024年02月12日
    浏览(11)
  • 【RuntimeError: CUDA error: device-side assert triggered】问题与解决

    【RuntimeError: CUDA error: device-side assert triggered】问题与解决

    当我在调试模型的时候,出现了如下的问题 /opt/conda/conda-bld/pytorch_1656352465323/work/aten/src/ATen/native/cuda/IndexKernel.cu:91: operator(): block: [5,0,0], thread: [63,0,0] Assertion `index = -sizes[i] index sizes[i] “index out of bounds”` failed. 通过提示信息可以知道是个数组越界的问题。但是如图一中第二行

    2024年01月21日
    浏览(12)
  • RuntimeError: nms_impl: implementation for device cuda:0 not found.

    RuntimeError: nms_impl: implementation for device cuda:0 not found.

    RuntimeError: nms_impl: implementation for device cuda:0 not found. 关于mmpose的网页搜索并不多,查了一些资料是cuda不匹配的问题,参考添加链接描述,后续检查了自己配置,是匹配的。 就卸载了mmcv-full ,在重新安装,安装命令是 没有后面的指定版本,运行demo时成功! 虽然卸载的和再重新

    2024年02月13日
    浏览(30)
  • BUG:RuntimeError: CUDA error: invalid device ordinal CUDA kernel errors might be asynchronously repo

    BUG:RuntimeError: CUDA error: invalid device ordinal CUDA kernel errors might be asynchronously repo

    参考链接 当运行以下代码出现报错: 报错信息如下 RuntimeError: CUDA error: invalid device ordinal 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. 报错完整截图 报错的信息告诉我们,编号\\\"1\\\"是无效的设

    2024年02月12日
    浏览(12)
  • 已解决RuntimeError: CUDA error: invalid device ordinal CUDA kernel errors might be asynchronously repo

    已解决RuntimeError: CUDA error: invalid device ordinal CUDA kernel errors might be asynchronously repo

    参考链接 当运行以下代码出现报错: 报错信息如下 RuntimeError: CUDA error: invalid device ordinal 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. 报错完整截图 报错的信息告诉我们,编号\\\"1\\\"是无效的设

    2024年02月04日
    浏览(15)
  • Bug小能手系列(python)_13: RuntimeError: CUDA error: device-side assert triggered CUDA kernel errors might

    Bug小能手系列(python)_13: RuntimeError: CUDA error: device-side assert triggered CUDA kernel errors might

    在运行 Python 代码时出现报错: RuntimeError: CUDA error: device-side assert triggered 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. 注意:报错对应的代码部分与实际出现错误的部分是不同的。具体报错

    2024年02月04日
    浏览(15)
  • 已解决RuntimeError: CUDA error: device-side assert triggered异常的正确解决方法,亲测有效!!!

    已解决RuntimeError: CUDA error: device-side assert triggered异常的正确解决方法,亲测有效!!! RuntimeError: CUDA error: device-side assert triggered 出现 CUDA error: device-side assert triggered 错误通常是由于 GPU 上的某些计算出现了问题,导致 CUDA 运行时库触发了设备端断言。 下滑查看解决方法 要解

    2024年02月07日
    浏览(10)
  • RuntimeError: FlashAttention is only supported on CUDA 11 and above

    RuntimeError: FlashAttention is only supported on CUDA 11 and above

    RuntimeError: FlashAttention is only supported on CUDA 11 and above 此错误的原因可能是 nvcc 的 CUDA 版本(通过键入“nvcc -V”获得,可能 11.0)与 torch (11.7) 的 CUDA 版本不匹配。 类似问题在这里解决: https://stackoverflow.com/questions/40517083/multiple-cuda-versions-on-machine-nvcc-v-confusion 我解决了这个问题通

    2024年02月07日
    浏览(9)
  • 解决RuntimeError: CUDA error: no kernel image is available for execution on the deviceCUDA

    解决RuntimeError: CUDA error: no kernel image is available for execution on the deviceCUDA

    解决RuntimeError: CUDA error: no kernel image is available for execution on the deviceCUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect. 在服务器复现代码的时候,遇到了上述错误,解决办法如下。 .bashrc文件在服务器上初始页面的配置文件的地方 参考:

    2024年02月16日
    浏览(14)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包