Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issues with backward pass in LED/Longformer Self-attention #13613

Merged

Conversation

aleSuglia
Copy link
Contributor

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

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@ibeltagy @patrickvonplaten

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@patrickvonplaten patrickvonplaten merged commit 19b7acd into huggingface:master Sep 17, 2021
@aleSuglia aleSuglia deleted the global-attention-backward-fix branch September 18, 2021 09:37
Albertobegue pushed a commit to Albertobegue/transformers that referenced this pull request Jan 13, 2022
…ices (huggingface#13613)

Co-authored-by: Alessandro Suglia <asuglia@fb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants