报错信息:
one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.LongTensor [32, 128]] is at version 32; 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).
解决方案
加上.clone()即可
示例
我的报错代码:
x = functionA(x)
修改之后的代码:
x = functionA(x.clone())
问题原因
clone()之后的返回值才支持梯度回溯,这里是梯度传播出错