Skip to content

Fix image token mask in Gemma3 #38295

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

Merged
merged 2 commits into from
May 27, 2025
Merged

Fix image token mask in Gemma3 #38295

merged 2 commits into from
May 27, 2025

Conversation

Cyrilvallez
Copy link
Member

@Cyrilvallez Cyrilvallez commented May 22, 2025

What does this PR do?

As per the title. It got fixed in #38080 in the middle of #37866. This PR corrects the additional mask. See images for correctness for both sliding and full cases.
Before #37866 however, the masks were first created with full attention, then were truncated with sliding window in the DecoderLayer, so I'm pretty sure the added positions to the mask were removed in the sliding layers (i.e. even with #38080 it was not correct)-> kind of similar issue as with the Qwens. This not the case anymore, and everything is correctly generated and passed along 🤗

Of course both squares corresponds to 2 images of 5 image tokens.

Screenshot 2025-05-22 at 14 39 02
Screenshot 2025-05-22 at 14 35 07

@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
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Big win the fix looks simple

@Cyrilvallez Cyrilvallez merged commit b5ececb into main May 27, 2025
15 checks passed
@Cyrilvallez Cyrilvallez deleted the gemm3-mask branch May 27, 2025 09:15
rahulrshetty45 added a commit to rahulrshetty45/transformers that referenced this pull request May 28, 2025
… fix - Remove all Gemma3 changes as PR huggingface#38295 already fixed those issues - Keep only PaliGemma fix for original MedGemma issue huggingface#38333 - Remove unrelated workflow file from merge - Focus PR on single targeted fix for torch.compile() graph breaks
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