Repository navigation
Fix MultiSteps.has_updated after rejected mini-steps - #1837
Open
Linxiushen wants to merge 1 commit into
Open
Linxiushen wants to merge 1 commit into
Linxiushen wants to merge 1 commit into
Conversation
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.
After an emitted
MultiStepsupdate, rejecting the next mini-step preservesmini_step == 0andgradient_step > 0.has_updatedtherefore returnsTrueagain even though that call returned zero updates and did not advance the optimizer. Callers gating logging, evaluation or checkpoint cadence on this predicate receive a false update event.On unmodified main
9a1f892f52e28c18eec4d72b1001731cf20da532, CPU/JIT reproduction withMultiSteps(sgd(0.1), 2, should_skip_update_fn=skip_not_finite)gives:Record the last skip decision independently of the arbitrary user-provided
skip_state, and exclude rejected calls fromhas_updated. Counters, wrapped optimizer state and accumulated gradients still remain unchanged on rejection. This leaves the separate outgoing-update masking and accumulator-reset work in #1824 and #1834 untouched.The 13 new cases cover eager/JIT execution, accumulation lengths 1 and 2, both built-in skip predicates, a custom predicate with empty diagnostic state, repeated rejection, partial accumulation, finite recovery, preserved optimizer state, and serialization of initial/emitted/skipped states.
Validation on Windows, Python 3.12, JAX 0.8.0, Flax 0.12.0 (CPU):
python -m pytest -q optax/transforms/_accumulation_test.py optax/transforms/_masking_test.py optax/transforms/_combining_test.py: 60 passed, 29 subtests passed.git diff --checkpass.Compatibility:
MultiStepsStategains a defaulted sixth boolean field,last_step_skipped. Existing five-argument construction and its JIT update work. The serialized PyTree schema changes: strict old Flax state dictionaries require explicit migration by addinglast_step_skipped=False; the old checkpoint cannot reveal its last skip event. New-schema Flax roundtrips are tested; other checkpoint engines are untested.AI assistance was used to develop and locally validate this change.