Repository navigation
Conversation
With use_leave_one_out_baseline + normalize_rewards, a group that splits 7-vs-1 gives the singleton a leave-one-out set of identical rewards whose true std is 0. calculate_baseline_and_std_per_prompt computes std as sqrt(E[x^2]-E[x]^2) in fp32 matmuls, so non-dyadic rewards (0.35) leave a ~1.6e-4 residue that passes the old 'std > 0' guard and the singleton's advantage is divided by it. Wireup job 1973369 (32x8 web RL, CC v2) step 5 logged advantages/max 7428, loss -26, grad_norm 35 from exactly this. Threshold both GRPO and GDPO guards at STD_FLOOR = 1e-3 (same fix as the v1 training branch, b27dcff0c) and add a regression test that reproduces the residue and checks the singleton advantage stays unnormalized. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: jinx <[email protected]> (cherry picked from commit 502853df36041b155fd77577f7c50cb51d9a55de)
|
Adding the following note. This is crucial if training with non-binary intermediate rewards (such as 0.2 out of 0-1). I found a potentially important interaction between use_leave_one_out_baseline=true and grpo.normalize_rewards=true. With both enabled, the advantage is calculated using leave-one-out statistics: (reward - mean(other_rewards)) / std(other_rewards) For example, consider 16 rollout rewards: [1.0, 0.0, 0.0, ..., 0.1] For the rollout with reward 1.0, the leave-one-out group is [0.0, ..., 0.0, 0.1]. Its mean is approximately 0.0067 and its sample standard deviation is approximately 0.0258, producing: (1.0 - 0.0067) / 0.0258 ≈ 38.5 Therefore, this combination can produce extremely large advantages whenever one rollout is an outlier and the remaining rewards have low variance. This is not limited to non-binary rewards: with [1.0, 0.0, ..., 0.0], the successful rollout’s leave-one-out standard deviation is zero, so its normalized advantage is determined by the implementation’s epsilon or zero-variance handling. This differs from the standard formulations I found: GRPO uses reward normalization without a leave-one-out baseline. For our bounded [0, 1] reward setting, using normalize_rewards=false would give the standard RLOO-style advantage: reward - mean(other_rewards) This keeps the advantage bounded within [-1, 1] and avoids amplification caused by a near-zero leave-one-out standard deviation. Thus it is not advised to turn both use_leave_one_out_baseline=true and grpo.normalize_rewards=true if using non-binary intermediate rewards. |
|
Potentially a duplicate with #4158 |
|
Superseded by #4158, which detects identical comparison rewards exactly without introducing an arbitrary standard-deviation cutoff. The dynamic-sampling concern raised there should be addressed before merge: #4158 (comment) |
What does this PR do ?
Floor the GRPO/GDPO advantage std guard at 1e-3 so fp32 leave-one-out residue can no longer amplify a singleton's advantage by ~1000x.
Problem
With
use_leave_one_out_baseline: trueandnormalize_rewards: true,GRPOAdvantageEstimatordividesreward - baselineby the leave-one-out std wheneverstd > 0.calculate_baseline_and_std_per_promptcomputes that std as
sqrt(E[x^2] - E[x]^2)in fp32 matmuls. A group that splits 7-vs-1 on a reward that isnot exactly representable in fp32 (0.35, 0.4, 0.3, ...) gives the singleton a leave-one-out set of identical
rewards whose true std is 0 but whose fp32 result is ~1.6e-4. That passes the guard and the singleton's
advantage is divided by the residue: 0.6 / 1.6e-4 ~ 4000x. Observed in a 32x8 web-agent GRPO run
(advantages/max 7428, loss -26, grad_norm 35 on one step). Binary (dyadic) rewards cancel exactly and never hit it.
Fix
Threshold both the GRPO and GDPO guards at
STD_FLOOR = 1e-3(rewards are O(1); a genuine std below thatcarries no usable signal). Groups under the floor keep the unnormalized
reward - baseline.Regression test
tests/unit/algorithms/test_advantage_std_floor.pyreproduces the residue on CPU and checks thesingleton advantage stays at
-0.35.Additional Information
The floor removes the catastrophic exact-zero case only. Leave-one-out std normalization remains unbounded for
continuous rewards:
[1, 0 x6, 0.1]still normalizes to 26,[1, 0 x6, 0.01]to 264. Standard GRPO(
use_leave_one_out_baseline: false) is bounded by(G-1)/sqrt(G)and RLOO proper (LOO baseline, no std)by the reward range. Users with non-binary rewards should pick one of those; a docs note may be worth adding.