Skip to content

feat(capture): let a rollout skip token capture - #5711

Merged
zyzhou5 merged 6 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:feat-rollout-token-capture-off
Nov 12, 2026
Merged

zyzhou5 merged 6 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:feat-rollout-token-capture-off

Conversation

@zyzhou5

@zyzhou5 zyzhou5 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Token capture is set once per run (token_id_capture), so a training framework that validates through capturing agents gets its validation rollouts captured like its training rollouts. NeMo RL would then stage their token ids and logprobs in TransferQueue, which is wasted for rollouts it never trains on. RL does not hit this yet: only its single-controller runner captures, and it has no validation loop.

A row can now set _ng_skip_token_capture: true. None of that rollout's model calls carries /training-token-capture, so nothing is captured for it. false or no key keeps today's behavior: a row can turn capture off, never on. A skipped rollout keeps its /ng-rollout/<id> prefix and any /ng-sampling/<values> segment; only the training tag is dropped.

Where Change
Agent /run Reads _ng_skip_token_capture from the row.
Rollout collection Passes it to Environment Servers as skip_token_capture: true in the episode request, and does not rebuild a skipped row's response.
Environment Servers single_agent_turn, harbor, swe_together and nemo_user_sim call their agents without /training-token-capture. single_agent_turn_legacy reads the setting from the flat row.
Agents activated on a rollout path without /training-token-capture Capture nothing, whatever their own token_id_capture setting. Harnesses that build their own model URL (Claude Code, Codex, OpenCode, ...) used to add the segment back from their config. An unprefixed /v1/responses call keeps the agent's own setting.

The last row also affects two roles that Environment Servers already call without the segment: nemo_user_sim's user simulator and swe_together's judge stop being captured when they run on such a harness. Neither is trained on. An Environment Server outside Gym that activates a harness without the segment, and relied on the harness's own token_id_capture, stops capturing too.

A skipped rollout otherwise runs like an uncaptured evaluation rollout, including in agents whose output depends on capture: Claude Code folds its thinking into the message text and names its response with a generated id, and osworld_agent builds its response without the served calls.

Relation to other work

Issue

Closes #5340.

Validation

  • New unit tests for the row key, the agent routes (including Claude Code through /run), rollout collection, each Environment Server's activation path, and Claude Code's output under the skip. Removing any line they guard fails them.
  • Core, Environment Server and agent suites pass; the remaining core failures are environment-only. Not run here (missing packages): nemo_user_sim, mini-SWE sandboxed, swe_agents and verifiers.

Rollouts

Validated end to end in NVIDIA-NeMo/RL#5098 at 8bb0e7a: in a single-controller GRPO step with token capture on, skipped rollouts through single_agent_turn, single_agent_turn_legacy and legacy_agent were not captured and kept their rollout prefix, while training rollouts were captured as before.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 5, 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.

@zyzhou5
zyzhou5 force-pushed the feat-rollout-token-capture-off branch from c6356e0 to 8bb0e7a Compare November 6, 2026 23:08
@zyzhou5
zyzhou5 marked this pull request as ready for review November 6, 2026 23:25
@zyzhou5

zyzhou5 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8bb0e7a

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

SHIP WITH CARE

I found two preparation-path defects: task-data validation rejects the new framework key, and taskset collation drops it before dispatch. The inline findings describe separate corrections.

RISK — Required real-rollout evidence is missing

The PR description says end-to-end validation hasn't run. The protected AGENTS.md quality bar requires representative real-model smoke rollouts for behavior-changing agent or environment work. The mocked tests don't establish that a real harness and model server honor the new activation behavior together.

Could you run captured and skipped rows through a real harness/model pairing, covering /run and a typed Environment Server activation, and record the configuration, commands, rollout IDs, and inspected outcomes? No implementation patch is established by this evidence gap.

Proposed acceptance checks: the ordinary row retains the training tag and produces captured records; the skipped row retains its attempt-qualified rollout prefix, produces no training-token records, bypasses rebuilding without a capture-induced mask, and completes verification and cleanup. Preserve false/absent-key capture behavior, ensure a row cannot enable disabled capture, and retain evaluation-style output for skipped Claude Code runs. In a multi-participant pairing, the user simulator or judge must remain untagged.

I completed static inspection across all 24 changed files and their directly affected paths, including consolidation of all three review topics. I didn't execute tests or model rollouts.


Inline comments (escaped v1):

  • nemo_gym/data/task_data.py line 70: RISK — Reserve the new control in task-data validation

    The new _ng_skip_token_capture contract isn't reflected in RESERVED_ROW_KEYS. A flat example row such as {"responses_create_params":{"input":"task"},"_ng_skip_token_capture":true} is reported as containing an unknown task field against the empty example schema. Normalization leaves the key in the schema input; unknown extras make the report dirty, and strict collation raises. This affects flat rows and rows awaiting taskset materialization. A framework control should not require a task-schema field.

    Add only this key to the reserved set; don't suppress every _ng_* field or weaken task validation. Suggested replacement at this anchor, not executed; please verify before adopting:

            "_ng_rollout_index",
            "_ng_skip_token_capture",
    

    Proposed acceptance checks: validate the row above against the empty example schema and assert a clean report with no unknown keys; repeat with false and without the key. Add an unrelated typo and assert that it still produces a dirty report. Retain the existing misplacement regression: top-level unit_tests must still raise for both flat and taskset declarations. These are source-derived checks, not test results.

  • nemo_gym/data/dataset_preparation.py line 1314: RISK — Preserve the skip flag during taskset collation

    With a flat source row containing _ng_skip_token_capture: true and a dataset declaration containing taskset: tasks, this branch saves only the four identity fields. materialize_task() removes every _ng_* field, so the prepared row loses the skip. With validation off/warn—or after correcting the separate reserved-key issue—the episode converter receives no flag. Configured capture then runs and the collector rebuilds a rollout that requested neither. Already-materialized rows retain the flag, so the two supported preparation paths disagree.

    Keep the control at the prepared row's top level, beside task_id and task_input. The smallest correction is to import SKIP_TOKEN_CAPTURE_KEY_NAME and include it in this preserved-field tuple. Don't retain all collector metadata inside task_input.

    Suggested patch, not executed; please verify before adopting:

    @@ from nemo_gym.config.global_config import (
         ROLLOUT_INDEX_KEY_NAME,
    +    SKIP_TOKEN_CAPTURE_KEY_NAME,
         TASK_INDEX_KEY_NAME,
    @@
                                         ATTEMPT_INDEX_KEY_NAME,
    +                                    SKIP_TOKEN_CAPTURE_KEY_NAME,

    Proposed acceptance checks: extend test_collation_preserves_shard_and_retry_identity with the flag. Assert that true survives at the prepared row's top level, stays out of task_input, and yields skip_token_capture: true in the episode request. Preserve the existing shard-ID and attempt assertions, repeated copies, and source-file bytes. With false or no key, the episode must still omit the serialized flag. A retained non-boolean value must still be rejected by the collector's strict skip parser.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:training Training framework integrations and training-data interfaces needs-review PR is ready for code review and waiting on a reviewer labels Nov 7, 2026
@zyzhou5
zyzhou5 force-pushed the feat-rollout-token-capture-off branch from 8bb0e7a to 43294bb Compare November 9, 2026 19:40
@zyzhou5

zyzhou5 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 43294bb

@pthombre pthombre 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.

Thanks for this. The skip path looks correct across the agents, the five Environment Servers and rollout collection, and rows without the key behave exactly as on main. Both earlier bot findings are fixed at this head. Two small questions inline: how a null skip value should be treated, and a docs note for the new untagged-activation behavior.

Generated by Claude Code

Comment thread nemo_gym/core/episode_context.py Resolved
@zyzhou5
zyzhou5 force-pushed the feat-rollout-token-capture-off branch from 43294bb to 1e7c1fd Compare November 10, 2026 19:59
@zyzhou5

zyzhou5 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1e7c1fd

zyzhou5 and others added 6 commits November 11, 2026 01:17
A training framework that also runs rollouts it does not train on, such as
validation rollouts, can set `_ng_skip_token_capture: true` on the row. None
of that rollout's model calls then carries the `/training-token-capture`
segment, so the model server admits none of them for capture, and a
framework that stages tokens from its generation worker stores none.

- Agents: `/run` reads the row's setting, and an activation on a rollout path
  without the training tag captures nothing, whatever the agent's own
  `token_id_capture` setting. Both set a per-request context that
  `_token_id_capture_enabled()` reads, so harnesses that build their own
  model URL from it (Claude Code, Codex, OpenCode, ...) follow the rollout.
  `url_path_for_run` and `base_url_for_run` also read the row, for agents
  whose `/run` route does not set the context.
- Rollout collection passes the setting to Environment Servers as
  `skip_token_capture: true` in the episode request (omitted when false).
  single_agent_turn, harbor, swe_together and nemo_user_sim activate their
  agents without the tag; the flat-row relay reads it from the row.
- Rollout collection does not rebuild the response of a row that skips
  capture.

A row can turn capture off, never on: `false` or no key leaves capture to the
run's `token_id_capture` block.

Refs: NVIDIA-NeMo#5340

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Follow-up to the team review of the per-rollout skip:
- Rollout correlation now follows the run's configuration
  (`_token_id_capture_configured()`), so a `/run` that skips capture keeps
  its `/ng-rollout/<id>` prefix and drops only the training tag, as an
  Environment Server activation already did. The tag and capture-dependent
  output still follow the request (`_token_id_capture_enabled()`).
- Tests: Claude Code through the real `/run` route, Claude Code's
  evaluation output under the skip, every untagged rollout activation
  route, and the collector's episode request parsed by BaseEpisodeRequest.
- Docs: the section moves next to "Provide unique rollout ids", describes
  flat and typed rows correctly, and says what frameworks that rebuild
  responses and custom harnesses must do.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A dataset row may set `_ng_skip_token_capture: true`. Task-data validation
now treats the key as framework-owned (`RESERVED_ROW_KEYS`) instead of an
unknown task field, and taskset collation keeps it at the prepared row's
top level beside the collector identity, so the episode request still
skips capture.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… activations

- `_ng_skip_token_capture: null` now counts as unset, as `_ng_rollout_id: null`
  does: a table that sets the column on some rows writes null on the others,
  and one such row stopped the whole collection. Other non-boolean values are
  still refused, and the error names the row by its task and rollout index.
  The agent `/run` request accepts null too.
- The harness page says that an activation without `/training-token-capture`
  captures none of its calls, even if the agent sets `token_id_capture`.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
OpenCode now builds its model URL while handling the activation, so the
activation's path decides capture. An Environment Server activates a captured
rollout on `/ng-rollout/<id>/training-token-capture/v1/responses`; the test
used the untagged path, which no longer captures.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A rollout's sampling values travel in an `/ng-sampling/<values>` segment after
the training tag. Pin that an untagged activation drops only the tag and keeps
the sampling segment, and that a tagged one keeps both.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zyzhou5
zyzhou5 force-pushed the feat-rollout-token-capture-off branch from 1e7c1fd to 1ebb215 Compare November 11, 2026 01:34
@zyzhou5

zyzhou5 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1ebb215

@zyzhou5
zyzhou5 added this pull request to the merge queue Nov 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43310972604

Merged via the queue into NVIDIA-NeMo:main with commit 23557b7 Nov 12, 2026
67 of 69 checks passed
@zyzhou5
zyzhou5 deleted the feat-rollout-token-capture-off branch November 12, 2026 21:45

This branch had an error being deployed

1 failed deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:training Training framework integrations and training-data interfaces feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow token capture to be turned off per rollout (validation rollouts are captured today)

3 participants