masked_reward_policyNVIDIA-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).
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.exclude_infra: a masked rollout counts only if the environment blamed the policy for it.include, so no shipped recipe changes. The review raises no training bug, only doc and test fixes (see the end).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).
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.
| Rollout | include | exclude_infra | exclude |
|---|---|---|---|
| Not masked (A, B, C) | votes | votes | votes |
Masked, kind in policy_failure_kinds (D) | votes | votes | out |
| Masked, any other kind or none (E) | votes | out | out |
| Over-length prompt (dataset weight 0) | out | out | out |
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:
exclude_infra the default, as the #4160 follow-up promised, once a same-seed run on an environment that really masks samples shows no regression.
C1 — grpo.py:433infrastructure_error. This is wording only; the row is still left out.
C2 — grpo.md:368infra_failure_sample_rate from a per-row one.
C4 — test_selected_forest_boundaries.py:1471failure_kind field name next to the other copied Gym names, out of grpo.py.
C8 — grpo.py:393exclude_infra, as under include.The comment links open once the review is published.