Repository navigation
fix(ppo): prevent k3 KL gradient overflow - #1335
Merged
Merged
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.
The k3 KL estimator clips its output after computing the exponential. For an extreme but finite log-probability difference, the exponential overflows: the returned KL is still finite after clipping, but backward produces NaN through
0 * inf. A KL-regularized optimizer update can then corrupt otherwise finite parameters.Bound a local log-ratio copy before k3's exponential, only in a region where the existing output cap already saturates the result. This preserves the clipped objective and its normal-range gradients. The original log ratio remains available to the optional corrected-gradient surrogate.
Validation: full pytest suite (70 passed), compileall and pre-commit. Added FP16/BF16/FP32 value/gradient comparisons against a float64 reference, corrected-gradient coverage, and a CPU AdamW update test. Additional valid categorical-distribution stress checks pass after the fix. These are numerical regressions; no production incidence or GPU-training improvement is claimed.