Skip to content

fix(nemo-gym): read first-class sample mask flags - #4435

Merged
terrykong merged 2 commits into
mainfrom
alexandery/mask-sample-first-class-reader
Oct 15, 2026
Merged

terrykong merged 2 commits into
mainfrom
alexandery/mask-sample-first-class-reader

Conversation

@alexandery-nvidia

@alexandery-nvidia alexandery-nvidia commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

NeMo-Gym's BaseVerifyResponse carries mask_sample as a first-class typed field, and Gym-side evaluation aggregation reads it there. The rollout paths in NeMo-RL read only the response-extras mapping instance_config.mask_sample, so an environment that sets the first-class field is silently trained on.

All three readers now consult both forms: _mask_sample_flags on the rollout path (nemo_rl/experience/rollouts.py), and the mask-gate drop plus the sibling-seal read in the rollout manager (nemo_rl/experience/rollout_manager.py). The two reads are OR-ed rather than ordered, because Gym serializes mask_sample: false on every response, so an environment that flags only instance_config.mask_sample carries a false first-class field beside the true nested one. With env.should_mask_flagged_samples: false, the single-controller path drops both forms from the completions it builds (on copies of the results) while its per-agent metrics still report the flagged rate from the results themselves, as the batched path does. No configuration change; an environment emitting either form is masked.

Issue

No issue filed; found while training with a Gym resources server that sets the first-class field (its verifier masks rollouts whose evaluation infrastructure failed).

Validation

  • tests/unit/experience/test_rollouts.py, tests/unit/experience/test_rollout_manager.py, tests/unit/experience/test_reward_penalties.py, tests/unit/test_effort_shaping.py: 173 passed on this branch. The flag test carries the disagreeing row (mask_sample: false beside a true nested flag) and asserts it is flagged. The gate tests carry both forms on the token fixture and on the receipt fixture; a gate-off test asserts that the completion carries no flag while agent/mask_sample/mean is still reported; the finalization-request test passes the first-class form and the disagreeing row and expects both flagged.
  • Rollout evidence: the fork carrying this change ran a 50-step GRPO run on GB300 (Qwen3.5-35B-A3B, 384 rollouts per step) in which infrastructure-masked rollouts were excluded from the loss as expected.

🤖 Generated with Claude Code

Maintainer validation

Team review covered RL correctness, an independent bug/API scan, test/design perspective, existing discussion, and an independent devil’s-advocate challenge. Reviewed first-class mask_sample consumption and the legacy extras fallback; no blocking findings remain on the final reviewed head.

The additive main merge preserves all author commits.

Validation: 1 focused CPU tests passed. All formatting, lint, TOML, and recipe-minimization hooks passed. The pinned pyrefly0.24.2 check reports the same 34 diagnostics on main and this branch, from unavailable optional/native dependencies; there are no new diagnostics. No local GPU/model run was performed. Required repository CI remains the merge gate.

@copy-pr-bot

copy-pr-bot Bot commented Oct 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@linj-glitch linj-glitch changed the title fix(grpo): read the first-class mask_sample field from verify responses fix(nemo-gym): read first-class sample mask flags Oct 5, 2026
@linj-glitch linj-glitch added the CI:L0 Run doctests and unit tests label Oct 5, 2026
@linj-glitch
linj-glitch marked this pull request as ready for review October 5, 2026 17:41

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Team review covered RL correctness, an independent bug/API scan, test/design perspective, existing discussion, and an independent devil’s-advocate challenge. Reviewed first-class mask_sample consumption and the legacy extras fallback; no blocking findings remain on the final reviewed head.

The additive main merge preserves all author commits.

Validation: 1 focused CPU tests passed. All formatting, lint, TOML, and recipe-minimization hooks passed. The pinned pyrefly0.24.2 check reports the same 34 diagnostics on main and this branch, from unavailable optional/native dependencies; there are no new diagnostics. No local GPU/model run was performed. Required repository CI remains the merge gate.

@linj-glitch

Copy link
Copy Markdown
Contributor

/ok to test f0a65f4

@linj-glitch

Copy link
Copy Markdown
Contributor

/ok to test 18d8a52

