Based on my understanding, this error occurs mostly when some input tensor with grad_fn that was created in previous computation is fed to the model. Normally, I can pinpoint the problem by checking the grad_fn of each input tensor, however, this time this error occurs when I am using Allennlp command line, in which a lot of data feeding operations are hided from us. I guess I can still to the same thing as previous, but with more effort to dissect the source code of Allennlp.