coreference-resolution icon indicating copy to clipboard operation
coreference-resolution copied to clipboard

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

Open XinyiYang5 opened this issue 6 years ago • 2 comments

Hi, when I ran coref.py file, I encountered a RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation. I've tried pytorch 0.4.1 in the requirements.txt and pytorch 1.0 but they got same error. Could you please look into this? Thanks!

File "coref.py", line 692, in trainer.train(150) File "coref.py", line 458, in train self.train_epoch(epoch, *args, **kwargs) File "coref.py", line 488, in train_epoch corefs_found, total_corefs, corefs_chosen = self.train_doc(doc) File "coref.py", line 555, in train_doc loss.backward() File "/opt/conda/envs/mlkit36/lib/python3.6/site-packages/torch/tensor.py", line 93, in backward torch.autograd.backward(self, gradient, retain_graph, create_graph) File "/opt/conda/envs/mlkit36/lib/python3.6/site-packages/torch/autograd/init.py", line 90, in backward allow_unreachable=True) # allow_unreachable flag RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

XinyiYang5 avatar Mar 24 '19 03:03 XinyiYang5

The inplace operation is defined here. I think I did it this way because in 0.4.1, dropout could only be applied to a packed sequence by first unpacking it, applying dropout, and then repacking it. This seems likely to have been fixed in pytorch 1.0...

shayneobrien avatar Mar 26 '19 11:03 shayneobrien

I was getting the exact same error for torch==1.1.0 Changing

self.emb_dropout = nn.Dropout(0.50, inplace=True)
self.lstm_dropout = nn.Dropout(0.20, inplace=True)

to

self.emb_dropout = nn.Dropout(0.50)
self.lstm_dropout = nn.Dropout(0.20)

fixed it. Just as written by the author above me. Thank you.

vaibkumr avatar Aug 04 '19 13:08 vaibkumr