当前位置:网站首页>one of the variables needed for gradient computation has been modified by an inplace
one of the variables needed for gradient computation has been modified by an inplace
2022-08-10 01:18:00 【江_小_白】
项目场景:
根据项目要求,需要使用两个优化器对模型进行优化
问题描述
运行中一直出现:
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [100, 5000]], which is output 0 of TBackward, is at version 3; expected version 2 instead. Hint: enable anomaly detection
解决方案:
经过网上查询发现,这个问题可能是由于出现了x+=3类似的代码,改成x = x + 1,更改过后发现仍旧不行,后来发现,在使用两个优化器进行优化是需要是如下格式:
optimizerG.zero_grad()
optimizerD.zero_grad()
loss1.backward(retain_graph=True)
loss2.backward()
optimizerD.step()
optimizerG.step()
必须将参数更新放在最后
边栏推荐
猜你喜欢
随机推荐
Not, even the volume of the king to write code in the company are copying and pasting it reasonable?
eyb:Redis学习(4)
Solidity最强对手:MOVE语言及新公链崛起
sql实战积累
基于设计稿识别的可视化低代码系统实践
hopscotch game
对修饰器的实验支持功能在将来的版本中可能更改。在 “tsconfig“ 或 “jsconfig“ 中设置 “experimentalDecorators“ 选项以删除此警告
[网鼎杯 2020 青龙组]AreUSerialz
Qt的pro文件递归搜寻添加文件
RESOURCE_EXHAUSTED: etcdserver: mvcc: database space exceeded
Solve the problem of sed replacement text containing special characters such as "/" and "#"
Process management and task management
UI遍历的初步尝试
微透镜阵列的高级模拟
DHCP——动态主机配置协议
【SSRF漏洞】实战演示 超详细讲解
不是吧,连公司里的卷王写代码都复制粘贴,这合理?
volatile 关键字(修饰符 volatile 告诉编译器,变量的值可能以程序未明确指定的方式被改变)
[论文阅读] Multimodal Unsupervised Image-to-Image Translation
【引用计数器及学习MRC的理由 Objective-C语言】