Repository navigation
Fix Pix2StructTextAttention init using hidden_size instead of d_kv - #47558
Merged
Cyrilvallez merged 3 commits intoSep 3, 2026
Merged
Conversation
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: pix2struct |
Contributor
CI recapDashboard: View test results in Grafana |
sbucaille
pushed a commit
to sbucaille/transformers
that referenced
this pull request
Sep 16, 2026
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.
What does this PR do?
Pix2StructTextAttention's weight initialization in_init_weightscomputeskey_value_proj_dimwith a fallback that doesn't match the pattern used everywhere else in the same block:Every other line in this elif isinstance(module, Pix2StructTextAttention): block mirrors the same leaf attribute name in both branches:
but
key_value_proj_dimfalls back toself.config.hidden_sizeinstead ofself.config.d_kv, even thoughPix2StructTextConfig.d_kvis a distinct field (default 64, versus hidden_size which defaults much higher).#Impact
When
Pix2StructTextModel(orPix2StructTextAttention) is instantiated standalone — i.e. with a plainPix2StructTextConfigrather than wrapped in the compositePix2StructConfigthe isinstance check fails, andkey_value_proj_dimsilently becomeshidden_sizeinstead ofd_kv. This gives the wrong initialization std for the query, key, value, and output projection weights.I verified this numerically: with hidden_size=64, d_kv=16, the observed init std for query.weight matched factor * (hidden_size * hidden_size) ** -0.5 (the buggy formula) rather than factor * (hidden_size * d_kv) ** -0.5 (correct, matching the Pix2StructConfig-wrapped path).
@Cyrilvallez @Rocketknight1