Skip to content

feat(gym): support Environment Server tasksets - #4429

Merged
yfw merged 7 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:gym-environment-server
Nov 4, 2026
Merged

yfw merged 7 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:gym-environment-server

Conversation

@zyzhou5

@zyzhou5 zyzhou5 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Support Environment Server tasksets in NeMo-RL while preserving existing recipes that use the legacy_agent wrapper. Handle nested task inputs, taskset-based routing to Gym actors, and episode results in both token-capture and inline rollouts. Preserve agent attribution and reward-shaping metadata, and honor terminal episode failures within the existing retry policy.

Also documents taskset training in the NeMo Gym integration guide and adds an OpenMathReasoning GRPO recipe with AIME24 validation, using Simple Agent through single_agent_turn.

Validation

  • 902 focused tests passed: 883 CPU unit tests, 18 episode/HTTP collector tests, and the Gym authentication startup test, covering both row formats, routing, receipt identities, failure handling, reward shaping, and authentication.
  • Lint, formatting, recipe minimization, and type checking of the changed allowlisted modules passed. Full-project type checking reports the same 38 diagnostics as main in the local CPU environment.

Math recipe E2E passed: AGA job 1507776 used Nemotron Nano 9B v2 on one node with four GB300 GPUs, a 16K sequence limit, and three GRPO steps with eight prompts × four generations. All 96 training samples were valid, losses were finite, gradients were nonzero, and the step-3 checkpoint was saved; the job exited 0.

Two mixed-path training runs passed on PR revision 99341ff53ebe with its Gym pin da9f671490c3. Both used Nemotron-3-Nano-30B-A3B-BF16 on one AGA node with four GB300 GPUs: two for Megatron training (TP=2, EP=2) and two for vLLM inference (TP=2), with token capture and R3 enabled. Each ran three GRPO steps with two generations per prompt and a 1,024-token limit per model call.

Run Environment Server orchestration legacy_agent wrapper Batch and context Accepted training samples
Weather + Gymnasium (job 1270863) Weather tool with SimpleAgent Multi-turn Gymnasium agent 4 prompts/step, 16K context 24 total: 12 per path
Hermes + OpenHands (job 1279027) SWE-bench Pro NodeBB with Hermes SWE-rebench python-markdown__markdown-1529 with OpenHands through swe_agents 2 prompts/step, 32K context 12 total: 6 per path

The coding test used temporary compatibility fixes outside this PR; see Gym #4656.

The runs loaded their Gym definitions through env.nemo_gym.config_paths. The relevant definitions are shown inline under env.nemo_gym below; unrelated settings are omitted.

Weather + Gymnasium configuration
env:
  should_use_nemo_gym: true
  nemo_gym:
    config_paths:
      - responses_api_models/vllm_model/configs/vllm_model_for_training.yaml

    example_single_tool_call:
      resources_servers:
        example_single_tool_call:
          entrypoint: app.py
    example_single_tool_call_simple_agent:
      responses_api_agents:
        simple_agent:
          entrypoint: app.py
          num_workers: 1
          max_steps: 6
          model_server: {type: responses_api_models, name: policy_model}
    example_single_tool_call_environment_server:
      environment_servers:
        single_agent_turn:
          entrypoint: app.py
          resources_server: {type: resources_servers, name: example_single_tool_call}
          agent_server: {type: responses_api_agents, name: example_single_tool_call_simple_agent}
          resources_tool_transports: [direct_http]

    example_multi_turn_gymnasium:
      resources_servers:
        example_multi_turn_gymnasium:
          entrypoint: app.py
          allowed_agents: [gymnasium_agent]
    example_multi_turn_gymnasium_agent:
      responses_api_agents:
        gymnasium_agent:
          entrypoint: app.py
          max_steps: 5
          resources_server: {type: resources_servers, name: example_multi_turn_gymnasium}
          model_server: {type: responses_api_models, name: policy_model}
    example_multi_turn_environment_server:
      environment_servers:
        legacy_agent:
          entrypoint: app.py
          agent_server: {type: responses_api_agents, name: example_multi_turn_gymnasium_agent}

    environment_server_routes:
      example_single_tool_call:example: example_single_tool_call_environment_server
Hermes + OpenHands configuration
env:
  should_use_nemo_gym: true
  nemo_gym:
    config_paths:
      - responses_api_models/vllm_model/configs/vllm_model_for_training.yaml
      - resources_servers/swebench_pro/configs/swebench_pro.yaml
      - responses_api_agents/hermes_agent/configs/hermes_agent.yaml

    hermes_agent:
      responses_api_agents:
        hermes_agent:
          resources_server: null
          model_server: {type: responses_api_models, name: policy_model}
          max_turns: 8
    swebench_pro_environment_server:
      environment_servers:
        single_agent_turn:
          entrypoint: app.py
          resources_server: {type: resources_servers, name: swebench_pro_resources_server}
          agent_server: {type: responses_api_agents, name: hermes_agent}
          resources_tool_transports: []

    swe_agents_train:
      responses_api_agents:
        swe_agents:
          entrypoint: app.py
          agent_framework: openhands
          agent_config: responses_api_agents/swe_agents/configs/oh_config.toml
          agent_max_turns: 8
          model_server: {type: responses_api_models, name: policy_model}
    swe_agents_train_environment_server:
      environment_servers:
        legacy_agent:
          entrypoint: app.py
          agent_server: {type: responses_api_agents, name: swe_agents_train}

    environment_server_routes:
      swebench_pro: swebench_pro_environment_server

