Add skip_if, a step guard with non-finite and large-step conditions - #107
Merged
Merged
Conversation
Unlike optax's apply_if_finite, which gives up and accepts the poisoned update once the tolerance is exhausted, this raises: a run that has skipped that many steps in a row has diverged rather than hit a bad batch, and poisoning the weights at that point costs the rest of the run.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #107 +/- ##
==========================================
+ Coverage 97.47% 97.52% +0.04%
==========================================
Files 60 61 +1
Lines 3012 3069 +57
==========================================
+ Hits 2936 2993 +57
Misses 76 76 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
A single NaN batch ends a run today: it reaches the parameters and every Adam moment, and nothing recovers.
skip_ifwraps a rule and throws away any step its condition rejects, leaving the parameters and the optimizer state as they were. Exhausting the tolerance raises rather than accepting the poisoned update the way optax does; a run that has skipped that many steps in a row has diverged, not hit a bad batch.Two conditions ship:
nonfinite, aliasedapply_if_finite, andlarge_step, which thresholds on step norm and so fires while the numbers are still finite.large_stepisn't redundant withclip_by_global_norm. Clipping rescales bymax_norm / norm, which is zero once the norm is inf, so the poisoned coordinate becomesinf * 0and every healthy one is multiplied away; one inf destroys its own parameter and cancels the step for all the others. The guard covers only what the rule writes, so batch-norm running statistics, folded in bycompile_trainoutside it, still get poisoned.