记一次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网络的时候的报错。
解决方法:
mu *= 2
改为:
mu = mu * 2