[GRPO] Multiply the KL term by the per-token importance sampling ratio - #7188
Open
Alexander230 wants to merge 1 commit into
Open
[GRPO] Multiply the KL term by the per-token importance sampling ratio#7188Alexander230 wants to merge 1 commit into
Alexander230 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.
What does this PR do?
Fixes #6586.
The correction now always uses the per-token ratio, so the result no longer depends on
importance_sampling_level; token-level behaviour is unchanged.Before submitting
AI writing disclosure
Who can review?
Anyone
🤖 Generated with Claude Code
Note
Medium Risk
Changes GRPO loss gradients whenever
beta != 0anduse_bias_correction_klis enabled withimportance_sampling_level="sequence", which can alter off-policy training behavior.Overview
Fixes #6586 by changing how bias-corrected KL is weighted in
GRPOTrainer._compute_loss: whenuse_bias_correction_klis on, the KL term is multiplied by the per-token importance ratioexp(log_ratio)instead ofcoef_1(which followsimportance_sampling_leveland can be sequence-aggregated).Policy-loss importance sampling is unchanged; only the KL correction is decoupled so sequence-level IS no longer broadcast onto per-token KL.
GRPOConfigdocs now state that KL bias correction always uses the per-token ratio.A regression test builds synthetic batches where sequence-level ratios cancel to 1 but per-token ratios do not, with zero advantages so loss is KL-only, and asserts
_compute_lossmatches for"sequence"vs"token"IS levels.Reviewed by Cursor Bugbot for commit 0360546. Bugbot is set up for automated code reviews on this repo. Configure here.