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

OPT/BioGPT: Improved attention mask shape exception #23270

Merged
merged 3 commits into from
May 16, 2023

Conversation

gante
Copy link
Member

@gante gante commented May 10, 2023

What does this PR do?

Related exception: #23197

Currently, in OPT/BioGPT, if we don't pass an attention mask or if we pass an attention mask with a wrong shape, an exception will be printed in the attention layer: Attention mask should be of size {(bsz, 1, tgt_len, src_len)}, but is {attention_mask.size()}. This exception has the following problems:

  1. It checks the expanded attention mask, not the attention mask as set by the user (or the default). Even as a maintainer, I can't immediately decode the error message, as I would need to know how the mask is expanded for the model in question.
  2. If there is a bug computing bsz, tgt_len, or src_len, the exception will be misleading.

In #23197 we found that when the length of past_key_values is equal to the length of the attention_mask, tgt_len and src_len will be wrong (in at least these 2 models), triggering the exception with an incorrect message. This PR solves both issues: it prevents the incorrect computation of tgt_len and src_len by checking the shape of attention_mask in the main model class, printing a user-friendly message.

If this PR gets approved, I will add a similar check to the other models.

@gante gante requested a review from amyeroberts May 10, 2023 16:15
Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for updating!

Just a small q about the assert logic

src/transformers/models/opt/modeling_tf_opt.py Outdated Show resolved Hide resolved
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented May 16, 2023

The documentation is not available anymore as the PR was closed or merged.

@gante gante merged commit 466af1a into huggingface:main May 16, 2023
@gante gante deleted the fix_23197 branch May 16, 2023 13:00
sheonhan pushed a commit to sheonhan/transformers that referenced this pull request Jun 1, 2023
gojiteji pushed a commit to gojiteji/transformers that referenced this pull request Jun 5, 2023
novice03 pushed a commit to novice03/transformers that referenced this pull request Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants