记一次BUG,RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

错误:

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [100, 1]], which is output 0 of TanhBackward0, is at version 1; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

场景:在训练pytorch网络的时候的报错。

记一次BUG,RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation
记一次BUG,RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

解决方法:

mu *= 2
改为:
mu = mu * 2

Original: https://www.cnblogs.com/Twobox/p/16736031.html
Author: Wei_Xiong
Title: 记一次BUG,RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/566194/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球