[NNX] Checkpoint: persist and restore rngs/dropout across resumes#4343
Open
ecnal-cienet wants to merge 1 commit into
Open
[NNX] Checkpoint: persist and restore rngs/dropout across resumes#4343ecnal-cienet wants to merge 1 commit into
ecnal-cienet wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
8170ad6 to
1951802
Compare
1951802 to
8217f75
Compare
The NNX-only rngs/dropout state is stripped from the Linen on-disk layout, so on resume it was refilled from a base key(0) -- every preemption reset the dropout RNG stream even though the dataset iterator was restored. Persist that state as a separate nnx_aux composite item (the items payload stays byte-identical to the Linen layout, preserving interchangeability) and restore it when present, falling back to deterministic defaults for Linen-trained or pre-fix checkpoints. Emergency managers keep the default-fill path.
8217f75 to
4bd1403
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
A pure_nnx run saves in the Linen on-disk layout, which has no place for NNX-only
rngs/dropoutstate, so that state is stripped on save. On resume it was refilled from a basejax.random.key(0)— every preemption reset the dropout/RNG stream even though the dataset iterator was correctly restored, breaking mathematical continuity of the dropout masks across steps.This persists the stripped
rngs/dropoutstate as a separatennx_auxcomposite item and restores it when present:extract_rng_state) before reshaping to the Linen layout, and write it as annnx_auxitem. Theitemspayload stays byte-identical to today's Linen layout, so NNX↔Linen interchangeability is preserved.nnx_auxalongsideitemsand merge it back; fall back to the deterministic default when it is absent (Linen-trained or pre-fix checkpoints).create_orbax_checkpoint_managerregisters thennx_auxitem handler — required, as Orbax rejects an unregistered composite item at save time (empty/unused for Linen runs). Emergency managers keep the default-fill path.Tests
tests/unit/checkpointing_nnx_load_test.py—TestExtractRngState,TestDeepMerge,TestRngStateAuxPersistence(helper-level: extract keeps only rng/dropout; round-trip restores the saved counter not the base default; no-aux dir falls back; save adds/omitsnnx_auxcorrectly). 14 passed.tests/unit/checkpointing_nnx_roundtrip_test.py— end-to-end through the realcreate_orbax_checkpoint_manager → maybe_save_checkpoint → load_state_if_possiblestack against an on-disk Orbax checkpoint: the dropout rng count survives a save/restore (andnnx_aux/is written), and a checkpoint withoutnnx_auxfalls back to the base default. 2 passed. (This e2e is what exposed the missing item-handler registration — the mocked unit tests passed without it.)Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.