Skip to content

feat(external-vllm): Support for persistent judge model pools - #4542

Merged
yfw merged 9 commits into
mainfrom
sniverty/external-vllm-persistent-pool
Oct 16, 2026
Merged

yfw merged 9 commits into
mainfrom
sniverty/external-vllm-persistent-pool

Conversation

@snivertynv

@snivertynv snivertynv commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

EXTERNAL_VLLM_MODE=serve runs the pools as their own long-lived job; training jobs attach through attach_and_run.sh, which resolves the URLs and #4381's readiness gate from the pool's manifest at job start and stops training if the pool stops, is replaced, or goes silent. pool_config.sh gains submit_external_vllm_pool_job / submit_external_vllm_attached_job as the single entry point. Early Ray start (previously part of this PR) is superseded by #4381 and dropped.

Issues

Depends on NVIDIA-NeMo/Gym#4108: Gym's model-endpoint startup check must treat a load balancer's 503 (no healthy backend yet) as "still starting". Without it, both early Ray and attaching to a pool that is still loading can send rollouts to a judge with no healthy backend. The wait is bounded by env.nemo_gym.model_endpoint_readiness_timeout_seconds (Gym default 600 s); don't set it to 0, which skips the check.

Usage

Early Ray (inline, the existing two-hetgroup job): Ray, the driver and worker setup start as soon as the pools' load balancers are up, instead of after every replica is healthy.

EXTERNAL_VLLM_EARLY_RAY=1 sbatch ... tools/external_gym_vllm/run_in_allocation.sh   # otherwise unchanged

Persistent pools (serve): run the pools alone as a plain job that outlives any training job.

EXTERNAL_VLLM_MODE=serve EXTERNAL_VLLM_POOL_DIR=<shared>/judge-pools/<name> \
sbatch --nodes=<external-pool-nodes> --exclusive --gres=gpu:4 --time=<hours> \
  --export=ALL tools/external_gym_vllm/run_in_allocation.sh

Once every pool is healthy, the job writes <pool>_url, pools.env, job_id and log_dir to EXTERNAL_VLLM_POOL_DIR, and READY last. It relaunches a replica or load balancer that exits on the same nodes, so URLs never change (up to EXTERNAL_VLLM_MAX_RESTARTS, default 5). On exit it removes READY and writes STOPPED.

Attach a training job:

  • If the pools are READY, substitute each URL for its placeholder in COMMAND and submit ray.sub directly.
  • If they are still queued or loading, submit with attach_and_run.sh as the batch script. It waits for READY from the expected pool job (EXTERNAL_VLLM_ATTACH_TIMEOUT, default 3600 s), then fills in the URLs and runs ray.sub:
EXTERNAL_VLLM_POOL_DIR=<shared>/judge-pools/<name> EXTERNAL_VLLM_POOL_JOB=<pool-job-id> \
COMMAND="... <POOL>_URL_PLACEHOLDER ..." RAY_SUB=<path>/ray.sub \
sbatch --dependency=after:<pool-job-id>+15 --nodes=<training-nodes> ... \
  --export=ALL tools/external_gym_vllm/attach_and_run.sh

inline mode (the existing heterogeneous job) is unchanged, and EXTERNAL_VLLM_EARLY_RAY defaults to 0.

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

End-to-end (Nemotron-3.5-nano GRPO recipe with GenRM, NL2Bash and safety-judge pools, on a GB300 Slurm cluster):

  • Early Ray, 86 nodes: Ray stopped waiting for the judges (470 s → 17 s blocked), cutting several minutes off time to first training step.
  • Serve/attach, 10 nodes:
    • A training job was cancelled mid-run and resubmitted against the same pool, with no judge reload.
    • Killing both NL2Bash replicas mid-run: the pool relaunched them under the same URL and the run completed.
    • Deferred attach: a training job submitted while the pool was loading waited for READY, then ran.
  • Serve/attach, 86 nodes: a 68-node training job attached to a 22-node pool job completed 3 GRPO steps. Step times and setup time matched the inline layout, and the training job holds 22 fewer nodes.

@snivertynv
snivertynv requested review from saumishr and yfw October 6, 2026 17:03
@snivertynv snivertynv self-assigned this Oct 6, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 6, 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.

