Skip to content

fix(ppo): prevent k3 KL gradient overflow - #1335

Merged
hijkzzz merged 1 commit into
OpenRLHF:mainfrom
Excelius-Wang:fix/k3-finite-gradient
Sep 12, 2026
Merged

hijkzzz merged 1 commit into
OpenRLHF:mainfrom
Excelius-Wang:fix/k3-finite-gradient

Conversation

@Excelius-Wang

Copy link
Copy Markdown
Contributor

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.

@hijkzzz
hijkzzz merged commit 0ed43bd into OpenRLHF:main Sep 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants