autograd error

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

正向传播时:开启自动求导的异常侦测

torch.autograd.set_detect_anomaly(True)

反向传播时:在求导时开启侦测

with torch.autograd.detect_anomaly():
loss.backward()

你可能感兴趣的:(算法,NLP,自然语言处理,pytorch)