@snivertynv snivertynv changed the title feat(external-vllm): Support for persistent judge model pools that survive training-job restarts and enable early Ray start feat(external-vllm): Support for persistent judge model pools and early Ray start Oct 6, 2026
@snivertynv snivertynv changed the title feat(external-vllm): Support for persistent judge model pools and early Ray start feat(external-vllm): Support for persistent judge model pools Oct 7, 2026
@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test 2ea4123

@snivertynv snivertynv added the CI:L0 Run doctests and unit tests label Oct 7, 2026
@snivertynv
snivertynv requested a review from terrykong October 8, 2026 12:53
@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test b551c62

@saumishr

saumishr commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

@snivertynv I followed up with @yfw
On overlapping the NemoRL start up with externalized vLLM, there may be some overlap with this PR: #4381 which is planned to get merged soon? Could we please rebase on top of that PR?

Also, on persistent judge pools, @yfw had built some POC here: 11746b3

@yfw could you please take a look at the approach in this PR and we can move this PR forward.

@saumishr

saumishr commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

@snivertynv The change looks good to me. Confirming the workflow first:

Step 1: start the pool once:

EXTERNAL_VLLM_MODE=serve \
EXTERNAL_VLLM_POOL_DIR=/lustre/.../judge-pools/nano-grpo \
sbatch --nodes=22 --exclusive --gres=gpu:4 --time=12:00:00 \
  --export=ALL tools/external_gym_vllm/run_in_allocation.sh

Step 2: start or restart training against it:

EXTERNAL_VLLM_POOL_DIR=/lustre/.../judge-pools/nano-grpo \
EXTERNAL_VLLM_POOL_JOB=<pool-job-id> \
COMMAND="... __SAFETY_BASE_URL__ ..." RAY_SUB=/path/ray.sub \
sbatch --dependency=after:<pool-job-id>+15 --nodes=68 ... \
  --export=ALL tools/external_gym_vllm/attach_and_run.sh

So a warm run is step 2 only? and in that case the --dependency is already satisfied and can be dropped (harmless either way); it only earns its keep on the first launch, where it stops the training job from holding 68 nodes idle while the judges load. Please confirm that's the intent.

A few questions and suggestions:

1. Isolation between pool jobs looks right. The registry file lives under the per-job log dir and the group ID carries the job ID (inline-<pool>-<SLURM_JOB_ID>), and nodes are exclusive, so replicas from one pool job can't register into another's pool. Good.

One gap at the layer this PR adds: EXTERNAL_VLLM_POOL_DIR has no ownership. Two serve jobs pointed at the same directory will overwrite each other's job_id/pools.env/<pool>_url, and whichever exits first runs rm -f "${POOL_DIR}/READY" and withdraws the other job's readiness: attaching jobs then route to whoever wrote last. Could we take an O_EXCL lock file holding the job ID at publish time and refuse if a live job owns the dir? The attach side already validates job_id; this makes the serve side symmetric.

Relatedly, nothing records which training jobs are attached, so there's no safe way to decide whether a pool can be cancelled, and a second attacher silently halves the first one's judge throughput. Having attachers touch attached/<job-id> in the pool dir (removed on exit) and logging the set from the serve loop would be enough to make this operable.

Also minor: the default group ID is hardcoded inline-... even in serve mode, which is confusing when grepping serve-job logs. Worth making mode-aware.

2. READY is asserted stale across a replica relaunch. The readiness gate (registry_count_ready == replicas, then the end-to-end /models probe) runs exactly once, before publishing. The serve supervision loop afterwards only
checks whether PIDs are alive, so when a replica dies and is relaunched, READY stays on disk for the several minutes the replacement spends loading weights. Multi-replica pools take a capacity dip; a single-replica pool is a full outage with READY still asserted, so a job attaching in that window goes straight into Gym's 503 wait and a job already running sees failures.

Smallest fix reusing what's there: in the relaunch path, rm -f READY, re-run the existing readiness check, then rewrite it.

Alternatively the load balancer already publishes the signal but note it has to be compared against the replica count, since status: "ok" is just healthy_count > 0 and would call a 1-of-2 pool healthy:

https://github.com/NVIDIA-NeMo/RL/blob/main/tools/external_gym_vllm/vllm_pool_lb.py#L281-L290

The route is /health at the root (the catch-all proxy handles everything else), so it's http://<lb-ip>:<port>/health rather than under /v1. Polling it also catches a failure mode PID-watching misses entirely: a replica whose process is alive but wedged.

3. Pool-job death. Two things here.

No heartbeat, so READY can go permanently stale. The cleanup trap writes STOPPED on normal exit and SIGTERM, but not on SIGKILL or loss of node 0, and READY then sits there forever. attach_and_run.sh's squeue check catches a job that's gone but not a wrapper that died inside a job still holding nodes.
One touch "${POOL_DIR}/heartbeat" per poll iteration plus a staleness check on the reader side closes it.

max_restarts has no decay. It's per-step (step_restarts[replica:${index}]), so this needs the same replica index flapping but a 12-hour pool job where one replica dies every couple of hours still gives up at restart 6 despite never
having crash-looped. lb_watchdog.sh already handles this correctly by only counting failures within 5s of start and resetting otherwise:

https://github.com/NVIDIA-NeMo/RL/blob/main/tools/external_gym_vllm/lb_watchdog.sh#L52-L60

Could the serve loop mirror that and reset a step's counter once it's been up for N minutes?

4. Inline mode's teardown guarantee is gone in serve mode. Inline check_service_steps killed ray.sub when a required judge exited, so a judge failure meant a dead training job. In serve mode the training job reads the URLs
once at start and never looks again, so a dead or degraded pool means bad rewards rather than a crash which for RL is the worse outcome, since the run looks alive. Could attach_and_run.sh run a small side-watcher that fails the
training job when STOPPED appears or the heartbeat goes stale? At minimum this tradeoff should be called out in the README, which currently only notes that URLs change on a pool restart.

5. Bug in attach_and_run.sh's liveness check:

state=$(squeue -h -j "${EXTERNAL_VLLM_POOL_JOB}" -o %T 2>/dev/null | head -1)
if [[ -z "${state}" ]]; then
  echo "[FATAL] judge pool job ${EXTERNAL_VLLM_POOL_JOB} is gone" >&2

Under set -euo pipefail, a non-zero squeue propagates through the pipe and kills the assignment via errexit, so the [FATAL] branch never runs, you get a bare exit code instead. Since real squeue exits non-zero on an unknown job ID,
that's the actual "pool job is gone" path. Same code means one transient slurmctld failure kills a 68-node training job at startup with no explanation. Suggest capturing the status explicitly and only declaring the job gone after a few consecutive failures.

(The existing test passes because the stub squeue echoes an empty line and exits 0, worth making the stub exit non-zero so it reflects the real contract.)

6. Collapsing the launch and attach flows. I'd like one entry point, but I don't think it can live in attach_and_run.sh: that script runs inside the training allocation, so it can't create the pool's own exclusive 22-node job there, and sbatch-and-wait from inside would hold the training nodes idle through the pool's queue and model load, exactly what serve mode avoids. Could we instead add a submit-side wrapper that checks the pool dir, submits the pool job only if no live job owns it, and then submits the training job with the dependency?

Separately, the README's two attach paths should become one. Since attach_and_run.sh is a no-op wait when the pool is already READY, it should be the only documented path hand-substituting URLs is where someone pastes a
stale address from a previous pool job, and that path skips the job_id freshness check that would catch it.

7. Publish the pool's remaining time. Attaching a 6-hour training job to a pool with 40 minutes left is an easy and expensive mistake. Writing EndTime from scontrol show job into the pool dir and having the attach path compare it
against the training job's own time limit (warn, or refuse behind a flag) would prevent it.

8. A requeued pool job is indistinguishable from the original. Slurm keeps
SLURM_JOB_ID across requeue but the job gets new nodes, so the URLs change while job_id stays equal and that equality is the whole freshness check in attach_and_run.sh. Publishing a generation token (job_id plus SLURM_RESTART_COUNT) and comparing the full token would fix it, and matches how LOG_DIR already encodes the restart count.

9. Testing. The stub-srun approach exercising the real backend registry is the right call, and the relaunch, give-up and attach cases are well covered. The gap mirrors the design gap: nothing asserts what READY looks like during a
relaunch. If (2) is fixed, that's the test to add the stub already supports it via STUB_NO_REGISTER on the relaunched replica.

… attach

