Skip to content

feat: Overlap external vLLM and NeMo RL startup - #4381

Merged
terrykong merged 4 commits into
mainfrom
yifuw/external-vllm-startup-overlap
Oct 12, 2026
Merged

terrykong merged 4 commits into
mainfrom
yifuw/external-vllm-startup-overlap

Conversation

@yfw

@yfw yfw commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Upstreams #3832 from super-v3.5-posttraining: overlap external vLLM model loading with NeMo RL startup, gated by a readiness check in the NeMo Gym actor. Works on all Gym entrypoints, including the SingleController path (examples/run_grpo_single_controller.py).

Previously tools/external_gym_vllm/run_in_allocation.sh waited for every external vLLM pool to become healthy before starting ray.sub. Now it:

  1. starts ray.sub on hetgroup 0 while the external pools are still loading;
  2. replaces a required __EXTERNAL_SERVICE_READINESS__ token in COMMAND with ++env.nemo_gym.external_service_readiness=..., carrying each pool's load-balancer /health URL and its replica count; and
  3. keeps watching both the external services and ray.sub during startup.

The NeMo Gym actor starts its local Gym servers, then polls every external load balancer until /health reports status: ok and healthy_backends / total_backends at or above the replica count. All pools share one deadline. On timeout the actor stops its local servers and raises. Ray, policy/trainer, and local Gym initialization now overlap with external model loading, and rollout collection still can't start early.

Adapted to main

  • One extraction point for every entrypoint. The readiness block is popped and validated in _build_gym_actor_config. run_grpo.py, distillation, and the SingleController path all reach it through build_nemo_gym_actors. The source PR's distillation.py call-site change is therefore unnecessary and dropped. On the SC path, Gym spinup already runs in its own ThreadPoolExecutor task next to generation and trainer init, so the readiness wait blocks only that task.
  • Sharded Gym. external_service_readiness is added to NEMO_RL_DICT_CONFIG_KEYS. Otherwise find_gym_config_entries treats this dict-valued key as a Gym server overlay. A multi-shard plan then rejects it ("have no owner"), and a single-shard plan passes it through to Gym silently. With the fix, every shard gets the block.
  • Timeout cleanup. The actor clears self.rh before calling RunHelper.shutdown(), the same way NemoGym.shutdown() does. The caller's teardown calls shutdown() again, and RunHelper.shutdown() is not idempotent.

Issues

