‘lengths‘ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor
今天在用pytorch训练模型遇到一个错误:
RuntimeError: ‘lengths’ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor
解决:
参考https://github.com/pytorch/pytorch/releases
inp = torch.rand(10, 2, 3, device=“cuda”)
lengths = torch.tensor([10, 7], device=“cuda”)
torch.nn.utils.rnn.pack_padded_sequence(inp, lengths)
RuntimeError: ‘lengths’ argument should be a 1D CPU int64 tensor,
but got 1D cuda:0 Long tensorEnsure the lenghts is already on the right device
lengths = lengths.cpu()
torch.nn.utils.rnn.pack_padded_sequence(inp, lengths)Runs fine with no implicit move across device
在torch\nn\utils\rnn.py 第244行附近
_VF._pack_padded_sequence(input, lengths, batch_first)
改为 _VF._pack_padded_sequence(input, lengths.cpu(), batch_first)
‘lengths‘ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor相关推荐
- 关于‘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 ...
- RuntimeError: ‘lengths‘ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor
- 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 ...
- 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_ ...
- 异常解决(一)-- RuntimeError: expected device cpu but got device cuda:0
最近在编写深度学习的相关代码,基于PyTorch,运行程序的时候,报错,报错内容如下所示: RuntimeError: expected device cpu but got device cuda: ...
- C++使用ffmpeg解码v模块,支持cpu解码、amd64平台的cuda解码和NX平台的Nvmpi解码
仓库代码:https://gitee.com/liudegui/ffmpeg_decode_video ffmpeg_decode_video 使用ffmpeg解码video模块,支持3种解码:cpu ...
- 活久见 kernel:NMI watchdog: BUG: soft lockup - CPU#8 stuck for 28s! [xsoftdd/12:0]
1. 引入 在一台linux机器上工作,没敲入任何命令,但命令行里突然出现 "kernel:NMI watchdog: BUG: soft lockup - CPU#8 stuck for ...
- TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to
问题描述: Traceback (most recent call last):File "D:\rotation-yolov5-master\detect.py", line 1 ...
- CPU双核补丁智能安装包 V3.0
在普通的Windows XP(SP2)操作系统中,基于需求切换,系统会根据负载改变ACPI处理器的性能状态,比如处理器电压.工作频率等.Windows XP的处理器功耗管理会在对应的处理器上采用这样的 ...
- 基于tensorflow-gpu + E5 CPU + GTX1660 SUPER + TESLA-P40 显卡 安装CUDA(11.8.0)
基于tensorflow-gpu + E5 CPU + GTX1660 SUPER + TESLA-P40 显卡 安装CUDA(11.8.0) 前言: 在此之前,写了一篇基于GTX1660显卡的CUD ...
最新文章
- Code Sign error: Provisioning profile 'xxxxxxxxxxxxxxxxxxxxxxxxx'
- 修改mysql用utf8mb4_更改MySQL数据库的编码为utf8mb4
- 导航菜单(移动出现子菜单)
- sql报表按月统计_如何通过INTOUCH组态软件做EXCEL报表(含代码)
- C#中将list进行序列化并使用SharpZipLib进行压缩
- idea本地跑如何看gc日志_牛逼了!用 IDEA 扒出了开源组件导致FGC的原因
- 【经典回放】多种语言系列数据结构算法:队列(C版)
- linux db2 权限管理,DB2五种管理权限
- 活动文档服务器,服务器 活动
- down perm什么意思_没想到“羽绒服”竟叫down coat!为啥有个down?
- 部署模型之Libtorch学习(一)
- 程序员高效学习的六原则
- centos7 redis 重启_linux下redis启动/关闭/重启服务配置
- 17张程序员搞笑图片
- 2022年最新全国各省五级行政区划代码及mysql数据库代码(省市区县乡镇村)
- VC6.0的兼容性问题解决方案
- 荧光量子产率计算机模拟,如何提高荧光染料的量子产率,或许可以从这里找到答案...
- spring注解开发配置spring父子容器
- 【无人机三维路径规划】基于A算法解决三维路径规划问题含危险障碍地形含Matlab源码
- 诺基亚C2-03 - 简单才是首要的诺基亚C2-03