Which rows count toward the GRPO baseline: include vs exclude

NVIDIA-NeMo/RL #4160 ยท follow-up #4968 ยท permalinks pinned to head 1429122e

Before
There was no switch. Each trainer chose on its own which rows count toward the advantage statistics. The legacy and TransferQueue loops counted every row; SingleController counted only rows that train.
This PR
Adds grpo.masked_reward_policy: include (default) or exclude. All four trainers apply it the same way.
Status
Merged (2026-10-27). The review found no bugs. Two items are still open: #4968 handles the default for rows the environment flags (it adds an opt-in exclude_infra), and the include-vs-exclude training comparison was never posted.
Background. GRPO trains on groups of answers to the same prompt. Each answer's advantage is its reward minus the group's average reward (the baseline). Some rows are kept out of the loss, for example an answer cut off at the length limit, or one the environment marked as bad data. The question this PR answers: should those rows still count toward the average their siblings are compared against? Dotted words have a short explanation: hover or tap them.

The loss mask never changes; a masked row never trains. The new key decides only which rows vote, meaning which rows count toward the group baseline, the standard deviation, batch normalization and dynamic-sampling admission. Under include, every row with a nonzero dataset weight votes (_include_valid_mask). Under exclude, only rows with a nonzero loss weight vote. Voting is yes or no: a row with loss weight 0.5 still gets one full vote (_binary_participation).

One prompt group, 5 answers. Std scaling and leave-one-out off, to keep the numbers simple. answer reward flag trains? votes: include votes: exclude r11normal r21normal r30normal r40cut off at length limit r50env flagged mask_sample baseline 2/5 = 0.40 2/3 โ‰ˆ 0.67 advantage of r1 (reward 1) +0.60 +0.33 advantage of r3 (reward 0) โˆ’0.40 โˆ’0.67 trains (loss weight 1) no loss votes in baseline does not vote _advantage_valid_mask picks the column

The same three rows train in both columns. Only the baseline moves. Under include the two masked zeros pull the average down, so the correct answers r1 and r2 get a bigger push (+0.60 instead of +0.33). That is the trade-off. A row that was cut off really did fail, so counting it is fair. A row the environment flagged because its own grader broke is not a real measurement, yet under include it still moves its siblings. #4968 is the follow-up for that case.

Where each trainer decides, and where they meet

The three loop trainers call one shared helper, _advantage_valid_mask. SingleController makes the same two-way choice in its own six lines, because that stage also runs PPO. Every path then passes the result to the estimator as valid_mask. That is where they become one: GRPO, GDPO and Reinforce++ all read it (GRPO, GDPO, Reinforce++).

TrainerPicks the voters atWhat the default (include) changed
Legacy sync GRPOgrpo.py L4150GRPO/GDPO group averages: nothing. Reinforce++ batch normalization now counts masked rewards.
Async GRPOgrpo.py L5994Same as legacy.
TransferQueuegrpo_sync.py L1058Same as legacy, and rows flagged with mask_sample no longer train (they used to train at full weight).
SingleControlleradvantage_stage.py L424Masked, cut-off and sequence-error rows now vote. Before, only rows that train voted.

Two kinds of rows never vote, on any trainer, under either setting: prompts too long to fit the sequence limit (the dataset gives them loss_multiplier = 0 before any rollout), and SingleController's empty placeholder rows.

Why PPO is left out. In advantage_stage.py, the check not cfg.is_ppo only avoids reading a field PPO's config does not have. PPO's GAE estimator has no group baseline. It whitens advantages over the tokens that train (L575) and never reads valid_mask. So the setting has nothing to change for PPO.

So what. Pick exclude when your environment flags rows because its own grader or tooling failed. Those rewards are noise, and under include they shift every sibling's advantage. Keep include (the default) when masked rows are real failures, such as answers cut off at the length limit. No controlled training run comparing the two has been published yet. To run one, use the paired include / exclude configs.

๐Ÿ“ review comment C1 (docs wording) โ€” grpo.py:363