RuntimeError: Tensor for 'out' is on CPU, Tensor for argument #1 'self' is on CPU, but expected them to be on GPU (while checking arguments for addmm

产生这类错误的原因,模型和数据未在相同设备上
解决方法:
将其放在同一设备上,模型和数据都放在GPU上 net .to(“cuda”) data.to(“cuda”)

最后如果还出现相同错误,请检查网络模型定义部分,将nn.Linear() nn.LayerNorm()等放在def __init__函数里初始化
对于将不同结构组成一个module的情况,初始化时不要使用[],一定要使用nn.ModuleList()
如:

self.mlp_blocks = nn.ModuleList()
for _ in range(num_blocks):self.mlp_blocks.append(MixerBlock(tokens_mlp_dim, channels_mlp_dim, tokens_hidden_dim, channels_hidden_dim))

https://stackoverflow.com/questions/69872820/runtimeerror-tensor-for-out-is-on-cpu-tensor-for-argument-1-self-is-on-cp

https://blog.csdn.net/weixin_43760844/article/details/116047427

RuntimeError: Tensor for ‘out‘ is on CPU, Tensor for argument #1 ‘self‘ is on CPU, but expected them相关推荐

  1. 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 ...

  2. PyTorch 笔记(03)— Tensor 数据类型分类(默认数据类型、CPU tensor、GPU tensor、CPU 和 GPU 之间的转换、数据类型之间转换)

    1. Tensor 数据类型 Tensor 有不同的数据类型,如下表所示,每种类型都有 CPU 和 GPU 版本(HalfTensor)除外,默认的 tensor 是数据类型是 FloatTensor ...

  3. 06_2_Pytorch的基础数据类型、CPU tensor类型和GPU tensor类型、判断数据类型、CPU或GPU张量之间的转换、数据类型转换、1-4维向量、Tensor张量、Variable等

    1.6.2.Pytorch的基础数据类型 1.6.2.1.Torch定义了的七种CPU tensor类型和八种GPU tensor类型 1.6.2.2.基础数据类型 1.6.2.3.Pytorch数据 ...

  4. RuntimeError: set_sizes_contiguous is not allowed on a Tensor created from .data or .detach().

    报错信息如下: RuntimeError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_19156/27953557 ...

  5. tensor判断是否相等_PyTorch的Tensor(中)

    背景 在PyTorch的Tensor系列上一篇文章中: Gemfield:PyTorch的Tensor(上)​zhuanlan.zhihu.com Gemfield介绍了一个Tensor的创建过程,特 ...

  6. IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python

    报错原因分析: train_loss += loss.data[0] 是旧版本的Pytorch版本代码,在Pytorch0.4-0.5中会出现警告,不会报错, 在Pytorch0.5版本以上会报错 I ...

  7. pytorch tensor 初始化_PyTorch简明笔记[1]-Tensor的初始化和基本操作

    听麻麻说,偷偷收藏而不感谢是不礼貌的,至少应该点个赞~我觉得麻麻说的对! 不断地被人安利PyTorch,终于忍不住诱惑决定入坑了. 当初学习TensorFlow的时候,没有系统性地学习.之前TF的英文 ...

  8. 解决IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Pyth

    解决IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Pyth ...

  9. 【报错记录】RuntimeError: don‘t know how to restore data location of torch.FloatStorage (tagged with CPU)

    问题描述 在调试一个代码时,在输入参数都正确的情况下,报出 RuntimeError: don't know how to restore data location of torch.FloatSt ...

  10. invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a python number

    提示 Use tensor.item() to convert a 0-dim tensor to a Python number 原语句:running_loss+=loss.data[0]修改后: ...

最新文章

  1. 016-热更新之FishingJoy一
  2. 使用nltk.pos出现IndexError: string index out of range
  3. 彻底火了!这份Python学习贴,90%程序员用的上!
  4. 网易新闻APP、喜马拉雅APP数据接口
  5. m1也能用的视频无损放大软件:topaz video enhance ai mac版
  6. 家庭和睦、人生平淡也是一种成功
  7. [ZROI1788]计算器
  8. CPA十二--我国外币会计报表折算(转载)
  9. Mapper method 'comxx' has an unsupported return type
  10. SpringCloud神兽(二)之Ribbon
  11. ShadowLayout 实现阴影效果
  12. Graphite介绍
  13. 2022年全国PMP考试地点汇总,你都知道吗?
  14. 廖雪峰Git教程学习笔记
  15. 5G/万物互联时代,这些智能设备和应用值得期待
  16. 【技术贴】怎么 豆瓣网在线看书
  17. linux下的source命令(.命令)解释及应用
  18. 十年时光 离开的谷歌给中国互联网界留下了这些人
  19. Ubuntu 驱动Mecury MW150UH无线网卡总结
  20. ERP服务器虚拟机,全球首发!Windows Server 2008虚拟机ERP压力测试

热门文章

  1. 2.5导入和混合配置 P61 Spring实战 第四版
  2. 树形导航栏(折叠)(jquery)
  3. 详细描述Tomcat体系结构(图文并茂)
  4. 普通学历,大一大二要不要打ACM?
  5. Android MediaRecorder录制视频
  6. linux学习之用户管理篇
  7. IBM X系列服务器通过sysmgmt接口查看日志
  8. STEAM 教育相关书籍
  9. WebIM 网页聊天工具
  10. 顺丰推出“丰食”平台 单挑美团饿了么胜算几何?