{{ message }}
Repository navigation
fix(grpo): normalize rewards per query and unique rollout - #2446
Open
huanhuan6666 wants to merge 2 commits into
Open
huanhuan6666 wants to merge 2 commits into
huanhuan6666 wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #2445.
Context compaction can turn one sampled rollout into multiple training rows.
BatchBuilder._post_process_rewardscurrently normalizes the whole batch when the row count differs fromrollout_batch_size * n_samples_per_prompt. This mixes unrelated queries. Grouping rows by query alone also overweights episodes that produce more rows.This change groups by
Sample.group_index, computes the mean and optional sample standard deviation over distinctrollout_idvalues within each query, then broadcasts each episode's normalized reward to its rows in their original order. For example, query A with episode rewards[1, 0]and query B with[0, 0]keep centered rewards[0.5, -0.5]and[0, 0], even when episodes are split during compaction.BatchBuilder.convert.Validation: 86 CPU tests passed, including 27 new reward regressions and the existing trajectory-manager branching, Sample, rollout-data and sample-hook tests. The regression exercises the real
TrajectoryManager -> BatchBuilder.convert -> get_grpo_returnspath with and without compaction. On the unmodified base, 19 of the 27 new cases fail. The new test file is registered in CPU CI; Black 24.3.0, isort 5.13.2, Ruff 0.14.7 andgit diff --checkpass. No GPU training run was performed.Related work: #2062 already proposes the same query/rollout grouping principle; #2204 addresses explicit query grouping. This is a focused implementation against the current
BatchBuilder, with native compaction regression coverage and strict handling of ambiguous legacy batches. Both earlier PRs remain unmerged as of this submission preparation.