Fix Gemma 4 MLP hook aliases - #1650
Merged
jlarson4 merged 1 commit intoAug 12, 2026
Merged
Conversation
Collaborator
|
Looks great, thanks for putting this together @koriyoshi2041! |
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.
Description
Fixes #1646.
Problem
The Gemma 4 adapter decomposes its dense MLP into
gate_proj,up_proj, anddown_proj, but wraps them in a plainGeneralizedComponent. The standard gated-MLP aliases (hook_pre,hook_pre_linear, andhook_post) are therefore missing even though the underlying module has the same projection structure as other supported gated MLPs.Fix
Use the adapter's existing
_gated_mlp()helper for Gemma 4. This preserves the same projection paths while installing the standard hook aliases. The unit test now checks both the bridge type and the exact alias mapping.Test
uv run pytest tests/unit/model_bridge/supported_architectures/test_gemma4_adapter.py -q(10 passed)uv run pytest tests/integration/model_bridge/test_gemma4_bridge.py -q(12 passed across PLE/KV-shared, dense K=V, and MoE fixtures)uv run mypy transformer_lens/model_bridge/supported_architectures/gemma4.pymake check-formatgit diff --checkRisk
Low. The component retains the same
mlppath and gate/up/down projection names. Gemma 4's delegated blocks still execute the Hugging Face forward path, and the three existing architecture fixtures retain logit parity. The change only adds the gated-MLP compatibility interface around the already-decomposed projections.Type of change
Checklist