Which masked rollouts still move the GRPO baseline, under each masked_reward_policy

NVIDIA-NeMo/RL #4968 (adds exclude_infra), a follow-up to #4160. Code links pinned to head 956c6f04. Background on the first two values: who votes (#4160).

Before
Two values. include (default): every masked rollout's reward still counts in its group's baseline and std. exclude: no masked rollout counts, even when the policy caused the mask.
This PR
Adds a third, opt-in value, exclude_infra: a masked rollout counts only if the environment blamed the policy for it.
Status
Open PR, not merged. The default stays include, so no shipped recipe changes. The review raises no training bug, only doc and test fixes (see the end).
Background. In GRPO each prompt gets several rollouts. A rollout's advantage compares its reward with its siblings'. A masked rollout never trains, but under include its reward still shifts its siblings' baseline. NeMo-Gym also sends a failure_kind string saying why it masked a row. The PR splits masked rows by that string: a kind in grpo.policy_failure_kinds (for example agent_timeout) is the policy's fault; any other kind, or none, is an infrastructure failure. Dotted words have a short explanation: hover or tap them.

One prompt group, five rollouts. A, B, C are normal. D was masked because the agent timed out (a policy kind). E was masked with no failure_kind, for example a judge error, so its reward is a meaningless 0 or 1. The numbers are from running the PR's real estimator (GRPO, leave-one-out baseline, rewards normalized by std).

one prompt group: rollout = reward advantage of A if E = 0if E = 1 normalnormalnormal masked:agent_timeout masked:no kind includedefault A = 1 B = 1 C = 0 D = 0 E = 0|1 +1.500+0.866 votes by dataset weight: _include_valid_mask exclude_infranew, opt-in A = 1 B = 1 C = 0 D = 0 E = 0|1 +1.155+1.155 E's dataset weight set to 0 when results arrive (rollouts.py L3585) exclude A = 1 B = 1 C = 0 D = 0 E = 0|1 +0.707+0.707 votes by loss weight: _binary_participation votes and trains votes, never trains left out of baseline and std red= A's advantage depends on E's meaningless reward D and E never train in any mode (loss weights [1, 1, 1, 0, 0]); the modes differ only in who sets A, B, C's baseline.

Where each value does the work

include and exclude decide who votes at the advantage step. exclude_infra does not add a third rule there. It works earlier: when Gym's results arrive, it gives each infrastructure-failed row a dataset weight of 0, the same weight an over-length prompt gets. From then on it is just include, which never lets a zero-weight row vote. That is why no trainer's advantage math changed.

Rollout builder, after (legacy, async and TQ trainers)

# per prompt group, when Gym's results arrive
mask_sample = flags(results)                 # Gym: this row gets no loss
if policy == "exclude_infra":
    infra = mask_sample & (kind not in policy_failure_kinds)  # infra_failure_flags
    loss_multiplier[infra] = 0                   # same weight as an over-length prompt
    metrics["infra_failure_sample_rate"] = infra.mean()

Real code: _postprocess_single_nemo_gym_group. SingleController does the same in record_to_train_batch (native) and finalize_group (token capture), writing 0 into sample_mask.

Who votes, before

# advantage step, every trainer
def _advantage_valid_mask(loss_weight, cfg, dataset_weight):
    if cfg.masked_reward_policy == "include":
        return dataset_weight != 0              # every row the dataset kept
    return loss_weight != 0                     # exclude: only rows that still train

Who votes, after

def _advantage_valid_mask(loss_weight, cfg, dataset_weight):
    if cfg.masked_reward_policy == "include":
    if cfg.masked_reward_policy in ("include", "exclude_infra"):  # _votes_by_dataset_weight
        return dataset_weight != 0              # E's weight is already 0 here
    return loss_weight != 0

Real code: _advantage_valid_mask, _dynamic_sampling_valid_mask (same switch), SingleController advantage stage. The kinds list defaults to Gym's model-fault kinds (DEFAULT_POLICY_FAILURE_KINDS), and a Gym-lane test fails if the two drift apart.

Rolloutincludeexclude_infraexclude
Not masked (A, B, C)votesvotesvotes
Masked, kind in policy_failure_kinds (D)votesvotesout
Masked, any other kind or none (E)votesoutout
Over-length prompt (dataset weight 0)outoutout

What to take away, and what the review asks

Only under include does a meaningless reward (E) move the advantages of rollouts that train. exclude_infra removes that, and unlike exclude it keeps a policy-caused failure (D) in the baseline, because a timeout is a real result. It is opt-in, so existing recipes do not change.

The review has no training bug. It asks for:

The comment links open once the review is published.