linj-glitch
linj-glitch previously approved these changes Oct 6, 2026

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked the final head after updating against main f04e61b. Author history is preserved by additive main merges. No blocking logical issues remain in the reviewed changes.

Local validation: (3 durations < 0.005s hidden. Use -vv to show these durations.)
=========================== short test summary info ============================
PASSED tests/unit/experience/test_rollouts.py::test_mask_sample_flags_read_the_first_class_field_with_the_extras_fallback
1 passed, 53 deselected, 24 warnings in 7.50s
. Formatting, lint, TOML, and recipe-minimization hooks passed. Pinned pyrefly has the same 13 diagnostics as current main in this local environment, with no introduced diagnostics. No fresh GPU/model training was run. Required repository CI is awaiting test-environment approval; this approval does not bypass that merge gate.

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yaoyu-33 could you help review? does this align with some of the masking changes incoming from gym?

@aroshanghias-nvd

aroshanghias-nvd commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head 37398b1. The first-class and legacy nested mask flags are correctly OR-ed across batched rollouts, SingleController payloads, and capture finalization. The opt-out strips both forms without mutating the original results, preserving the flagged-rate metrics. Local CPU validation passed: 24 focused repository tests, 30 additional boundary probes, and 90 related tests (with some overlap); no fresh GPU training. No blocking findings in this diff.

This PR fixes mask-field ingestion; excluding masked rewards from siblings’ baseline/std and advantages is already tracked in #4061 and addressed by the open draft PRs #4490 and #4160. Our local estimator reproduction confirms that existing issue. It is not a new finding or a blocker introduced by this PR. Those estimator fixes complement this PR’s ingestion changes.

@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 93c1fae

alexandery-nvidia and others added 2 commits October 12, 2026 12:18
NeMo-Gym's BaseVerifyResponse now carries mask_sample as a first-class typed
field, and Gym-side evaluation aggregation reads it there. The rollout paths
read only the response-extras mapping instance_config.mask_sample, so an
environment that sets the first-class field is silently trained on. All three
readers now prefer the first-class field with the instance_config mapping as
the fallback: _mask_sample_flags on the rollout path, and the
mask-gate drop plus the sibling-seal read in the rollout manager. The gate
tests carry both forms and a new unit test pins the precedence.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: alexandery <[email protected]>
(cherry picked from commit 079b9f5f3699c5649bbc7a532d231f6c17937c29)
…s when the gate is off

