fix(ppo): preserve raw KL so rollout/kl logging is correct - #2114
Merged
Conversation
EazyReal
force-pushed
the
fix/ppo-kl-inplace-metric
branch
3 times, most recently
from
June 24, 2026 04:17
cbf085d to
0a034ba
Compare
Contributor
Author
|
@zhuzilin could you review this now-cleaned version? PPO reward shaping was mutating the raw KL tensor before metrics, so rollout/kl logging could report shaped rewards instead of KL. The fix keeps raw KL separate and mirrors the local-k pattern used by the reinforce loss helpers. |
EazyReal
force-pushed
the
fix/ppo-kl-inplace-metric
branch
from
June 30, 2026 08:58
9369513 to
f343036
Compare
EazyReal
added a commit
to EazyReal/slime
that referenced
this pull request
Jul 7, 2026
Contributor
Author
|
@zhuzilin refreshed on latest main and checks are green. This keeps raw KL separate from token-level rewards so rollout/kl logging stays correct while PPO still applies the KL penalty. Could you review when you have bandwidth? |
EazyReal
force-pushed
the
fix/ppo-kl-inplace-metric
branch
from
August 18, 2026 21:59
c271685 to
1eae53b
Compare
k *= kl_coef wrote through rollout_data['kl'], so logged KL was the scaled reward term. Other estimators are unchanged.
EazyReal
force-pushed
the
fix/ppo-kl-inplace-metric
branch
from
August 21, 2026 00:50
1eae53b to
3e4378a
Compare
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.
Problem
compute_advantages_and_returnswrites per-token KL intorollout_data["kl"], which is what gets logged as the KL metric.The PPO branch then did:
kis the same tensor already stored inrollout_data["kl"], so logging seeskl_coef-scaled KL with the scalar reward added on the last token. GRPO / GSPO / CISPO / R++ do not mutateklthis way.Change
Build token-level rewards out of place:
PPO advantages/returns still use the scaled+reward tensor.
rollout_data["kl"]stays the raw metric. Other estimators are untouched.Test plan
tests/test_ppo_kl_metric.py— after PPO,rollout_data["kl"]still matchescompute_approx_kl(registered inpr-test.yml.j2)