Skip to content

feat(environments): carry a training framework's sampling values into multi-agent environments - #5562

Open
zyzhou5 wants to merge 3 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:feat-multi-agent-model-sampling
Open

zyzhou5 wants to merge 3 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:feat-multi-agent-model-sampling

Conversation

@zyzhou5

@zyzhou5 zyzhou5 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Gym side of PR 2 in the design doc "RL sampling through Gym": multi-agent environments. It needs no NeMo RL code change; NeMo RL picks it up with a Gym submodule bump. Two of its parts moved into #5463 during review and are on main: environment servers that do not apply the values refuse them (applies_model_sampling), and roles an agent runs besides the trained one get null (trained=False).

Problem

  • On main, nemo_user_sim and swe_together refuse an episode that carries a training framework's sampling values (model_sampling): they do not apply them, so they do not declare applies_model_sampling. A NeMo RL run cannot use them.

What each participant's URL carries, in a run with values

Environment Participant URL carries
nemo_user_sim Assistant (trained) The episode's values
nemo_user_sim User simulator; judge, summary and tool simulation (the environment's own calls to support_model) null
swe_together Candidate (trained) The episode's values
swe_together Judge; user simulator and interaction scorer null

Each environment server sets its participants' segments with BaseEnvironmentServer.model_sampling_segment(request, trained=...), and both now declare applies_model_sampling. Every untrained participant that calls a Gym Model Server is marked null explicitly, so a trained participant whose segment goes missing is refused rather than sampled as untrained. A participant wrongly given null is not refused; the tests check who gets which.

Not changed

  • sampling_overrides, model_call_sampling.required_model_servers ([policy_model]) and nemo_user_sim's shipped config.
  • One trained participant per environment, as today.
  • Gym-only eval: no values, no segment, the same URLs.

Compatibility

  • UserSimEnvironmentServer.responses_path: keyword capture_training_tokens is now trained.
  • nemo_user_sim and swe_together now admit episodes that carry values; on main they refuse them at admission.
  • swe_together's run_judge and AuxiliaryModel take a new keyword-only model_sampling (default None).

Validation

  • New tests in nemo_user_sim's and swe_together's suites, including which participants get the values with token capture on.
  • Server suites pass: swe_together; nemo_user_sim ran with a stand-in for usersim.
  • pre-commit run --files on the changed files: passed.
  • End to end at bbb44a5, the full stack before two of its parts moved into feat(rollouts): carry a training framework's sampling values to every model call #5463 (later commits only rebase and add the tests and docs above), with feat(gym): send policy sampling with each rollout instead of into its task RL#5030 at bd35f96. Nemotron 3 Nano 30B-A3B (BF16) on one node with 4 GB300 GPUs. Sampling: training 0.85/0.97, validation 0.6/0.95, max_new_tokens 2048. Each untrained role is pinned to values of its own.
  • swe_together ran later, Gym only, at d0e4280 (this head): one task with the training values, sandboxes on OpenSandbox. Its untrained roles keep the benchmark's own settings. The judge reached its turn limit before giving a verdict, so the episode is unscored; that doesn't affect the sampling check.
Run Entry point Slurm job W&B
Async GRPO: 1 step examples/run_grpo_single_controller.py 1715476 sampling-pr2-async-r2
Gym only: training values, validation values, none nemo_user_sim rollouts (no NeMo RL recipe yet) 1715482
Gym only: training values swe_together rollout, one task 1946599
Agent Environment server Endpoint Untrained roles Async GRPO Gym only
simple_agent + LLM judge single_agent_turn Responses LLM judge ✓
tau2 legacy_agent Chat Completions simulated user ✓
conversational_tool_use_policy_tool_generation legacy_agent Chat Completions judge ✓
simple_agent nemo_user_sim Responses simulated user; judge, summary, tool simulation ✓
opencode_agent swe_together Chat Completions judge (claude_code_agent), simulated user, interaction scorer ✓

Every trained call carried its phase's values within the cap. Every untrained role's calls carried null and kept its own values. No refusals; in the RL run, no vLLM sampling assertion fired and the training step completed.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 4, 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-multi-agent-model-sampling branch from 973a307 to bbb44a5 Compare November 4, 2026 19:02
@zyzhou5
zyzhou5 marked this pull request as ready for review November 5, 2026 00:20
@zyzhou5
zyzhou5 force-pushed the feat-multi-agent-model-sampling branch 2 times, most recently from 835adfc to 5418fe8 Compare November 5, 2026 00:41
@zyzhou5
zyzhou5 marked this pull request as draft November 5, 2026 18:48
@zyzhou5
zyzhou5 force-pushed the feat-multi-agent-model-sampling branch from 5418fe8 to d4bac44 Compare November 6, 2026 19:58
@zyzhou5
zyzhou5 marked this pull request as ready for review November 6, 2026 19:58
@zyzhou5

zyzhou5 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d4bac44

@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 RISK issues: collation can discard the new sampling field, and redirects can drop the sampling segment before generation. Both can make trained calls fail or use the wrong sampling values.

I reviewed the supplied changeset and directly affected contracts, callers, and tests. This was a static review; I didn't execute tests or independently verify the reported smoke runs.


Inline comments (escaped v1):

  • nemo_gym/data/dataset_preparation.py line 1314: RISK — Preserve sampling when collation materializes a flat row

    A flat source row containing responses_create_params and _ng_model_sampling={"temperature":0.6}, declared with taskset: tasks, loses its sampling during collation. materialize_task removes _ng_ fields from task data, but this whitelist restores only identity fields. The new _episode_request_body branch consequently sends no model_sampling. A required Model Server refuses the trained call; an optional one generates without the requested values.

    Could you import MODEL_SAMPLING_KEY_NAME here and add it to this tuple, immediately after ATTEMPT_INDEX_KEY_NAME?

                                        ATTEMPT_INDEX_KEY_NAME,
                                        MODEL_SAMPLING_KEY_NAME,
    

    Also add the literal "_ng_model_sampling" to RESERVED_ROW_KEYS. Validation runs before conversion and currently treats this framework field as unknown task data, so strict collation rejects the same valid row. Keep the existing whitelist rather than copying every _ng_ field. The invariant is that sampling survives beside the task, never inside it.

    Proposed checks, not executed: extend test_collation_preserves_shard_and_retry_identity with _ng_model_sampling={"temperature":0.6,"top_p":0.95,"max_output_tokens":64}. Assert that the prepared row retains it, task_input excludes it, and the parsed episode request contains exactly those values. Retain both explicit-rollout-ID cases and their attempt assertions. Add a strict-validation case that accepts this field while still rejecting an unrelated unknown task field. Rows without sampling must retain their existing shape. Please verify the suggested change before adopting it.

  • nemo_gym/server_runtime/request_handling/model_sampling.py line 129: RISK — Keep the sampling segment on redirects

    Stripping the segment without restoring it on redirect responses loses the caller's sampling. For example, send POST /ng-sampling/<encoded temperature=0.6>/v1/responses/ with body {"input":"task","temperature":1.0} to a Model Server and follow its trailing-slash redirect. The first request is routed as /v1/responses/; it isn't rewritten because _TOKEN_LIMIT_FIELDS matches only the slashless path. The redirect therefore targets /v1/responses without sampling. A required server answers 422, while an optional server generates at 1.0 instead of 0.6. The agent middleware has the same omission at its forwarding branch.

    Redirect preservation is already part of the URL-prefix contract: the trace middleware restores its segment, and its existing regression test explicitly covers followed trailing-slash redirects.

    Could you wrap send in both sampling middleware classes and restore the original sampling segment on root-relative and same-origin redirect targets? Preserve the mount path, rollout ID, capture tag, trace context, and query; insert sampling after those prefixes, without duplicating an existing segment. Leave cross-origin redirects untouched. The exact helper needs to account for the different model and agent prefix stacks; a blanket prepend would put sampling before the rollout prefix and be rejected.

    Proposed checks, not executed: parameterize followed trailing-slash requests across Responses, Chat Completions, and Messages, with required sampling on and off. Encoded values must reach the provider and capture unchanged, including the output cap. A null request must retain the caller's sampling and the vLLM x-ng-sampling: null header. Add an agent activation case proving its downstream model call retains the segment. Repeat with rollout/capture/trace prefixes and a relay mount; retain slashless behavior, query strings, unsampled evaluation behavior, malformed-segment rejection, and unchanged cross-origin redirect targets.

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

@kajalj22
kajalj22 removed request for a team November 6, 2026 22:02
@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:training Training framework integrations and training-data interfaces labels Nov 7, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Nov 7, 2026
@zyzhou5
zyzhou5 force-pushed the feat-multi-agent-model-sampling branch from d4bac44 to 5f9ed17 Compare November 9, 2026 19:46
@zyzhou5

zyzhou5 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5f9ed17

@zyzhou5

zyzhou5 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c97de79

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

This PR needs a refreshed description and swe_together rollout evidence before it merges.

The description predates the rebase onto main:

  • It says the PR is stacked on #5463 and that its last five commits are this PR's. #5463 has merged, and this PR is three commits.
  • Several parts describe #5463, not this PR: the second problem bullet, the tau2, pinchbench and conversational_tool_use_policy_tool_generation rows, the applies_model_sampling paragraph, and the compatibility notes on the agent URL helper.
  • Compatibility should list the new model_sampling keyword on run_judge and AuxiliaryModel. It should also say that nemo_user_sim and swe_together now admit episodes with values instead of refusing them at admission.
  • Validation lists unit tests this PR does not touch, and the end-to-end run is at bbb44a5, before the rebase.
  • "A trained participant whose values get lost is refused rather than sampled as untrained" holds only when the segment is missing. A participant given null passes required_model_servers.

No run shows swe_together with values. Please add a short smoke run where the candidate on policy_model gets the values and the judge, user simulator and interaction scorer carry null. Or say why it is N/A.

Two follow-ups for whichever change lands second:

  • #5711 conflicts with this PR in responses_path. Its nemo_user_sim test still calls responses_path(capture_training_tokens=...), which needs trained=.
  • NVIDIA-NeMo/RL#5030's doc names only single_agent_turn, single_agent_turn_legacy and harbor as environment servers that apply the values.

zyzhou5 and others added 3 commits November 13, 2026 18:51
… values

nemo_user_sim accepted an episode's model_sampling and ran every participant
without it. The assistant, the participant a training framework trains, now
carries the episode's values in its activation path, beside the training tag it
already had. The user simulator carries null, and so do the environment's own
judge, summary and tool-simulation calls to support_model, which defaults to
the policy endpoint: they keep their own sampling, or support_model's
sampling_overrides. Those calls set the segment through the request context, so
the server client places it after any rollout prefix it adds.

nemo_user_sim now declares applies_model_sampling. Gym-only evaluation sends no
values, and its URLs are unchanged.

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

swe_together accepted an episode's model_sampling and ran its agents without it.
The candidate, the agent a training framework trains, now carries the episode's
values in its activation path. The judge agent's activation and the environment's
own simulator and interaction-scorer calls carry null, so they keep their own
sampling, or their Model Servers' sampling_overrides.

swe_together now declares applies_model_sampling. Gym-only evaluation sends no
values, and its URLs are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zeyu Zhou <[email protected]>
The training guide said nemo_user_sim and swe_together do not apply a training
framework's values yet. It now lists the participants those environments do not
train among the calls that keep their own sampling, and describes how an
environment server applies the values to its participants or refuses them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zeyu Zhou <[email protected]>
@zyzhou5
zyzhou5 force-pushed the feat-multi-agent-model-sampling branch from c97de79 to d0e4280 Compare November 13, 2026 18:52
@zyzhou5

zyzhou5 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d0e4280

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 13, 2026 18:53
@zyzhou5
zyzhou5 requested a review from ananthsub November 17, 2026 18:24
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 18, 2026
@ananthsub

Copy link
Copy Markdown
Contributor

Before this merges, I think it should be folded into the agent-instance stack (#5252, #5253). Otherwise Gym ends up with two conventions for which agent instances are trained: one for token capture and one for sampling.

Where the two diverge. This PR fixes the trained agent instance in code (_TRAINED_ALIAS = "assistant_model" in nemo_user_sim, trained=True on swe_together's candidate). #5253 adds the training-capture tag from the run-level token_id_capture.training_agent_instances list. Once both land, a run that sets training_agent_instances: [assistant, user] captures nemo_user_sim's user simulator for training while this PR gives it /ng-sampling/null, so it samples with its own values. Nothing fails, because null passes required_model_servers. One of #5253's swe_together tests sets [assistant, judge], which does the same to the judge.

Proposed split: three settings at three levels.

  • Token capture settings (enabled, capture directory, store): the Gym config, as today.
  • Which agent instances are trained: the environment server. Each environment server declares a default trained agent instance (nemo_user_sim → assistant, swe_together → its candidate), which its own config can override. The environment server binds the choice in the episode seed, and both the training-capture segment and the sampling values follow from it.
  • Per episode: whether this rollout is captured at all (skip_token_capture, feat(capture): let a rollout skip token capture #5711), and the sampling values themselves (model_sampling), both carried with the row.

What this removes. all_agents was added before environment servers, so that NeMo RL could turn on capture for single-agent training without naming agent servers. With environment servers it is a footgun: it turns on capture for every agent server, including judges and simulated users served by the policy model. With the choice in the environment server, single-agent training no longer needs it either:

  • Rows routed through an agent's own /run (legacy_agent, single_agent_turn_legacy) have exactly one agent. Rollout collection can mark that request as trained, the same way it already carries the per-row skip flag.
  • all_agents and the per-agent-server token_id_capture flag can then become deprecated aliases.
  • The run-level training_agent_instances list has not shipped, so it can be dropped.

Concretely for this PR: rebase onto #5253, and replace _TRAINED_ALIAS and swe_together's trained=True with the stack's selection, so that an agent instance gets the run's sampling values exactly when it is trained.

@pthombre, does this split work for the stack?

@zyzhou5

zyzhou5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

currently waiting for #5253 to be merged

This branch had an error being deployed

1 failed (outdated) 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 sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants