Adapt inspect_checkpoint.py for Automated Ckpt Validation Pipeline (NNX Support)#4567
Adapt inspect_checkpoint.py for Automated Ckpt Validation Pipeline (NNX Support)#4567olufiyin19 wants to merge 1 commit into
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
0453b56 to
c31d3ae
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Thanks for adding the support for inspecting NNX checkpoint! By comparing the code with checkpoint_conversion/inspect_checkpoint.py, it seems the change is relatively safe (diff). Would you consider directly incorporating to that script for broad use?
| key_str = ".".join(key_parts) | ||
| if getattr(config, "enable_nnx", False) and not key_str.startswith("params"): | ||
| param_key = "params.params." + key_str | ||
| else: | ||
| param_key = "params." + key_str |
There was a problem hiding this comment.
The name looks a bit inconsistent from prev test. Maybe rerun?
I expect both linen and nnx to print like
key: params.Tid2EidVar.decoder.layers_0.mlp.MoeBlock_0.tid2eid | shape: (129280, 6)
key: params.Tid2EidVar.decoder.layers_1.mlp.MoeBlock_0.tid2eid | shape: (129280, 6)
key: params.Tid2EidVar.decoder.layers_2.mlp.MoeBlock_0.tid2eid | shape: (129280, 6)
key: params.params.decoder.decoder_norm.scale | shape: (4096,)
key: params.params.decoder.hc_head.hc_base | shape: (4,)
key: params.params.decoder.hc_head.hc_fn | shape: (16384, 4)
key: params.params.decoder.hc_head.hc_scale | shape: (1,)
key: params.params.decoder.layers_0.mhc_attention.mhc_norm.scale | shape: (16384,)
key: params.params.decoder.layers_0.mhc_attention.post_alpha | shape: (16384, 4)
There was a problem hiding this comment.
I used param_key_parts_from_path to fix the underscores so output now resembles layers_0. and updated the prefix logic to explicitly ignore Tid2EidVar so MoE layers no longer get the accidental params.params. double prefix. Both outputs now match exactly and I've updated them in my description
5c5d7e1 to
bf2d3dc
Compare
bf2d3dc to
fe82cb9
Compare
Description
This PR modifies
inspect_checkpoint.pyto introduce native NNX architecture support, while preserving Linen compatibility as a fallback. The previous coreinspect_checkpoint.pyutility only supported Linen-based models. As our automated validation pipeline transitions to an NNX-first architecture, a way to inspect checkpoints against NNX abstract models is required.create_nnx_abstract_modelandflax.nnx.splitto dynamically generate abstract parameters for NNX models whenenable_nnx=Trueis passed in the config.Tests
1. Manually verified that passing `enable_nnx=True` successfully initializes the NNX abstract model and accurately resolves the params.params. key structure.
Command:
python3 ~/maxtext/src/maxtext/checkpoint_conversion/inspect_checkpoint.py maxtext model_name=llama2-7b scan_layers=False enable_nnx=True2. Verified that falling back to older configs successfully routes to the legacy Linen Transformer initialization without failure.
Command:
python3 ~/maxtext/src/maxtext/checkpoint_conversion/inspect_checkpoint.py maxtext model_name=llama2-7b scan_layers=False enable_nnx=FalseChecklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.