Fix: Gemma4 checkpoint conversion failure when enable_nnx=True - #4378
Merged
copybara-service[bot] merged 1 commit intoJul 8, 2026
Conversation
chiajunglien
requested review from
NicoGrande,
RissyRan,
aireenmei,
bvandermoon,
gagika,
gobbleturk,
hengtaoguo,
jiangjy1982,
parambole,
richjames0,
shralex,
shuningjin and
suexu1025
as code owners
July 8, 2026 04:52
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
chiajunglien
force-pushed
the
emma/fix-gemma4-cp-convert
branch
from
July 8, 2026 08:54
3029c02 to
28e9cf7
Compare
shralex
approved these changes
Jul 8, 2026
NuojCheng
approved these changes
Jul 8, 2026
copybara-service
Bot
merged commit Jul 8, 2026
ebd4a78
into
AI-Hypercomputer:main
64 of 65 checks passed
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
When converting Gemma4 checkpoints with
enable_nnx=Trueandscan_layers=True, the process fails with a ValueError because the flattened param_map keys mismatch the actual state keys.Cause of the bug
In
layers/nnx_decoders.py, the constructor initializes the scanned block container underself.scanned_blocks. However, in the_apply_gemma4_scanned_blocksmethod, the main scan was applied to and assigned toself.layersinstead ofself.scanned_blocks.This inconsistency caused JAX to dynamically bind the scanned blocks under
self.layersat runtime under NNX, producing path keys of the formparams-decoder-layers-layers_{layer_idx}. Because the Gemma4 checkpoint conversion's parameter mapping strictly expects Linen's hardcoded prefixparams-decoder-scanned_blocks-layers_{layer_idx}, the conversion failed with:ValueError: maxtext_state_dict must be a subset of flattened param_mapSolution
Correct the variable naming inside
layers/nnx_decoders.py's_apply_gemma4_scanned_blocksmethod to useself.scanned_blocksinstead ofself.layers.Tests
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.