栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

【错误处理】RuntimeError: Output 1 of UnbindBackward is a view and its base or another view of its

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【错误处理】RuntimeError: Output 1 of UnbindBackward is a view and its base or another view of its

RuntimeError: Output 1 of UnbindBackward is a view and its base or another view of its 项目场景问题描述原因分析解决方案

项目场景

项目场景 运行项目文件 - train.py文件时报错。
项目地址 https://github.com/RayneSun/VTPLSTM

问题描述

运行项目文件 - train.py文件时报错

RuntimeError: Output 1 of UnbindBackward is a view and its base or another view of its base has been modified inplace. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified inplace. You should replace the inplace operation by an out-of-place one.

train.py文件报错代码区间

for index, num in enumerate(loss):
 loss[index] num * max(1 / (index 1), 0.2) # [1,1/2,1/3,1/4,1/5,1/5,...]
原因分析

错误提示 UnbindBackward的输出1是一个视图 它的基视图的另一个视图已经被修改了。该视图返回多个视图的函数的输出。不允许就地修改输出视图。应该用一个其它变量来替代当前变量 来完成修改操作。

在for循环运行的过程中 num中的元素会被修改 然而在下一轮循环中还会读取num的值并修改 此时Python会迷惑 是操作原始的num值还是在第一轮修改后的num值。

解决方案

代码不使用遍历方式 改为索引的方式 相当于引入了一个新的变量 避免了原地修改的错误。

for index, num in enumerate(loss):
 # 修改: 添加下面的这一条语句。
 num loss[index]
 loss[index] num * max(1 / (index 1), 0.2) # [1,1/2,1/3,1/4,1/5,1/5,...]
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/268235.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号