Skip to content

fix(reward): keep the grouped shape in reward_norm when only std is per group - #511

Open
flyingdoubleG wants to merge 1 commit into
alibaba:mainfrom
flyingdoubleG:fix/reward-norm-group-std
Open

flyingdoubleG wants to merge 1 commit into
alibaba:mainfrom
flyingdoubleG:fix/reward-norm-group-std

Conversation

@flyingdoubleG

Copy link
Copy Markdown

What

reward_norm (roll/utils/functionals.py, used by the RLVR reward_postprocess) computes group statistics on the [n_groups, n_sample] view, but only uses that view when norm_mean_type == "group":

rewards = reshape_reward if norm_mean_type == "group" else response_level_rewards

With norm_std_type="group" and norm_mean_type "batch", "running" or None, the flat [N] rewards are divided by a [n_groups, 1] std, which broadcasts to [n_groups, N]; writing that back to the batch then fails with RuntimeError: batch dimension mismatch, got self.batch_size=torch.Size([N]) and value.shape=torch.Size([n_groups, N]). Both fields accept these values in PPOConfig, and the agentic agentic_reward_norm supports the same combination (an agentic example config has it commented out: norm_mean_type: batch / norm_std_type: group).

norm_mean_type, norm_std_type output shape before (N = 8, n_sample = 4)
group, group (8,)
batch, group (2, 8)
None, group (2, 8)
group, batch (8,)

Change

Use the grouped view whenever a group statistic is involved (group_mode and n_sample > 0) and restore the original shape afterwards. The combinations that already worked give the same values.

Tests

tests/utils/test_functionals.py::test_reward_norm_combinations checks shape and values for six combinations against a direct computation; the two group-std cases fail before the change, all pass after (CPU).

🤖 Generated with Claude Code

…er group

With norm_std_type="group" and norm_mean_type "batch", "running" or None,
reward_norm computes the per-group std on the [n_groups, n_sample] view
but subtracts the mean from the flat [N] rewards, so the division
broadcasts to [n_groups, N] and the RLVR pipeline fails when it writes
the result back to the batch. The agentic agentic_reward_norm supports
this combination.

Compute on the grouped view whenever a group statistic is used and
restore the original shape afterwards; the other combinations are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

1 participant