RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [2708, 7]], which is output 0 of ReluBackward0, 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).
解决方法是:
将 model 中所有的类似 a + =b,改为a = a + b
具体可以参考:
https://blog.51cto.com/u_11384719/6447673