Repository navigation
[BugFix] Zero GRPO advantage for groups of identical fractional rewards - #4610
Conversation
MCAdvantage normalized each group as (r - mean) / std.clamp_min(1e-6). When every reward in a group is the same fraction (e.g. 0.7), the float32 mean is off by a rounding step, so r - mean and std are both ~1e-8. Dividing that residue by the 1e-6 clamp gave every sample in the group the same nonzero advantage (0.06 for a group of 8 at 0.7, up to 0.24 for larger groups), biasing updates on groups that carry no learning signal. Dynamic sampling does not catch this, since such a group's mean lies inside the usual keep_return_bounds. Reduce the group shifted by its minimum instead: identical values then have an exact mean and a zero std, and their advantage is exactly zero. Applies to both the per-step and the trajectory_return paths. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4610
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit b1712a0 with merge base b763b5c ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @catherinelee274! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
catherinelee274
left a comment
There was a problem hiding this comment.
I have signed the cla.
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Seems the failing test is not related to my change: |
|
We have been meaning to fix this as this issue. this issue stems from a migration from ec2 to osdc jobs. However, this job isn't really relevant for your diff here. |
Description
MCAdvantagenormalizes each group as(r - mean) / std.clamp_min(1e-6). When every reward in a group is the same fraction (0.7, 0.3, 1/3, ...), the float32 mean is off by a rounding step. That leavesr - meanandstdboth around 1e-8, and dividing the residue by the1e-6clamp gives every sample in the group the same nonzero advantage, when it should be zero:trajectory_return="sum"keep_return_bounds=(0, 1)Every sample gets the same sign, so the update pushes the whole group up or down when the group carries no learning signal. Dynamic sampling doesn't catch this: the group's mean falls inside the usual bounds, which only drop all-0 or all-1 groups. The same issue was reported in miles#4019.
Fix
A new private helper,
_group_mean_std, reduces the group after shifting it by its minimum. Identical values then have an exact mean and an exactly zero std, so their advantage is exactly 0. There is no tolerance to tune and no Python branch on tensor values, so the fix stays compile-friendly. The variance is unchanged by the shift, and for non-uniform groups the result matches the previous one up to rounding. The helper is used in both the per-step path and thetrajectory_returnpath.Tests
TestMCAdvantage::test_mc_advantage_uniform_fractional_rewards, run in per-step andtrajectory_return="sum"mode. It asserts that a group of identical 0.7 rewards gets an advantage of exactly zero. Both cases fail onmainand pass with this change.pytest test/llm/test_llm_objectives.py -k MCAdvantage: 25 passed.🤖 Generated with Claude Code