记一次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网络的时候的报错。
image
image

解决方法:

mu *= 2
改为:
mu = mu * 2
posted @ 2022-09-27 21:15  Wei_Xiong  阅读(465)  评论(0编辑  收藏  举报
WX:我是来搞笑的