EXTERNAL_VLLM_MODE=serve runs the external vLLM pools as their own plain
Slurm job that outlives training jobs: replicas on its nodes, load balancers
on its first node. Training jobs attach to it with attach_and_run.sh, so a
training job can crash or be resubmitted without the judges reloading.
Inline mode is unchanged apart from launching its steps through the same
relaunchable helpers.

Pool directory (EXTERNAL_VLLM_POOL_DIR):
- owner: taken with O_EXCL at start; a second serve job on a directory
  owned by a live job fails, a dead owner's directory (or this job's own
  after a requeue) is taken over.
- generation (<job-id>-<restart-count>), job_id, log_dir, end_time.
- manifest.tsv: base URL, /health URL, expected backends, served model name
  and startup timeout per pool (plus <pool>_url and pools.env).
- READY: published once every load balancer counts every replica healthy,
  withdrawn while any pool is below full strength (a relaunch loading
  weights, or a wedged replica) and restored when it is whole again.
- heartbeat: rewritten every poll, also while the pools load.
- attached/<job-id>: training jobs currently attached, logged by the pool.
- STOPPED on exit, after READY is withdrawn.

A replica or load balancer that exits is relaunched on the same nodes; its
relaunch count resets after EXTERNAL_VLLM_RESTART_RESET_S of uptime, so only
a crash loop exhausts EXTERNAL_VLLM_MAX_RESTARTS. Default group ids are
mode-aware (serve-<pool>-<job>).

attach_and_run.sh waits for READY from the expected pool job with a fresh
heartbeat, resolves URL placeholders and the external-service readiness gate
from the manifest at job start, warns (or with
EXTERNAL_VLLM_ATTACH_REQUIRE_LIFETIME=1 refuses) when the pool ends before
the job, registers under attached/, and stops NeMo RL when the pool stops,
is replaced or requeued, or its heartbeat goes stale. A failed squeue is
only logged; the pool job counts as gone after EXTERNAL_VLLM_POOL_GONE_CHECKS
consecutive "finished or unknown" answers.

pool_config.sh adds submit_external_vllm_pool_job (reuses a live pool job
for the directory, else submits one) and submit_external_vllm_attached_job
(depends on the pool job only while it is not READY). pool_dir.sh holds the
helpers they share.

Signed-off-by: sniverty <[email protected]>
…it helpers

Run run_in_allocation.sh (serve), attach_and_run.sh and the pool_config.sh
submit helpers end to end against stub srun/scontrol/getent/curl/squeue/
sbatch; the stub replicas register in the real backend registry. The stub
squeue fails like the real one (non-zero exit), and the stub curl answers
/health with a per-port healthy-backend count so tests can degrade a pool.

Covers publishing, relaunch, READY withdrawn while degraded and restored,
READY waiting for the load balancers, ownership refusal and takeover
(finished, purged and requeued owners), the relaunch-count reset, the
readiness gate built from the manifest, stale READY rejection, transient
squeue failures, a purged pool job, stopping training on STOPPED, a
generation change or a stale heartbeat, the lifetime check, and the submit
helpers. The routing test now checks the per-mode srun selectors.

Signed-off-by: sniverty <[email protected]>
Submission through the pool_config.sh helpers and attach_and_run.sh as the one attach path, the pool directory, failure handling (including that an attached job stops when its pool does, as inline mode stops NeMo RL when a judge exits), and the new settings.

Signed-off-by: sniverty <[email protected]>
@snivertynv
snivertynv force-pushed the sniverty/external-vllm-persistent-pool branch from b551c62 to 16d060d Compare October 14, 2026 09:49
@snivertynv

Copy link
Copy Markdown
Contributor Author

@saumishr
Thanks for the thorough review. I rebased onto #4381 (the early-Ray commit is gone; #4381 covers it) and reworked serve/attach to reuse its readiness gate.

