[Bug] Multiple RL algorithm inconsistencies: missing `negative_approx_kl` clamp in `clip_cov`/`kl_cov`/`geo_mean`, GPG `alpha` silently overridden, GRPO single-sample std mismatch
System Info
Discovered via static code analysis of verl/trainer/ppo/core_algos.py. Three distinct but related algorithm correctness issues.
Information
- [x] The official example scripts
Tasks
- [x] An officially supported task in the
examplesfolder (such as GLUE/SQuAD, ...)
Reproduction
Issue A — Missing negative_approx_kl clamp (NaN risk)
In compute_policy_loss_clip_cov (line ~1789), compute_policy_loss_kl_cov (line ~1881), and compute_policy_loss_geo_mean (line ~1963), the code computes negative_approx_kl = log_prob - old_log_prob and immediately applies torch.exp(negative_approx_kl) without the clamp that all 8 other policy loss functions apply:
# Missing in clip_cov / kl_cov / geo_mean:
negative_approx_kl = torch.clamp(negative_approx_kl, min=-20.0, max=20.0)
In geo_mean, this clamp is present but commented out with "uncomment if you like" — the intent is ambiguous. Without it, large policy deviations early in training can produce exp(large_value) → NaN/Inf, corrupting the entire batch gradient.
Issue B — GPG alpha parameter silently overridden
In compute_gpg_outcome_advantage (line ~809):
def compute_gpg_outcome_advantage(scores, ..., alpha: float = 1.0):
...
alpha = bsz / m.clamp(min=1) # ← immediately overwrites the parameter
The caller-supplied alpha is always discarded. This breaks the function's contract: users who set alpha via config will silently get wrong behavior.
Additionally, id2std is computed (lines ~804, ~817, ~821) but never used in the normalization formula at line ~825.
Issue C — GRPO single-sample group std inconsistency
In compute_grpo_outcome_advantage (line ~315–317):
if len(id2score[idx]) == 1:
id2std[idx] = torch.tensor(1.0) # single-sample: std = 1 → advantage ≈ raw score
But in compute_grpo_outcome_advantage_vectorized, single-element groups produce std = 0 → advantage = 0. The two code paths have different behavior for the same input, making switching between them non-transparent.
Expected behavior
- A: Apply
torch.clamp(negative_approx_kl, min=-20.0, max=20.0)consistently in all policy loss functions, or explicitly document why specific variants intentionally omit it. - B: Remove the
alphaparameter from the function signature (since it is always overridden), or rename the internal variable to avoid shadowing. - C: Document and align the single-sample group behavior between the two GRPO implementations.
I reproduced the issue: in some PPO loss paths, negative_approx_kl can explode (very large magnitude), and the current implementation does not uniformly guard this term, which can lead to unstable/infinite loss behavior. So I think your concern is valid.
My plan is to fix this by clamping negative_approx_kl to a bounded range in the affected policy-loss variants (compute_policy_loss_clip_cov, compute_policy_loss_kl_cov, and compute_policy_loss_geo_mean) and adding a focused regression test for extreme log-probability differences. I have prepared a PR for this (fix-6478-negative-approx-kl-clamp) and will link it once it’s opened.