coli-saar / am-parser

Modular implementation of an AM dependency parser in AllenNLP.
Apache License 2.0
30 stars 10 forks source link

Error while retraining parser: Output 0 of SliceBackward is a view and is being modified inplace. #93

Closed ablodge closed 2 years ago

ablodge commented 2 years ago

Hello, while trying to retrain the parser on a toy corpus of about 1,000 sentences, on CPU, I got the following error:

Traceback (most recent call last):
  File "train.py", line 187, in <module>
    main()
  File "train.py", line 165, in main
    metrics = trainer.train(None, model_path=args.serialization_dir)
  File "./saarland-parser/graph_dependency_parser/train/amtrainer.py", line 503, in train
    train_metrics = self._train_epoch(epoch)
  File "./saarland-parser/graph_dependency_parser/train/amtrainer.py", line 345, in _train_epoch
    loss = self.batch_loss(batch_group, for_training=True)
  File "./saarland-parser/graph_dependency_parser/train/amtrainer.py", line 286, in batch_loss
    output_dict = self.model(**batch)
  File "/Users/austinblodgett/opt/anaconda3/envs/saarland/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "./saarland-parser/graph_dependency_parser/graph_dependency_parser.py", line 260, in forward
    ret = self.tasks[formalism_of_batch](encoded_text_parsing, encoded_text_tagging, mask, pos_tags, metadata, supertags, lexlabels, head_tags, head_indices)
  File "/Users/austinblodgett/opt/anaconda3/envs/saarland/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "./saarland-parser/graph_dependency_parser/components/AMTask.py", line 233, in forward
    edge_existence_loss = self.loss_function.edge_existence_loss(edge_existence_scores, head_indices, mask)
  File "./saarland-parser/graph_dependency_parser/components/losses/base.py", line 145, in edge_existence_loss
    return self.existence.loss(edge_scores,head_indices,mask)
  File "./saarland-parser/graph_dependency_parser/components/losses/KG.py", line 65, in loss
    return cle_loss(edge_scores,lengths,head_indices,self.normalize_wrt_seq_len)
  File "./saarland-parser/graph_dependency_parser/components/cle.py", line 85, in cle_loss
    m[range, g] -= 1.0 # cost augmentation
RuntimeError: Output 0 of SliceBackward is a view and is being modified inplace. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified inplace. You should replace the inplace operation by an out-of-place one.

It looks like a pytorch issue. Does this happen because I'm running on CPU?

jgroschwitz commented 2 years ago

Hi, I don't think this is due to the CPU. My guess is that it's the pytorch version. Which version are you using? We have tested the code with pytorch 1.1, and iirc newer versions can cause an error like this.

ablodge commented 2 years ago

That's exactly right! That fixed the issue I was having. Thank you.