Skip to content

generate: drop an all-ones attention mask from model_kwargs - #48803

Closed
SunMarc wants to merge 11 commits into
mainfrom
drop-mask-from-model-kwargs
Closed

SunMarc wants to merge 11 commits into
mainfrom
drop-mask-from-model-kwargs

Conversation

@SunMarc

@SunMarc SunMarc commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

CPU CI GPU run-slow

Same as #47951 but i try to remove the attention_mask from model_kwargs.

Padding can only come from the prompt, so settle once whether the inputs are padded and, when they
are not, take the mask out of `model_kwargs` entirely - the per-step `torch.cat` that grows it goes
with it. `_prefill` used the mask's length to tell whether `input_ids` holds the whole sequence or
only the new tokens, so that answer is recorded before the mask is dropped.
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

Comment thread src/transformers/generation/utils.py Outdated
Comment on lines +2784 to +2790
decoding_name = GENERATION_MODES_MAPPING[generation_mode]
uses_default_decoding_loop = (
"/" not in decoding_name
and decoding_method is getattr(GenerationMixin, decoding_name)
# Candidate generators slice `model_kwargs["attention_mask"]` themselves
and generation_mode != GenerationMode.ASSISTED_GENERATION
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i had the restrict a bit the fix since most methods still uses the attn masks but those can maybe be fixed

Comment on lines 2712 to 2713
model_kwargs["position_ids"] = self._prepare_position_ids_for_generation(inputs_tensor, model_kwargs)

@SunMarc SunMarc Sep 14, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we could delete the attention_mask even earlier but we will have to pass a new arg to _prepare_position_ids_for_generation : generation_config._mask_length so that we can create correctly the positions_ids. Note that we would have to update the models where _prepare_position_ids_for_generation is overwritten . Also some models do self.model.get_rope_index(inputs_tensor, **model_kwargs) where they use the attn mask

@SunMarc
SunMarc requested a review from Cyrilvallez September 14, 2026 21:45
@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 34898108242:1
Result: success | Jobs: 16 | Tests: 189,709 | Failures: 0 | Duration: 17h 40m

@SunMarc

SunMarc commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

closed in favor of #48814 !

@SunMarc SunMarc closed this Sep 15, 2026
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.

2 participants