Skip to content

feat(gym): do not capture tokens for validation rollouts - #5098

Merged
terrykong merged 5 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:gym-rollout-token-capture-off
Dec 1, 2026
Merged

terrykong merged 5 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:gym-rollout-token-capture-off

Conversation

@zyzhou5

@zyzhou5 zyzhou5 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

RL side of NVIDIA-NeMo/Gym#5711: validation rollouts are not token-captured.

It has no effect until validation runs with token capture on, which no RL path does yet.

Related: #5044 (item 1, "Training-time validation": the single-controller validation loop that will turn this on).

Problem

  • With token capture on, Gym captures every rollout of a capturing agent, including validation rollouts that RL never trains on. A validation loop under capture would make RL's vLLM worker stage their token ids and logprobs in TransferQueue, plus the top_logprobs alternatives when set.
  • Under token capture, the Gym actor assumes every rollout was captured, and masks a rollout that has no capture records.

Changes

  • run_nemo_gym_rollout_sync and run_async_nemo_gym_rollout take skip_token_capture (default False):
    • with True, _prepare_nemo_gym_rows marks each row _ng_skip_token_capture: true, and Gym captures none of that rollout's model calls;
    • with False, it removes any leftover mark, so rows RL trains on never skip capture. The single-controller rollout manager clears it too.
  • GRPO's and distillation's validate() and grpo_sync's validate_sync() pass skip_token_capture=True; SyncRolloutActor.rollout_to_tq forwards it for grpo_sync.
  • Under token capture, the Gym actor reads no capture manifest for a row RL skipped. It returns the Environment Server's result as full_result, with receipt: None. A row without the mark still needs its capture, and is masked as before when it has none.
  • NEMO_GYM_SKIP_TOKEN_CAPTURE_KEY copies Gym's SKIP_TOKEN_CAPTURE_KEY_NAME, and a test checks that they match.

Usage

No new configuration. Validation rollouts skip token capture.

Validation

  • New unit tests for marking validation rows (GRPO, distillation and grpo_sync), each step that passes the setting on, clearing the mark from training rows, and the Gym actor's handling of skipped rollouts. Removing any line they guard fails them.
  • End-to-end single-controller GRPO at b6b395a with Gym #5711 (8bb0e7ab1) as the Gym submodule. Nemotron 3 Nano 30B-A3B (BF16) on one node with 4 GB300 GPUs: vLLM TP2 on 2 GPUs (not colocated), Megatron TP2/EP2 on the other 2. Token capture on, observability off, 1 step of 8 prompts × 2 generations. A test hook, not part of this PR, sent one more rollout per training prompt the way validation does, alongside the training rollouts: _prepare_nemo_gym_rows(skip_token_capture=True), then the same Gym actor.
Run Entry point Slurm job W&B
Async GRPO with token capture: 1 step, plus 8 skipped rollouts examples/run_grpo_single_controller.py, through a test hook 1742620 capture-skip-r4
Agent Environment server Endpoint Training rollouts captured Skipped rollouts not captured
simple_agent + LLM judge single_agent_turn Responses ✓ ✓
simple_agent + LLM judge single_agent_turn_legacy Responses ✓ ✓
simple_agent + LLM judge legacy_agent Responses ✓ ✓
verifiers_agent legacy_agent Chat Completions ✓ ✓
mini-SWE single_agent_turn Responses ✓ ✓

The 8 skipped rollouts returned their reward with no model call captured, and kept their rollout prefix. The 16 training rollouts were captured as before, and the step trained.

🤖 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 gym-rollout-token-capture-off branch from 653e967 to b6b395a Compare November 6, 2026 23:08
@zyzhou5
zyzhou5 marked this pull request as ready for review November 9, 2026 18:56
@zyzhou5 zyzhou5 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 12, 2026
@zyzhou5

zyzhou5 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test b6b395a

@zyzhou5
zyzhou5 force-pushed the gym-rollout-token-capture-off branch from b6b395a to 4380d94 Compare November 16, 2026 23:59
@zyzhou5

zyzhou5 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4380d94

@zyzhou5
zyzhou5 force-pushed the gym-rollout-token-capture-off branch from 4380d94 to 00da814 Compare November 17, 2026 20:33
@zyzhou5

zyzhou5 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 00da814

@zyzhou5
zyzhou5 requested a review from pthombre November 19, 2026 18:08

@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 change is the RL half of NVIDIA-NeMo/Gym#5711 and it is done carefully: the setting is a plain keyword argument with the safe default, training rows are cleared rather than trusted, and the copied key name has a comment and a test that fails if Gym's name changes.

What the review checked:

  • All three NeMo-Gym validation paths (GRPO, distillation, grpo_sync) pass skip_token_capture=True, and no training path can send the mark.
  • RL writes the mark the way Gym reads it, at both the Gym commit this PR pins and the one main pins.
  • Removing any production line the PR adds makes one of the PR's tests fail (run in a light environment, not the locked one).

