fix(algorithms): honour the configured KL clamps in the reward-side KL - #3853
Open
tianyi-zhang-02 wants to merge 1 commit into
Open
tianyi-zhang-02 wants to merge 1 commit into
tianyi-zhang-02 wants to merge 1 commit into
Conversation
Under use_kl_in_reward, GeneralizedAdvantageEstimator and ReinforcePlusPlusAdvantageEstimator both call calculate_kl without input_clamp_value / output_clamp_value, so the user's configured values are silently replaced by the function defaults (20.0 / 10.0). They already read reference_policy_kl_penalty and reference_policy_kl_type off the same ClippedPGLossConfig that carries the two clamps, and ClippedPGLossFn passes both through -- so setting kl_output_clamp_value moves the loss-side KL and leaves the reward-side one alone. Same config, same approximation, two different bounds, no error. Tests are CPU-only. Note what they had to do to be non-vacuous: both estimators normalize the advantage globally at the end, so a KL that is constant across the batch normalizes away to zeros whatever the clamp does. The reference has to diverge by a different amount at each position for the clamp to be observable at all. Mutation-tested: dropping the two kwargs from either call site, and hardcoding a clamp to its old default, each turn one of these red. Signed-off-by: Tianyi Zhang <zhangtianyi975@gmail.com> Signed-off-by: Tianyi Zhang <123608656+tianyi-zhang-02@users.noreply.github.com>
tianyi-zhang-02
force-pushed
the
fix-reward-kl-clamp
branch
from
September 12, 2026 18:25
a2021ba to
1e7d312
Compare
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?
Makes reward-side KL calculations honor
loss_fn.kl_input_clamp_valueandloss_fn.kl_output_clamp_value.Both reward-based advantage estimators already read the KL coefficient and approximation type from
ClippedPGLossConfig, but their calls tocalculate_klomitted the two clamp values. A configured clamp therefore affected the loss-side KL while reward-side KL silently used the function defaults.The test inputs use non-uniform policy/reference divergence because a constant KL disappears during final advantage normalization and would not detect this regression.
Validation
Current head
1e7d3121b001782acd8ed77a115a474051031216, rebased onto upstreammainat90a2a212d503455d8590be5c8de3cb989d3425b0.tests/unit/algorithms/test_reward_kl_clamp.py+tests/unit/algorithms/test_grpo.py: 171 passedgit diff --check: passedThese are CPU tensor-math regressions; no GPU workload is required.