@yfw , this borrows the manifest idea from your standalone-services POC (health URL + expected backends + restart count), and keeps replica relaunch and deferred attach. Happy to converge further on one design.

  • Ownership: owner is taken with O_EXCL (a live owner is refused, a dead owner or our own requeue is taken over); attachers register in attached/, which the pool logs; group IDs are serve-… in serve mode.

  • READY during relaunch: READY is published only when every LB's /health reports healthy backends ≥ replicas, and is withdrawn and restored as that changes, which also covers wedged replicas.

  • Heartbeat; restart decay: a heartbeat every poll; the relaunch count resets after EXTERNAL_VLLM_RESTART_RESET_S (30 min) of uptime.

  • Teardown guarantee: attach_and_run.sh now runs ray.sub under a watcher and stops it on STOPPED, a generation change, or a stale heartbeat. The README calls out the trade-off.

  • The squeue bug: fixed. Failed queries are only logged; "gone" needs 3 consecutive finished-or-unknown answers. The stub squeue now exits non-zero like the real one.

  • One entry point: the two pool_config.sh helpers; the README documents only the attach_and_run.sh path.

  • Pool lifetime: end_time is published; attach warns, or refuses with EXTERNAL_VLLM_ATTACH_REQUIRE_LIFETIME=1.

  • Requeue: the generation is -, and attached jobs stop if it changes.

  • Tests: cover READY while degraded, plus all of the above.

On the workflow question: yes a warm run is step 2 only, and the dependency matters only on a cold start. The submit_external_vllm_attached_job now adds it only while the pool isn't READY. A 10-node serve-plus-attach run on our cluster is queued and I'll post results once done.

@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test 16d060d

snivertynv and others added 3 commits October 15, 2026 03:29
…under the shared root

run_in_allocation.sh refuses a tools directory outside EXTERNAL_VLLM_SHARED_ROOT (replicas mount it), and the stub environment pointed it at the repository checkout, so every serve-mode test exited before publishing READY. Copy tools/external_gym_vllm into tmp_path, as the stub environment's shared root, and let _attach_env callers override its defaults (COMMAND).

Signed-off-by: sniverty <[email protected]>
external_vllm_job_state captured squeue's stderr in a mktemp file, which fails where /tmp is not writable. Capture stdout and stderr together instead; on success squeue prints only the state.

Signed-off-by: sniverty <[email protected]>
@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test da99795

@snivertynv snivertynv added CI:L1 Run doctests, unit tests, and functional tests and removed CI:L0 Run doctests and unit tests labels Oct 15, 2026

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

Thanks for working through @saumishr's review so thoroughly. Tying READY to the load balancers' own counts, the heartbeat and attach watcher, and resolving URLs when the job starts make this a solid base. I checked each of the 9 points at da99795, and all of them are in. Inline mode looks unchanged: under the test stubs, a clean run and a replica dying mid-run behave the same before and after this PR, and the only difference is --open-mode=append, which does nothing on fresh log files.

A few minor nits in the inline comments.

On converging with my standalone-services POC (11746b3b): this PR is the better base. It resolves URLs when the job starts, relaunches dead replicas, keeps READY in step with the load balancers, and stops attached jobs when the pool goes away.

Generated by Claude Code

Comment thread tools/external_gym_vllm/pool_dir.sh Resolved
external_vllm_job_state merges squeue's stderr into its output, and squeue can print a non-fatal error there (e.g. a slurm.conf warning on every call) and still succeed. The first line was then taken as the job's state, so a running pool job looked gone: a second pool job could be submitted and take over the live pool's directory, and attached jobs would stop. Keep only the line that is a bare state name.

Tests: the stub squeue can print a warning on stderr first, and the serve-side ownership check is covered with a warning and with a failing squeue.
Signed-off-by: sniverty <[email protected]>
…unch

The replica body started vLLM with > LOG_FILE, which truncated vllm_<i>.log. In serve mode a dead replica is relaunched within one poll with the same log file, so the traceback explaining the crash was erased before anyone saw it. Append instead; inline mode starts every job with a fresh log directory and is unaffected.

Signed-off-by: sniverty <[email protected]>
@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test 92c3a00

@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test 0c8f44b

@yfw
yfw enabled auto-merge (squash) October 16, 2026 21:27
@yfw
yfw merged commit ed40ca3 into main Oct 16, 2026
259 of 264 checks passed
@yfw
yfw deleted the sniverty/external-vllm-persistent-pool branch October 16, 2026 21:48
alexandery-nvidia added a commit that referenced this pull request Oct 16, 2026
…failures-and-redispatch

main gained #4745, #4542 and #4596 since the previous merge, which put this head
eleven commits behind it; the merge keeps the head within main's up-to-date rule
for CI. No conflicts.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants