Repository navigation
[NNX] Emergency checkpoint: build the manager with a checkpoint-layout abstract - #4372
Merged
Merged
Conversation
ecnal-cienet
force-pushed
the
fix/nnx-emc-linen-abstract
branch
from
July 7, 2026 20:32
0e7124b to
03d1b36
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ecnal-cienet
force-pushed
the
fix/nnx-emc-linen-abstract
branch
5 times, most recently
from
July 13, 2026 14:43
1c96f5c to
27a1688
Compare
ecnal-cienet
marked this pull request as ready for review
July 13, 2026 15:36
ecnal-cienet
requested review from
A9isha,
NicoGrande,
NuojCheng,
RissyRan,
SurbhiJainUSC,
abhinavclemson,
aireenmei,
bvandermoon,
darisoy,
dipannita08,
gagika,
gobbleturk,
hengtaoguo,
igorts-git,
jiangjy1982,
khatwanimohit,
richjames0,
shralex,
suexu1025,
vipannalla and
xibinliu
as code owners
July 13, 2026 15:36
NuojCheng
reviewed
Jul 13, 2026
| restored = self._restore(manager, _Model) | ||
|
|
||
| self.assertEqual(jax.tree_util.tree_structure(saved), jax.tree_util.tree_structure(restored)) | ||
| matches = jax.tree_util.tree_map(_leaf_equal, saved, restored) |
Collaborator
There was a problem hiding this comment.
might be better adding is_leaf=lambda...
xibinliu
approved these changes
Jul 13, 2026
NuojCheng
approved these changes
Jul 13, 2026
…t abstract pure_nnx saves in the on-disk checkpoint layout (Linen params/opt_state/step plus an nnx_aux subtree) for both the regular and emergency managers. But the emergency manager is constructed with the NNX-native abstract (model/optimizer) from get_abstract_state, and unlike the regular manager it bakes that abstract in and restores against it, ignoring the restore-time item. So on resume Orbax compared a checkpoint-layout tree on disk against an NNX target and raised 'User-provided restore item and on-disk value metadata tree structures do not match', failing the EMC resume-from-GCS job. Convert the abstract with to_checkpoint_dict in create_orbax_emergency_checkpoint_manager so the baked-in blueprint matches what maybe_save_checkpoint writes; the restore path reshapes it back to NNX. Save, restore and the manager's blueprint now all partition the state the same way, through to_checkpoint_dict. Tests mirror checkpointing_nnx_roundtrip_test for the emergency manager: a mock guard that it is handed the checkpoint layout rather than the NNX roots, plus real save/restore round trips showing weights, optimizer moments, the dropout rng and batch stats all come back from nnx_aux, and that caches stay ephemeral.
ecnal-cienet
force-pushed
the
fix/nnx-emc-linen-abstract
branch
from
July 13, 2026 18:04
27a1688 to
9dc7704
Compare
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
This PR aims to fix issue b/530068041
The
maxtext_emc_resume_from_gcse2e job fails when apure_nnxrun resumes from its GCS checkpoint:A
pure_nnxrun saves in the on-disk checkpoint layout — Linenparams/opt_state/stepplus annnx_auxsubtree, viato_checkpoint_dict— so pure_nnx and Linen checkpoints stay interchangeable. Both the regular and the emergency manager save that way.The difference is on the restore side. The regular manager restores against the item it is given at restore time. The emergency manager instead bakes in the abstract it is constructed with and restores against that, ignoring the restore-time item.
create_orbax_emergency_checkpoint_managerwas handing itget_abstract_state's NNX-native tree (model/optimizer), so Orbax compared a checkpoint-layout tree on disk against an NNX target and raised. This is also why converting the restore-time item alone did not help: the emergency manager never looks at that item.Fix: convert the abstract with
to_checkpoint_dictincreate_orbax_emergency_checkpoint_managerwhen it is annnx.State, so the blueprint the manager holds matches whatmaybe_save_checkpointwrites.split_for_checkpointalready requires that save and restore partition the state identically; the manager's baked-in abstract is a third copy of that partition, and it now goes through the same function as the other two. The restore path reshapes back to NNX, so the state we train on is still NNX, and the on-disk format is unchanged. Six lines, in the constructor. A Linen state is not annnx.State, so it is passed through untouched.Tests
tests/unit/checkpointing_emergency_nnx_test.py(5) — the emergency-manager counterpart ofcheckpointing_nnx_roundtrip_test.py:params/opt_state/step/nnx_aux), not the NNXmodel/optimizerroots. Orbax is mocked, so this one runs in normal CI and catches a regression here without an emergency-checkpoint setup.EmergencyCheckpointManageris leaf-exact: weights, optimizer moments, dropout rng, batch stats.nnx_auxis genuinely restored rather than reset to a fresh init — checked by value (rng count, batch-norm mean, optimizer step), since a reset keeps the tree structure intact and would slip past the structural check.nnx_aux.Reverting the six lines fails four of the five (the fifth is the Linen pass-through case, which correctly still passes).
End-to-end on a v6e-8 (jax 0.10.0, orbax-checkpoint 0.12.1)
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.