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

Show a warning for missing attention masks when pad_token_id is not None #24510

Merged
merged 6 commits into from
Jun 30, 2023

Conversation

hackyon
Copy link
Contributor

@hackyon hackyon commented Jun 27, 2023

What does this PR do?

Fixes #16136

Shows a one-time warning message when the pad_token_id is not None and no attention masks are given.

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@gante @ydshieh

@hackyon hackyon force-pushed the warning_attention_mask branch 2 times, most recently from 156a9a6 to d007683 Compare June 27, 2023 01:47
@hackyon
Copy link
Contributor Author

hackyon commented Jun 27, 2023

@ydshieh @gante

I've added the warning message as per #21916 and also a short test. Please let me know if you have any suggestions. If it looks good, I can copy/paste the warning to more models as well. Thanks!

@hackyon hackyon force-pushed the warning_attention_mask branch 2 times, most recently from 6492be3 to e286374 Compare June 27, 2023 03:37
@gante
Copy link
Member

gante commented Jun 27, 2023

@hackyon LGTM 👍

But before you spend time propagating the change to the other models, let's also get a green light from a core maintainer (cc @sgugger )

Copy link
Collaborator

@sgugger sgugger 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 your PR but I'm not in favor of this. There are a lot of false positives this is going to generate: an attention mask should be passed if there are any tokens in the inputs that are the pad token. It's not necessary to pass one just because the model has a pad token ID.

@hackyon
Copy link
Contributor Author

hackyon commented Jun 27, 2023

Thanks for the review.

Would it be better to check for the presence of the pad_token_id inside input_ids first before throwing the error, as per
https://github.com/huggingface/transformers/pull/17444/files? If so, I can make the change to reflect that here.

@hackyon
Copy link
Contributor Author

hackyon commented Jun 28, 2023

@sgugger

Thanks for the input. I changed my pull request up to be more like #17444. Let me know what you think. Thanks!

@hackyon hackyon force-pushed the warning_attention_mask branch from 2afcd03 to 6993429 Compare June 28, 2023 09:59
Copy link
Collaborator

@sgugger sgugger 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 iterating, I think it's better this way. Let's jsut reuse the warning_once API we have.

src/transformers/modeling_utils.py Outdated Show resolved Hide resolved
src/transformers/modeling_utils.py Outdated Show resolved Hide resolved
@hackyon
Copy link
Contributor Author

hackyon commented Jun 28, 2023

Thanks, I've updated the code accordingly.

JB Lau and others added 6 commits June 30, 2023 18:37
These warning messages when there are pad tokens within the input ids and
no attention masks are given. The warning message should only show up once.
These warning messages are shown when the pad_token_id is not None
and no attention masks are given. The warning message should only
show up once.
@hackyon hackyon force-pushed the warning_attention_mask branch from 2bdaa09 to da850a1 Compare June 30, 2023 10:41
@sgugger
Copy link
Collaborator

sgugger commented Jun 30, 2023

@gante could you have a second look here?

Copy link
Member

@gante gante left a comment

Choose a reason for hiding this comment

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

This is a nice comprehensive warning, I like it! 🔥

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 30, 2023

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

@sgugger sgugger merged commit 78a2b19 into huggingface:main Jun 30, 2023
@gante
Copy link
Member

gante commented Jun 30, 2023

@hackyon Thank you for the contribution! Would you like to add it to the remaining models? 🤗

@hackyon
Copy link
Contributor Author

hackyon commented Jun 30, 2023

Sure, I'll look into it 👍

@hackyon hackyon deleted the warning_attention_mask branch August 3, 2023 15:23
@hackyon
Copy link
Contributor Author

hackyon commented Aug 4, 2023

Thanks @ydshieh for fixing the flaky test!

I was busy in July, but will now add the warning to more models over the next couple of days.

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.

Add warning message if model uses input_ids that include padding tokens, but no attention_mask is provided.
4 participants