fix(nnx): Fix Linen checkpoint restoration into NNX Gemma4 model - #4619
Draft
hsuan-lun-chiang wants to merge 7 commits into
Draft
fix(nnx): Fix Linen checkpoint restoration into NNX Gemma4 model#4619hsuan-lun-chiang wants to merge 7 commits into
hsuan-lun-chiang wants to merge 7 commits into
Conversation
Update layer path assertion in test_scan_layers_mismatch_tpu from decoder/layers/0/ to decoder/layers_0/ to match the unscanned layer naming structure introduced in PR #4504.
…ng NNX Variable PyTree structure
…dings raw array structure
…g nnx.Variable wrappers from out_shardings
…loading into NNX Gemma4 model
…ted array errors for non-restored parameters
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
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 parameter structure mapping and restore issues when restoring Linen checkpoints into NNX models for Gemma4.
Key Changes
flax.nnx.Variable/Paraminnnx_extract_named_sharding: Prevent JAX JIT pytree structure errors during sharded model creation by returning rawNamedShardingleaves.layers_N<->layers["N"]): Map target NNX attribute keysdecoder.layers_Nintodecoder.layers["N"]dictionary keys for Orbaxtarget_for_restorein_lookup_stored_metaand_adjust_target_for_moe_fusion, and unroll restored keys back tolayers_Nbefore callingnnx.update(model, checkpoint).int,str, andliststructures._free_device_memorybuffer deletion: Avoid deleting active Variable array references prior to restore to preventRuntimeError: Array has been deletedduring inference compilation.Testing
gemma4-26bandvllm_decode. Weights restored in 9.94s and inference output rendered successfully.