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

Generate: check that attention_mask is 2D #33575

Merged
merged 1 commit into from
Sep 19, 2024
Merged

Conversation

gante
Copy link
Member

@gante gante commented Sep 18, 2024

What does this PR do?

Fixes #33549

In generate, attention_mask must be in its 2D format. This PR adds a check for that.

@@ -1861,6 +1861,10 @@ def generate(
model_kwargs["attention_mask"] = self._prepare_attention_mask_for_generation(
inputs_tensor, generation_config._pad_token_tensor, generation_config._eos_token_tensor
)
elif kwargs_has_attention_mask:
# TODO (joao): generalize this check with other types of inputs
if model_input_name == "input_ids" and len(model_kwargs["attention_mask"].shape) > 2:
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure len(model_kwargs["attention_mask"].shape) > 2 generalizes (e.g. some audio models have 3d inputs), so I'm fixing the most common use case now and adding a TODO in case this issue pops up again for other input formats

@gante gante requested a review from LysandreJik September 18, 2024 17:54
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Makes sense!

@gante gante merged commit d9d59e7 into huggingface:main Sep 19, 2024
21 checks passed
@gante gante deleted the fix_33549 branch September 19, 2024 15:23
BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
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.

4D attention masks not compatible with generate
3 participants