Skip to content

fix(grpo): use rank-penalized rewards in the advantage numerator - #646

Open
David-Wu1119 wants to merge 1 commit into
agentscope-ai:mainfrom
David-Wu1119:fix/grpo-rank-penalty-advantage
Open

David-Wu1119 wants to merge 1 commit into
agentscope-ai:mainfrom
David-Wu1119:fix/grpo-rank-penalty-advantage

Conversation

@David-Wu1119

@David-Wu1119 David-Wu1119 commented Nov 11, 2026 •

Copy link
Copy Markdown

Description

Bug. GRPOGroupedAdvantage with rank_penalty set (advantage_fn_args: {rank_penalty: ...}) applies the unlikeliness reward of arXiv:2506.02355 (Sec. 4.1): each reward is rescaled by 1 - rank_penalty * rank / G, where higher-likelihood responses get larger ranks. The group mean and std are computed from the rescaled rewards, but the advantage was still computed from the raw exp.reward:

rewards = rewards * (1 - group_ranks * self.rank_penalty)
group_reward_mean = torch.mean(rewards)
group_reward_std = torch.std(rewards)
...
score = (exp.reward - group_reward_mean) / (group_reward_std + self.epsilon)

With binary rewards, every correct response in a group therefore gets the same advantage whatever its rank. The option only shifts the baseline and never favours the less likely correct responses, which is what the paper's modified reward r_i is for (the advantage is computed from r_i).

Reproduce. One group, rewards [1, 1, 0, 0], mean log-probs [-0.1, -2.0, -0.5, -1.0], rank_penalty=0.25: on main both correct responses get the same advantage; the unlikely one (-2.0) should get the larger one.

Fix. Compute the advantage from the same (possibly rank-penalized) rewards the group statistics use. Without rank_penalty the result is unchanged.

Tests. New tests/algorithm/advantage_fn_test.py::TestGroupedAdvantageFn::test_grpo_rank_penalty_advantages_use_adjusted_rewards checks the advantages against (r_i - mean(r)) / (std(r) + eps) on the adjusted rewards. It fails on main and passes with this change. tests/algorithm and tests/common/rewards pass (108 tests, CPU). pre-commit passes on the changed files. No GPU or model-weight tests were run.

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has passed all tests (only the CPU tests in tests/algorithm and tests/common/rewards were run; GPU and Ray tests were not)
  • Docstrings have been added/updated in Google Style
  • Documentation has been updated
  • Code is ready for review

🤖 Generated with Claude Code

With `rank_penalty` set, GRPOGroupedAdvantage rescales each reward by its
likelihood rank (the unlikeliness reward of arXiv:2506.02355) and computes
the group mean and std from the rescaled rewards, but the advantage itself
was still computed from the raw `exp.reward`. With binary rewards every
correct response then received the same advantage regardless of its rank,
so the option shifted the baseline but never favoured unlikely correct
responses, which is its whole purpose.

Compute the advantage from the same (possibly rank-penalized) rewards that
the group statistics use. Behaviour without `rank_penalty` is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 05:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants