Conversation
Signed-off-by: ryan.u(류민호)/kakao <ryan.u@kakaocorp.com>
This was referenced Sep 24, 2026
This branch has not been deployed
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.
What does this PR do ?
Prevent masked tokens and excluded samples from producing NaN gradients in
ClippedPGLossFn.The loss currently computes probability ratios and KL terms before applying the loss mask. In float32, a log-probability difference of 200 overflows
exp; multiplying the result by a zero mask still yields NaN. Masked-infor NaN inputs can also contaminate reductions and diagnostics.Zero the excluded log-probabilities and advantages before those operations, using the existing combined token/sample mask. Values at valid positions are unchanged. This covers the policy ratio, importance-sampling correction, reference KL penalty, and log-probability diagnostics without clamping valid-token ratios.
The regression test compares a clean batch against the same batch with extreme values in a masked prompt position and an excluded sample. It checks finite loss, gradients, and metrics, plus identical loss and input gradients. Its 18 cases cover token/sequence loss reduction, sequence importance ratios, on-policy/off-policy ratios, and finite overflow/
-inf/NaN inputs.Issues
No linked issue.
Usage
No configuration changes are needed.
Before your PR is "Ready for review"
Additional Information
Validated against upstream main
d633032b2a8017c69ddfff9183deb42cab6b36f4:--confcutdirexcludes the parent suite's automatic Ray-cluster fixtures for this local CPU run; the actual upstream loss implementation and test module are imported without stubs.git diff --checkpassed for the changed files.