PyTorch 使用报错

  • 报错内容
  • 原因分析
  • 解决方案

报错内容

RuntimeError: ‘lengths’ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor

原因分析

因为我使用的是高版本的 torch 1.7.1,这个报错是由于torch 1.5 以上BiLSTM升级导致的。

解决方案

  1. 转到CPU运行代码就不报错了!
  2. 将报错的位置参数lengths转化为cpu 类型:
lengths.to("cpu")

即可解决!

参考:link

RuntimeError: ‘lengths’ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor相关推荐

  1. RuntimeError: ‘lengths‘ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor

  2. 关于‘lengths‘ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor报错的解决方发

    复现论文的时候遇到的BUG,后来发现是torch版本升级的原因,发个博客记录一下. 解决方法是需要修改RNN.py文件中的代码. 源代码在244行上下: data, batch_sizes = \_V ...

  3. Tensor for ‘out‘ is on CPU, Tensor for argument #1 ‘self‘ is on CPU

    1.问题 模型训练完后进行测试,报错 RuntimeError: Tensor for 'out' is on CPU, Tensor for argument #1 'self' is on CPU ...

  4. 异常解决(一)-- RuntimeError: expected device cpu but got device cuda:0

    最近在编写深度学习的相关代码,基于PyTorch,运行程序的时候,报错,报错内容如下所示: RuntimeError: expected device cpu but got device cuda: ...

  5. RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1.

    最近在修改模型不支持的算子后,由于对模型的效果产生了影响,所以需要进行微调训练,但是训练的时候报错了,如下: File "/home/xxxxxxx/EdgeNets/nn_layers/e ...

  6. PyTorch 错误 RuntimeError: invalid argument 5: k not in range for dimension at /pytorch/aten/src/THC/g

    PyTorch 错误 RuntimeError: invalid argument 5: k not in range for dimension at /pytorch/aten/src/THC/g ...

  7. RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0—问题分析

    声明: 这里仅仅提供一个思路,暂时没有绝对正确通用的解决方案 作者:{ 墨理 } 感谢通过私信.评论交流,协力探讨解决问题的同学 UP .Penser 文章目录 探讨的 pytorch 报错信息如下 ...

  8. Pytorch踩坑: RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0.

    报错信息: RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 186 a ...

  9. Cannot input a tensor of dimension other than 0 as a scalar argument

    Cannot input a tensor of dimension other than 0 as a scalar argument 错误代码: channels_per_group = num_ ...

  10. RuntimeError: dimension specified as 0 but tensor has no dimensions

    RuntimeError: dimension specified as 0 but tensor has no dimensions

最新文章

  1. python简单代码 春节集五福-新年福利来一波之Python轻松集齐五福(demo)
  2. Incomedia WebSite X5 17中文版
  3. linux服务器黑屏_xshell连接Linux系统(小红帽7.3)服务器,导致服务器黑屏
  4. 【转载】Nginx简介及使用Nginx实现负载均衡的原理
  5. nginx学习笔记002---Nginx代理配置_案例1_实现了对前端代码的方向代理_并且配置了后端api接口的访问地址
  6. vc中把数据库记录表导入Excel
  7. 对俄罗斯应用“一刀切”,乌克兰知名开发商推出 Mac 专用反间谍软件
  8. hastable与dictionary
  9. flex invalidation 机制
  10. 卸载MySQL安装包
  11. linux通过usb链接网络,Nokia N9 通过USB连接使用PC(Linux)主机的网络
  12. 【端口扫描工具】mascan核心使用
  13. 百度关键词地区排名查询php源码,百度关键词地区排名查询
  14. java贪吃蛇碰撞判定分析_java贪吃蛇碰撞检测
  15. linux基础之系统安装
  16. 生产服务器硬盘寻道时间,服务器01-硬盘篇(HDD)
  17. 8.HTML标签-表格标签table
  18. 基于Linux下的VIC使用(1)VIC部分(Fortran版本)
  19. 2021年茶艺师(中级)考试题库及茶艺师(中级)考试试卷
  20. Google面试官亲授Java面试课程

热门文章

  1. 项目管理论文十大领域各一篇
  2. 新视野大学英语3视听说教程智慧版听力原文 Further practice in listening
  3. 手机浏览器devtools_浏览器DevTools的秘诀:启动,网络和性能
  4. 厦门理工学院OJ题解(1223:Rite与跳舞毯)
  5. K-Means聚类算法原理及实现
  6. netty: LEAK: ByteBuf.release() was not called before it‘s garbage-collected
  7. 关于MySql使用索引的分析
  8. UnExpected Error, Quitting
  9. macos 系统固件 路径_itunes下载固件在哪里 itunes下载固件位置【介绍】
  10. Debian旧版本下载