With env.should_mask_flagged_samples: false the single-controller path
popped the flag out of each result's full_result before the per-agent
metrics were computed, so <agent>/mask_sample/* and the flag's column in
the full_result table disappeared exactly in the mode that exists to
watch a flag too coarse to honor; the batched path kept them. The gate
now works on copies handed to the completions, and _compute_rollout_metrics
aggregates the results the caller still holds (full_results), so the
completions carry no flag while the metrics still report the flagged
rate.

From review as well: the docstring and the flag test described a
precedence between the first-class field and instance_config.mask_sample
that the code never implemented. Both reads are OR-ed on purpose, because
Gym serializes mask_sample: false on every response, so a nested-only
environment carries a false first-class field beside the true nested
one; the test now carries that row. The receipt fixture carries both
forms so the receipt branch's handling of the first-class field is
observed, and the capture-manager helper can spread verify-response
fields, so the sibling-seal read is pinned with the first-class form and
the disagreeing row.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test e488c1b

@yaoyu-33 yaoyu-33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Verified first-class and legacy mask propagation across rollout paths, including the opt-out. The separate advantage-statistics work remains tracked in #4061.

@terrykong
terrykong merged commit c30bbd4 into main Oct 15, 2026
75 checks passed
@terrykong
terrykong deleted the alexandery/mask-sample-first-class-reader branch October 15, 2026 20:21
alexandery-nvidia added a commit that referenced this pull request Oct 15, 2026
…-truncated-by-status

RL #4435 merged on main as c30bbd4 and appended a test to the rollouts unit-test file where
this branch had appended its own; both sides stay.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
alexandery-nvidia added a commit that referenced this pull request Oct 15, 2026
…failures-and-redispatch

RL #4435 merged on main as c30bbd4 and appended a test to the rollouts unit-test file where
this branch had appended its own; both sides stay. Two redispatch tests stubbed `_compute_rollout_metrics` with a positional-only lambda; main's #4435 passes the aligned Gym results to it by keyword (`full_results`), so the stubs now accept keyword arguments.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
alexandery-nvidia added a commit that referenced this pull request Oct 15, 2026
…roups-distinct-first-prompts

RL #4435 merged on main as c30bbd4 and appended a test to the rollouts unit-test file where
this branch had appended its own; both sides stay.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
alexandery-nvidia added a commit that referenced this pull request Oct 15, 2026
…ta-step-metrics

RL #4435 merged on main as c30bbd4 and appended a test to the rollouts unit-test file where
this branch had appended its own; both sides stay.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
alexandery-nvidia added a commit that referenced this pull request Oct 15, 2026
…andery/gym-health-check-during-collection

Brings #4446's merge of main after RL #4435's squash (c30bbd4): main's appended rollouts test
and this stack's appended tests both stay, and the redispatch tests' metric stubs accept the
keyword argument main now passes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
alexandery-nvidia added a commit that referenced this pull request Oct 15, 2026
…xandery/gym-rollout-metrics-hook

Brings the stack's merge of main after RL #4435's squash (c30bbd4). In _compute_rollout_metrics
main now builds the per-agent rows from the full Gym results when the loop passes them, so the
mask flag the completion conversion drops is still reported; those rows feed this branch's shared
per_agent_result_metrics helper, which keeps the union of keys and the masked-row exclusion.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
macandro96 added a commit that referenced this pull request Oct 23, 2026
…s rollout metrics

Main now passes full_results to _compute_rollout_metrics and computes per-group
reward diagnostics from each result's full_result (#4435). This test predates
that and still stubbed the old signature and built results without
full_result, so it failed in CI's Nemo Gym unit lane after the rebase.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
macandro96 added a commit that referenced this pull request Oct 26, 2026
…s rollout metrics

Main now passes full_results to _compute_rollout_metrics and computes per-group
reward diagnostics from each result's full_result (#4435). This test predates
that and still stubbed the old signature and built results without
full_result, so it failed in CI's Nemo Gym unit lane after the rebase.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
macandro96 added a commit that referenced this pull request Oct 27, 2026
…s rollout metrics

Main now passes full_results to _compute_rollout_metrics and computes per-group
reward diagnostics from each result's full_result (#4435). This test predates
that and still stubbed the old signature and built results without
full_result, so it failed in CI's Nemo Gym unit lane after the rebase.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
macandro96 added a commit that referenced this pull request Oct 28, 2026
…s rollout metrics

Main now passes full_results to _compute_rollout_metrics and computes per-group
reward diagnostics from each result's full_result (#4435). This test predates
that and still stubbed the old signature and built results without
full_result, so it failed in CI's Nemo Gym unit lane after the rebase.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
macandro96 added a commit that referenced this pull request Oct 31, 2026
…s rollout metrics

Main now passes full_results to _compute_rollout_metrics and computes per-group
reward diagnostics from each result's full_result (#4435). This test predates
that and still stubbed the old signature and built results without
full_result, so it failed in CI's Nemo Gym unit lane after the rebase.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
macandro96 added a commit that referenced this pull request Oct 31, 2026
…s rollout metrics

Main now passes full_results to _compute_rollout_metrics and computes per-group
reward diagnostics from each result's full_result (#4435). This test predates
that and still stubbed the old signature and built results without
full_result, so it failed in CI's Nemo Gym unit lane after the rebase.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
macandro96 added a commit that referenced this pull request Oct 31, 2026
…s rollout metrics

Main now passes full_results to _compute_rollout_metrics and computes per-group
reward diagnostics from each result's full_result (#4435). This test predates
that and still stubbed the old signature and built results without
full_result, so it failed in CI's Nemo Gym unit lane after the rebase.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
macandro96 added a commit that referenced this pull request Nov 2, 2026
…s rollout metrics

Main now passes full_results to _compute_rollout_metrics and computes per-group
reward diagnostics from each result's full_result (#4435). This test predates
that and still stubbed the old signature and built results without
full_result, so it failed in CI's Nemo Gym unit lane after the rebase.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants