Fix decoder_attention_mask None handling in generation utils#45985
Open
damodharg6 wants to merge 1 commit into
Open
Fix decoder_attention_mask None handling in generation utils#45985damodharg6 wants to merge 1 commit into
damodharg6 wants to merge 1 commit into
Conversation
Member
|
Hey, can you give us some sample code that shows how the issue can be triggered? We get a lot of agent fixes that don't fix actual bugs, so we'd like to see a reproducer! |
Author
|
Thanks for reviewing!
Here’s a minimal reproducer for the issue:
from transformers import AutoTokenizer, AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("gpt2")
tokenizer = AutoTokenizer.from_pretrained("gpt2")
inputs = tokenizer("Hello", return_tensors="pt")
outputs = model.generate(
**inputs,
decoder_attention_mask=None,
max_new_tokens=5,
)
Before the fix, generation utilities fail when
"decoder_attention_mask=None" is propagated internally.
With the fix applied, generation works normally without errors.
…On Fri, 15 May 2026, 6:55 pm Matt, ***@***.***> wrote:
*Rocketknight1* left a comment (huggingface/transformers#45985)
<#45985 (comment)>
Hey, can you give us some sample code that shows how the issue can be
triggered? We get a lot of agent fixes that don't fix actual bugs, so we'd
like to see a reproducer!
—
Reply to this email directly, view it on GitHub
<#45985 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BRCZIHDEHP4GD4K5B36OWXL424LGNAVCNFSM6AAAAACY62757OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DINRQGEZTENZQGQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Member
|
That code snippet runs fine for me. |
Author
|
Thanks for checking! I’ll investigate further and see if it’s environment
specific on my side.
…On Fri, May 15, 2026 at 8:12 PM Matt ***@***.***> wrote:
*Rocketknight1* left a comment (huggingface/transformers#45985)
<#45985 (comment)>
That code snippet runs fine for me.
—
Reply to this email directly, view it on GitHub
<#45985 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BRCZIHENZEYCMYIMVLTFNGT424UG7AVCNFSM6AAAAACY62757OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DINRQG4ZDOMJWGQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a potential issue in
generation/utils.pywheredecoder_attention_maskcould be accessed before proper validation.Changes
model_kwargs.get("decoder_attention_mask", None)Nonecheck before applyingtorch.cat(...)Motivation
This prevents failures during generation/evaluation workflows when
decoder_attention_maskis not provided.