One small cleanup:

  1. (C1, C2) The skip_token_capture key in the result of a rollout that skipped token capture has no reader outside the test.

Generated by Claude Code

Comment thread nemo_rl/environments/nemo_gym.py Resolved
@zyzhou5

zyzhou5 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0d29049

zyzhou5 and others added 3 commits November 20, 2026 20:33
Gym can now skip token capture for one rollout: a row with
`_ng_skip_token_capture: true` makes none of that rollout's model calls
carry the training tag, so RL's vLLM worker stages nothing for it in
TransferQueue (NVIDIA-NeMo/Gym#5340).

- GRPO and distillation validation mark their rows with
  `_ng_skip_token_capture: true`
  (`run_nemo_gym_rollout_sync(skip_token_capture=True)`). Rows RL trains on
  drop any leftover mark, so they are always captured; the single-controller
  rollout manager clears it the same way.
- Under token capture, the Gym actor reads no ledger manifest for a row RL
  skipped. It returns the Environment Server's result with `receipt: None`
  and `skip_token_capture: True`. A row without the mark still needs its
  capture and is masked as before when it has none.

No path runs validation with token capture today: only the single
controller enables capture, and it has no validation loop. Synchronous
validation never captures, so the mark changes nothing there yet.

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:
- The TransferQueue sync trainer's validation (`grpo_sync.validate_sync`)
  marks its rows: `SyncRolloutActor.rollout_to_tq` takes
  `skip_token_capture` and forwards it to `run_nemo_gym_rollout_sync`.
- Tests for each forwarding step: sync to async, async to
  `_prepare_nemo_gym_rows`, the single controller's `_build_inputs`, and
  distillation's and grpo_sync's validation.
- Comments say that training rows never skip capture, rather than that
  they are always captured.

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

No code reads the key in the Gym actor's result for a rollout RL skipped
capture for; a caller that needs to know already holds the row and its
`_ng_skip_token_capture` mark. Remove it with the docstring words that
named it.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zyzhou5
zyzhou5 force-pushed the gym-rollout-token-capture-off branch from 0d29049 to cceb2eb Compare November 20, 2026 20:39
@zyzhou5

zyzhou5 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test cceb2eb

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

Thanks for this. The RL half of Gym#5711 is small and safe. The default clears the mark on training rows, which matters because Gym's dataset prep keeps a row's skip mark (dataset_preparation.py). The copied key has a test that fails, not skips.

What we checked:

  • Every Gym validation path passes the flag: grpo, distillation and grpo_sync. Async GRPO reuses grpo's validate.
  • Gym reads the key at the row's top level, where RL writes it (episode_context.py).
  • With capture off, the mark changes nothing (base_responses_api_agent.py).
  • Every added line fails a test if reverted.

FYI, no action: the v1 batch builder reads input_message_log[0], so it can't use token-less results, captured or skipped. Nothing reaches it today: only the single controller turns capture on, and it has no validation loop yet. Whoever turns on validation with capture will need that consumer to read full_result.

Inline:

  1. (C3) Trim the _skipped_capture_result docstring to three lines, ending with a pointer to #5044.

Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5098-validation-skips-capture.html

nemo-rl-review: kind=expert harness=claude-code/2.1.332 model=claude-opus-5-5 effort=medium review-pr-team=v3 reviewed=cceb2eb

Comment thread nemo_rl/environments/nemo_gym.py Resolved
Say what the helper returns and point single-controller validation to
NVIDIA-NeMo#5044 and full_result, as suggested in review.

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

zyzhou5 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d75f961

@svcnvidia-nemo-ci svcnvidia-nemo-ci added complexity:medium Moderate change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:none Cannot change training results. Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify) labels Nov 30, 2026
@terrykong
terrykong enabled auto-merge (squash) November 30, 2026 21:43
@terrykong

Copy link
Copy Markdown
Collaborator

/ok to test 457d683

@terrykong
terrykong merged commit 5674b58 into NVIDIA-NeMo:main Dec 1, 2026
102 of 106 checks passed
yfw added a commit that referenced this pull request Dec 1, 2026
…masked_reward_policy

Main's #5098 added test_actor_forwards_the_token_capture_setting_to_the_gym_rollout
with a SimpleNamespace grpo config that has no masked_reward_policy. On this
branch rollout_to_tq passes exclude_infra_policy_kinds(cfg.grpo), which reads
that field, so the test raised AttributeError after the merge of main. Real
configs always carry it (GRPOConfig defaults it to exclude_infra), so the fake
config gets the field rather than the read getting a default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[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) complexity:medium Moderate change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:none Cannot change training results. Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants