Skip to content

feat(gym): send policy sampling with each rollout instead of into its task - #5030

Merged
yfw merged 2 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:gym-rollout-sampling
Nov 17, 2026
Merged

yfw merged 2 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:gym-rollout-sampling

Conversation

@zyzhou5

@zyzhou5 zyzhou5 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

RL side of PR 1 in the design doc "RL sampling through Gym": single-agent paths. The Gym side is NVIDIA-NeMo/Gym#5463.

Needs #5195, which bumps the Gym submodule and goes in first.

Problem

  • NeMo RL writes policy.generation's temperature, top_p and max_new_tokens into each row's responses_create_params, which does not reach every model call. Harness agents reject the fields (Coding-agent servers reject generation controls sent by NeMo-RL Gym#4656), CLI harnesses don't send them on every call, and multi-agent tasks have no single responses_create_params (review comment on #4429).
  • RL's vLLM check rejects any call that matches neither the training nor the validation values. That includes an untrained LLM judge on the policy model that runs at its own temperature.

Changes

  • _prepare_nemo_gym_rows and AsyncNemoGymRolloutImpl._build_inputs put the values on each row as _ng_model_sampling and leave the task unchanged. The values are temperature, top_p, and max_new_tokens as max_output_tokens, with the val_* values for validation. Gym applies them to every model call of the trained agent.
  • The NeMo-Gym actor sets Gym's model_call_sampling: {required_model_servers: [policy_model]}.
    • A policy_model call that lost the values fails (422) instead of sampling with other values.
    • Gym's resources servers mark their own model calls null, so a judge keeps its sampling.
    • The actor refuses sampling_overrides on policy_model and points to policy.generation.
  • The vLLM worker skips its train/val check for calls with the header x-ng-sampling: null, which Gym sends only for callers RL does not train. Trained agents' calls are still checked.
  • docs/design-docs/nemo-gym-integration.md describes the new flow.

Usage

No new configuration. Set policy.generation as before.

Validation

  • Done: ruff on the changed files.
  • Unit tests: the tests this PR adds or changes pass; the rest of those files need a GPU or Ray.
  • End-to-end GRPO at 0a09316 (this change before its rebase onto main) with Gym 77486408c. 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. Sampling: training temperature/top_p 0.85/0.97 (no agent's default), validation 0.6/0.95, max_new_tokens 2048, with vllm_cfg.logprobs_mode: processed_logprobs (main requires it when top_p < 1).
Run Entry point Token capture Slurm job W&B
Sync GRPO: validation, then 1 step examples/nemo_gym/run_grpo_nemo_gym.py off 1838133 sampling-bump-sync-20261111-r3
Async GRPO: 1 step examples/run_grpo_single_controller.py on 1838134 sampling-bump-async-20261111-r3
Agent Environment server Endpoint Sync Async
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 ✓ ✓
Codex CLI single_agent_turn Responses ✓
Claude Code single_agent_turn Anthropic Messages ✓
mini-SWE single_agent_turn Responses ✓

Every trained call carried its phase's values within the cap. LLM-judge calls carried null and kept their own values. No refusals, no vLLM sampling assertion, and both training steps completed. In the async run, RL's rollout reassembler dropped one of 16 rollouts from training (mini-SWE, ambiguous_terminal); its 5 calls carried the training values.

🤖 Generated with Claude Code

@copy-pr-bot

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

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Nov 2, 2026
@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 3, 2026
@zyzhou5
zyzhou5 marked this pull request as ready for review November 3, 2026 01:48
@zyzhou5
zyzhou5 force-pushed the gym-rollout-sampling branch from 26b8663 to 90dd761 Compare November 3, 2026 08:11
@zyzhou5

zyzhou5 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 90dd761

@zyzhou5
zyzhou5 force-pushed the gym-rollout-sampling branch from 90dd761 to d5c885e Compare November 3, 2026 18:33
@zyzhou5

zyzhou5 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d5c885e

@zyzhou5

zyzhou5 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test bd35f96

@zyzhou5
zyzhou5 force-pushed the gym-rollout-sampling branch from bd35f96 to d5e29cf Compare November 4, 2026 19:09
@zyzhou5

zyzhou5 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d5e29cf

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

GitHub reports a conflict with main, so please rebase on main. The only conflict is in the import block of nemo_rl/experience/rollout_manager.py, against #4588 (single-controller dynamic sampling). To resolve it, keep this PR's single get_nemo_gym_attribution_key import and the nemo_rl.experience.dynamic_sampling import block from main. A trial 3-way merge with that resolution has no unused or undefined names (ruff F401/F821).

Sending the sampling values beside the task, and letting Gym's model server apply them, is the right design. One place serves every agent shape, and the task stays as the dataset wrote it. The change fixes the Codex sandbox, Hermes and Pi agents that refused the stamped rows. It also lets multi-turn Harbor tasks through, and it lets an LLM judge that a resources server calls on policy_model keep its own sampling on vLLM. These parts work as described:

Inline comments:

  1. (C1) Merge blocker: the new nemo_gym.config import fails at the current Gym pin and at Gym main. Please bump the Gym submodule in this PR to a commit with NVIDIA-NeMo/Gym#5462, NVIDIA-NeMo/Gym#5463 and the change in c1f64f10a3, and update the design doc on Environment Servers.
  2. (C2) A null call that token capture records skips the vLLM sampling guard. Please run the guard on captured calls, and test that case.
  3. (C3) Servers that _copy policy_model are not in required_model_servers, and the recipe's own list is overwritten.
  4. (C4) The design doc says that all untrained calls keep their own sampling, but Gym marks only some of them. docs/guides/grpo.md does not mention the null exception.
  5. (C5) No test covers stamping a task that has no responses_create_params.
  6. (C6) The comment on the copied Gym names gives the wrong reason for the copy.
  7. (C7) Two docstrings describe behavior that the code does not have.

For information, no action needed in this PR:

  • The description says that a policy_model call that lost the values "fails (422)". The 422 comes from Gym's model server. Inside an agent session, the agent returns it as an HTTP 200 with a failed, empty turn (C1). Outside a session, the agent turns it into a 500. RL counts that as an infrastructure failure and retries before the run stops.
  • The description says that validation rows get the val_* values. That is true for grpo.validate. The validation in grpo_sync (grpo_sync.py#L323-L330, sync_rollout_actor.py#L251-L253) and in distillation stamps the training values. That is older than this PR.
  • The TRT-LLM HTTP server keeps its own train/val guard, with no null skip (trtllm_http_server.py#L478-L491). The design doc already limits the null behavior to "On the vLLM backend".
  • Agents that fill a missing output limit from their own configuration (image_tools_agent, hermes_sandboxed_agent, simple_strands_agent) now cap at the smaller of that default and max_new_tokens. No RL recipe uses them.
  • A follow-up after the bump: test_nemo_gym_episode_collection.py#L39-L46 calls pytest.importorskip on old Gym module paths. Gym keeps them only as aliases and plans to remove them in nemo_gym 0.10.0. After that, the whole file skips without an error.
  • For the Gym side: please make the trained=False helper from 65398414b5 also turn off token capture for the roles that it marks, so their calls stay out of RL's training ledger (C2).

The end-to-end runs in the description used RL bd35f96 and Gym 8d075644a. Both are from before the rebase and before NVIDIA-NeMo/Gym#2890, which changes how context variables reach Gym routes. The sampling values travel in such a context variable. After the bump, please run the sync and single-controller 1-step smoke tests again at the final commits, and say whether token capture was on.

CI ran only the pre-test jobs at head b488b20a2, because no /ok to test was posted for that commit.

Generated by Claude Code

Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread tests/unit/experience/test_rollouts.py Resolved
Comment thread nemo_rl/experience/interfaces.py Resolved
Comment thread nemo_rl/experience/rollouts.py Resolved
@zyzhou5
zyzhou5 force-pushed the gym-rollout-sampling branch from b488b20 to 0a09316 Compare November 11, 2026 02:09
@zyzhou5

zyzhou5 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0a09316

@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: 0a09316 (PR #5030 from gym-rollout-sampling)

✅ Submodules that are properly updated:

Gym: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

@zyzhou5
zyzhou5 force-pushed the gym-rollout-sampling branch from 0a09316 to 8639516 Compare November 12, 2026 18:02
@zyzhou5

zyzhou5 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8639516

@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: 8639516 (PR #5030 from gym-rollout-sampling)

✅ Submodules that are properly updated:

Gym: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

yfw
yfw previously approved these changes Nov 12, 2026
Comment thread 3rdparty/Gym-workspace/Gym Resolved
@yfw
yfw dismissed their stale review November 12, 2026 21:29

Approved by mistake while posting C8. C8 blocks the merge.

@zyzhou5
zyzhou5 force-pushed the gym-rollout-sampling branch from 8639516 to fdbfe24 Compare November 12, 2026 22:38
@zyzhou5

zyzhou5 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test fdbfe24

… task

NeMo RL wrote policy.generation's temperature, top_p and max_new_tokens into
each Gym row's responses_create_params. Harness agents reject those fields, CLI
harnesses do not send them on every call, and multi-agent tasks have no single
responses_create_params to write into (review item C4). RL's vLLM check also
rejected every call that matched neither the train nor the validation values,
including an untrained judge's call on the policy model.

Rows now carry the values for the rollout's phase beside the unchanged task, as
_ng_model_sampling, and Gym applies them to every model call of the trained
agent. Gym's model server keeps a smaller output limit the call asks for, as
the min() here did.

- The NeMo-Gym actor sets Gym's model_call_sampling block, so a call that
  lost the values fails on policy_model, on servers that _copy it and on any
  the recipe lists, and it refuses sampling_overrides on policy_model.
- The vLLM HTTP server skips its train/val check for calls that Gym marks with
  x-ng-sampling: null, which come from agents NeMo RL does not train.

Only calls Gym does not mark null are held to top_k and the policy's sampling.
_spinup imports Gym's model_call_sampling block name, so a stale Gym fails at
spinup; a test checks the names RL copies (row key, header, null) against Gym's.
A spinup test checks that score centering's logprobs/top_logprobs pin on the
required policy_model is accepted by Gym's VLLMModel.

Signed-off-by: Zeyu Zhou <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zyzhou5
zyzhou5 force-pushed the gym-rollout-sampling branch from fdbfe24 to db37d48 Compare November 16, 2026 23:46
@zyzhou5

zyzhou5 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test db37d48

The NeMo-Gym actor tells Gym to require sampling values on calls to
policy_model, the label RL's recipes give the policy's Model Server, and Gym
refuses a run whose config has no Model Server by that name. The sanity test's
config labeled the server openai_model, so its NeMo-Gym actor failed to start.

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

zyzhou5 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5fe979c

@yfw
yfw enabled auto-merge (squash) November 17, 2026 20:12
@yfw
yfw merged commit 89329fc into NVIDIA-NeMo:main Nov 17, 2026
96 checks passed
jthomson04 added a commit to jthomson04/RL that referenced this pull request Nov 17, 2026
…tron actor concurrency, Qwen3-30B recipe tuning) into jthomson04/dynamo-gym

One conflict, in nemo_rl/models/generation/vllm/vllm_worker_async.py: NVIDIA-NeMo#5030
changed the chat route's sampling check, which this branch moved to
nemo_rl/models/generation/vllm/chat_server.py. The branch's worker is kept, and
NVIDIA-NeMo#5030's change is applied in chat_server.py: a call NeMo-Gym marks with
`x-ng-sampling: null` skips the train/validation sampling check.

- tests/unit/models/generation/test_vllm_generation.py: NVIDIA-NeMo#5030's new test expects
  this branch's HTTP 400 answer for an off-policy call instead of a raised error.
- docs/guides/dynamo-generation.md: through Dynamo every chat call is still
  checked, because NeMo RL's chat engine does not read that header.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
zyzhou5 added a commit to zyzhou5/RL that referenced this pull request Nov 17, 2026
…ting

Resolve two conflicts with NVIDIA-NeMo#5030. In the design doc's data-flow
paragraph, keep main's sampling text and add the multi_harness routing
and per-agent metric clauses. In rollout_manager.py, drop the
get_nemo_gym_task_input import that main no longer uses and keep the
multi-harness imports.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zeyu Zhou <[email protected]>
jthomson04 added a commit to jthomson04/RL that referenced this pull request Nov 17, 2026
…ym rollout) into jthomson04/dynamo-1.7

Brings in NVIDIA-NeMo#4979's merge of main 89329fc (NVIDIA-NeMo#5030, NVIDIA-NeMo#5120, NVIDIA-NeMo#5007, NVIDIA-NeMo#5187, NVIDIA-NeMo#5265). Git merged the five files both sides changed without a conflict: the Dynamo guide, nemo_gym.py and three test files. pyproject.toml, uv.lock and the submodule pins are unchanged.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
jthomson04 added a commit to jthomson04/RL that referenced this pull request Nov 17, 2026
The native chat route skips the train/validation sampling check for a
call NeMo-Gym marks with the header x-ng-sampling: null, such as an LLM
judge's on the policy model (NVIDIA-NeMo#5030). Dynamo's frontend does not forward
request headers, so NeMo RL's chat engine checked every call and refused
that one with HTTP 400.

The chat engine now reads the mark from the nemo_rl:gym: annotation
(GymCallExtras.ng_sampling) and skips the check on the same value the
native route compares. NeMo-Gym's Dynamo dialect has to send it there;
the pinned Gym does not yet, and the guide says so.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: jthomson04 <[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) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants