Fixes issues with backward pass in LED/Longformer Self-attention #13613
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes the computational graph created when computing the global attention scores in LED/Longformer Self-attention. The current implementation breaks the computational graph preventing the model from running the backward pass correctly in some cases. As explained in the dedicated issue, this problem arises in the current version of PyTorch (PyTorch 1.9) but not in one of the previous ones (PyTorch 1.7.1).
This PR simply clones the appropriate tensors in order to avoid the issue.
clone()
is a differentiable operation so there are no changes to the actual model behaviour.The issue is carefully reproduced in the following Google Colab: https://colab.research.google.com/drive/13rKxs6Ype0kDEBlnywsGynE2zpzv2CR-?usp=sharing
Fixes #12613
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@ibeltagy @patrickvonplaten