Dataset rows select the route: materialized task rows use task_id.taskset and environment_server_routes; flat rows use agent_ref.name to select the wrapped agent.

@copy-pr-bot

copy-pr-bot Bot commented Oct 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 Oct 2, 2026
@zyzhou5 zyzhou5 added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed Documentation Improvements or additions to documentation labels Oct 2, 2026

@zyzhou5 zyzhou5 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Generated by Codex using NeMo-RL’s review-pr-team skill

No issues found in the reviewed changes, including checks for redundant mechanisms, trackers, and test coverage.

Full regression tests and end-to-end GPU training were not rerun for this review.

@zyzhou5

zyzhou5 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test b73e7f9

@zyzhou5

zyzhou5 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 93bae51

@zyzhou5
zyzhou5 force-pushed the gym-environment-server branch from 93bae51 to 7e1139e Compare October 15, 2026 17:02
@zyzhou5 zyzhou5 added CI:L1 Run doctests, unit tests, and functional tests and removed CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) labels Oct 15, 2026
@zyzhou5 zyzhou5 changed the title feat(gym): support native Environment Server tasksets feat(gym): support Environment Server tasksets Oct 15, 2026
@zyzhou5

zyzhou5 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7e1139e

@zyzhou5 zyzhou5 added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Oct 15, 2026
@zyzhou5
zyzhou5 force-pushed the gym-environment-server branch from 7e1139e to 99341ff Compare October 15, 2026 19:05
@zyzhou5

zyzhou5 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 99341ff

@zyzhou5

zyzhou5 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 61ce964

Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread nemo_rl/environments/nemo_gym.py Resolved
@ananthsub
ananthsub requested a review from yfw October 16, 2026 17:19
Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread nemo_rl/experience/rollout_manager.py Resolved
Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread nemo_rl/environments/nemo_gym_shards.py Resolved
Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread nemo_rl/environments/nemo_gym.py Resolved
@zyzhou5

zyzhou5 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 28d7daf

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Oct 20, 2026
@zyzhou5
zyzhou5 force-pushed the gym-environment-server branch from f7c41b1 to 1f299a8 Compare October 20, 2026 06:23
@zyzhou5

zyzhou5 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2fca130

@zyzhou5

zyzhou5 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a8bb38f

@zyzhou5
zyzhou5 force-pushed the gym-environment-server branch from 2fca130 to a8bb38f Compare October 30, 2026 23:29
yaoyu-33
yaoyu-33 previously approved these changes Nov 2, 2026

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

Reviewed a8bb38f. Approving with one non-blocking follow-up: the async collector still retries terminal Gym episode failures. Add the existing is_terminal_gym_episode_failure(last_error) check alongside the actor-death guard in _collect_rollout_batch, with a regression test.

Validation: 98 focused CPU tests passed with the Ray/GPU fixtures excluded. A source-function probe reproduced four dispatch attempts for terminal failures and confirmed that the proposed guard stops after one. Full GPU training was not rerun locally.

CI remains outstanding: L0_Unit_Tests_Other failed when one process in the unchanged two-rank leader-broadcast test did not exit within 30 seconds; the aggregate quality check also failed. Patch coverage is 78.23% against the 80% target.

@zyzhou5

zyzhou5 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e93eb41

Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread nemo_rl/experience/rollout_manager.py Resolved
Read materialized task inputs, route Environment Server requests, and adapt episode results for training while preserving flat-row support. Include the initial scope simplifications and regression coverage.

Signed-off-by: Zeyu Zhou <[email protected]>
Address the first review round: clarify task-row and episode terminology, preserve compatibility routing, and validate recovery overrides.

Signed-off-by: Zeyu Zhou <[email protected]>
Address startup validation and compatibility-failure feedback, including terminal-failure handling and regression coverage.

Signed-off-by: Zeyu Zhou <[email protected]>
Address taskset attribution feedback across rollout grouping, metrics, and recovery. Include the corresponding updates to existing test expectations.

Signed-off-by: Zeyu Zhou <[email protected]>
Address the replay-compatibility follow-up and document taskset training. Add the validated OpenMathReasoning recipe with AIME24 evaluation.

Signed-off-by: Zeyu Zhou <[email protected]>
Preserve taskset episode handling through the updated capture and recovery contracts, with integration coverage for capture modes and retries.

Signed-off-by: Zeyu Zhou <[email protected]>
@zyzhou5
zyzhou5 force-pushed the gym-environment-server branch from e93eb41 to e082209 Compare November 3, 2026 18:03
@zyzhou5

zyzhou5 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e082209

@zyzhou5

zyzhou5 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e91d968

@yfw
yfw enabled auto-merge (squash) November 3, 2026 20:19
@yfw
yfw merged commit f91988b into NVIDIA-NeMo:main Nov 4, 2026
90 checks passed
@terrykong terrykong mentioned this pull request Nov 21, 2026
1 task done
alexandery-nvidia added a commit that referenced this pull request Nov 24, 2026
…warning

Since #4429 a materialized task row carries no agent_ref, so the warning,
which read row["agent_ref"]["name"], raised KeyError for a group of such
rows whose first prompts differ. It now reads the attribution key that
_postprocess_single_nemo_gym_group stamps on every result (the agent of a
flat row, the taskset of a materialized task), reports once per key, and
says "attribution key(s)" in the message. The test covers a group of
materialized task rows.

Two tests that main added (#4500, #5206) run _run_rollouts on results
that carry tokens with no tokenizer. The diagnostic pads the first
prompts with the tokenizer's pad id, so both tests get the tokenizer
stand-in that the other tests of this path use.

Signed-off-by: alexandery <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[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.

4 participants