N/A (upstream of #3832)

Usage

COMMAND must include __EXTERNAL_SERVICE_READINESS__ among the training script's arguments. run_in_allocation.sh and validate_external_vllm_submission refuse to start without it, and the Ultra and Lightning launchers add it when external pools are configured. The wrapper replaces the token with the block below. To set it by hand:

env:
  nemo_gym:
    external_service_readiness:
      services:
        - name: GENRM
          url: http://10.0.0.1:9213/health
          expected_backends: 2
      timeout_seconds: 3600
      poll_interval_seconds: 5
      request_timeout_seconds: 10

New launcher knobs: EXTERNAL_VLLM_READINESS_POLL_INTERVAL_SECONDS (default 5) and EXTERNAL_VLLM_READINESS_REQUEST_TIMEOUT_SECONDS (default 10).

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

Testing

  • Unit: 368 passed across test_nemo_gym.py, test_nemo_gym_utils.py, test_nemo_gym_shards.py, test_external_gym_vllm.py, and single_controller/test_setup.py (-m "not nemo_gym"; the 3 tests that need the nemo_gym extra were not run locally).
  • New tests on top of feat: Overlap external vLLM and NeMo RL startup #3832's: the shared builder lifts the block out of Gym's global config, a malformed block fails on the driver before any actor is created, and the block reaches every shard.
  • Not yet run end to end with external vLLM pools on main. The super-v3.5-posttraining before/after runs from feat: Overlap external vLLM and NeMo RL startup #3832 are summarized in the PR comments: about 8 minutes less from allocation to setup complete and to the end of a 2-step run.

Known limitation (pre-existing, not changed here). Sharded Gym spinup has a fixed 1800s budget (DEFAULT_SHARD_SPINUP_TIMEOUT_SECONDS) that no caller can override. The readiness deadline is the largest pool POOL_STARTUP_TIMEOUT (default 3600s). With sharded Gym and an external pool that takes more than 30 min to load, shard spinup fails before the readiness deadline. Unsharded Gym has no such cap. The shard timeout error also suggests env.nemo_gym.spinup_timeout, which isn't wired to anything yet. Tracked in #4565.

🤖 Generated with Claude Code

Upstream of #3832 from super-v3.5-posttraining.

The external vLLM launcher now starts ray.sub while the external pools are
still loading and injects an env.nemo_gym.external_service_readiness block.
The NeMo Gym actor starts its local servers, then waits for every external
load balancer to report the required healthy backend count under one shared
deadline before it exposes rollout collection.

Adapted to main:
- The readiness block is extracted in _build_gym_actor_config, which every
  entrypoint (run_grpo.py, distillation, and the SingleController path in
  run_grpo_single_controller.py) reaches through build_nemo_gym_actors. The
  distillation.py call-site hunk is therefore unnecessary and dropped.
- external_service_readiness is registered in NEMO_RL_DICT_CONFIG_KEYS so
  sharded Gym treats it as a NeMo RL setting rather than an unclaimed Gym
  server overlay, and every shard receives it.
- The timeout cleanup clears self.rh before calling RunHelper.shutdown(),
  matching NemoGym.shutdown(), since the caller's teardown calls shutdown()
  again and RunHelper.shutdown() is not idempotent.

(cherry picked from commit d96ae88)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Sep 30, 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.

@yfw

yfw commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4b80f15

1 similar comment
@yfw

yfw commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4b80f15

@yfw yfw added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Sep 30, 2026

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

The overlap is a clean port of #3832: the launcher's override round-trips through ray.sub and Hydra into ExternalServiceReadinessConfig, every entrypoint strips the block before it reaches Gym, sharded configs propagate it, and the teardown paths hold.

Inline: one timeout-diagnostics fix (source plus a paired test edit), an optional test for the _spinup gate wiring, and two out-of-date guides.

Generated by Claude Code

Comment thread nemo_rl/environments/nemo_gym.py Resolved
Comment thread tools/external_gym_vllm/README.md Resolved
- _wait_for_external_services raises right after its final sleep instead
  of starting a round at the deadline. That round could not probe and
  overwrote every observation with "startup deadline expired before
  probe", hiding the real cause (connection refused, a backend short).
- The timeout test now lets sleep drive the clock, so its last sleep ends
  at the deadline, as it does in a real run. It fails on the old loop.
- New test runs NemoGym._spinup with the readiness gate set and pins the
  order: RunHelper.start, the wait, then RunHelper.shutdown with self.rh
  cleared first.
- Both Nemotron 3 Ultra guides now describe the overlapped startup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Oct 2, 2026
@yfw

yfw commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d61fd40

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

The overlap is a clean change. The gate is set up in the one place every Gym entrypoint goes through (nemo_gym.py#L1793), sharded configs carry it to every shard (nemo_gym_shards.py#L40-L41), and the launcher still stops the job if a pool dies (run_in_allocation.sh#L671). Thanks for applying all four self-review fixes.

Three inline comments, all low severity: make the launcher's readiness override work no matter how COMMAND ends, say in the probe's docstring which /health it expects, and add a test that ties the probe to the load balancer's real reply.

Two asks not tied to a line:

  • The description says this hasn't run end to end with external pools on main yet. Could you share one run with the Ultra or Lightning launcher that reaches the first rollout step, plus its time to first step compared with the old wait-then-start order? That number is the point of the PR.
  • Please file the follow-up for the 1800s sharded-spinup limit you listed under "Known limitation", and link it here.

Generated by Claude Code

Comment thread nemo_rl/environments/nemo_gym.py Resolved
@terrykong
terrykong enabled auto-merge (squash) October 6, 2026 07:11
Appending the external_service_readiness override to COMMAND bound it to
whatever ended the command: with a trailing `| tee log`, `; echo done`, or
`# comment` the gate was silently dropped and rollouts could start against
pools that were still loading.

- run_in_allocation.sh substitutes __EXTERNAL_SERVICE_READINESS__, the same
  way it substitutes pool URLs, and refuses to start without it.
- validate_external_vllm_submission rejects a command without the token.
- The Ultra and Lightning launchers add the token to TRAIN_CMD only when
  external pools are configured, so ray.sub-only runs never see it.
- The probe docstrings state that the URL must be a vllm_pool_lb /health
  endpoint; a plain vLLM /health never reads as ready.
- New test feeds LoadBalancer.handle_health's real reply into
  _probe_external_service, so a field rename on either side fails CI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @terrykong. All three inline comments are addressed in e25db89. Answers to the two other asks:

Follow-up for the sharded spinup limit: #4565.

Before/after startup. Both runs used the Lightning 3.5 launcher with the same topology: 26 NeMo RL nodes plus 6 external nodes (GenRM 2× TP=8, NL2Bash 2× TP=4). Both were 2-step runs and completed both steps.

Elapsed from Slurm allocation start:

Milestone Before With overlap
ray.sub starts 9m22s 0m21s
Driver starts 14m41s 6m28s
Setup complete (generation, policy and Gym ready) ~27m ~19m
Step 1 duration 182.7s 185.6s
2-step run ends (ray.sub exits) 40m03s 31m56s

There's no wall-clock stamp on the start of step 1 itself. Setup completion and run end both come out about 8 minutes earlier, and the step times match, so time to first step drops by about the same 8 minutes. Setup completion is bracketed from vLLM log timestamps, so it's only accurate to about a minute. In the overlap run the Gym actor logged All external NeMo-Gym services are ready: GENRM, NL2BASH with no Waiting for ... line before it. The pools were already healthy by the time Gym's local servers were up, so all of their roughly 9 minutes of loading was hidden.

Caveats:

  • These are the pre-merge validation runs of feat: Overlap external vLLM and NeMo RL startup #3832 on super-v3.5-posttraining, not runs of this branch on main. A run of this branch on main is still pending.
  • Not a controlled benchmark. Policy MTP was on only in the before run, and the runs got different node sets. Most of the gap is the 9 minutes ray.sub used to spend waiting for the pools, which MTP doesn't affect.

@yfw

yfw commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Additional startup A/B measurements using this PR's main-branch base (910773917e) versus the tested PR revision (d61fd40e36).

Both arms used the same recipe, dependencies, container, and resource topology, with policy MTP disabled in both.

Elapsed from Slurm allocation start, excluding queue time:

Milestone Before With overlap
ray.sub starts 9m55s 0m20s
Driver starts 14m44s 7m07s
Setup complete (generation, policy, and Gym ready) ~23m33s ~16m13s

Allocation-to-setup time decreased by approximately 7m20s (31%). The logs confirm that the overlap arm starts Ray while external judge pools are loading, rather than waiting for them first. Driver-side RL initialization was similar: 517.4s before versus 534.7s with overlap; the improvement comes from overlapping the pre-driver startup work.

The setup-completion estimates combine the timestamped driver launch, logged Python/import startup time, and RL INIT TIMING BREAKDOWN total. These are startup-only measurements from one A/B pair on different node allocations, so exact timings can vary with cluster and filesystem conditions.

@yfw

yfw commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4e73fad

@terrykong
terrykong merged commit f821987 into main Oct 12, 2026
171 of 175 checks passed
@terrykong
terrykong deleted the yifuw/external-vllm-startup-overlap branch October 12, 2026 22:41
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