Skip to content

feat(local_vllm_model): serve external vLLM endpoints without Ray - #6039

Merged
ananthsub merged 2 commits into
mainfrom
ananthsub/local-vllm-external-no-ray
Nov 13, 2026
Merged

ananthsub merged 2 commits into
mainfrom
ananthsub/local-vllm-external-no-ray

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

local_vllm_model declares ray_enabled = True. Gym reads that flag from the entrypoint's source before any config exists, so a local_vllm_model server whose base_url points at an external vLLM pool still pays for Ray, though it launches nothing:

  • The supervisor starts or joins Ray for it (_ray_server_names → initialize_ray()). In an evaluation run with no other Ray server, this server alone starts a private cluster. It also makes the run fail when nemo-gym[ray] is not installed where gym runs.
  • The server process calls ray.init(address=...) in run_webserver.
  • The process imports Ray and vLLM at module level, which takes several seconds for vLLM.
  • app.py has no module-level app for uvicorn workers, so such a server cannot set num_workers > 1.

Production RL recipes do this for external judge pools: the NeMo RL launcher injects base_url at nl2bash_judge_model.responses_api_models.local_vllm_model.base_url, and launches vLLM locally instead when no pool URL is set.

This PR adds responses_api_models/local_vllm_model/external_app.py, a second entrypoint for the external case, and keeps the static source check unchanged.
It has two benefits: the server no longer starts or joins Ray, and it can run with num_workers > 1.
For a busy judge, spreading request forwarding across workers can matter more than skipping Ray.
The entrypoint:

  • It declares ray_enabled = False and imports neither Ray nor vLLM, so the supervisor launches it with RAY_ENABLE_AUTO_CONNECT=0 and starts no cluster on its account.
  • It requires a non-empty base_url, and rejects a list with a blank entry, such as [""].
  • It accepts every app.py key; vllm_serve_kwargs and vllm_serve_env_vars become optional. A config switches between a local launch and an external pool by changing entrypoint and base_url, so the launcher's local fallback keeps working.
  • It keeps the /get_inner_vllm_config route that local_vllm_model_proxy reads.
  • It supports num_workers > 1.

The shared config moves from app.py to server_config.py, so external_app.py can load it without importing Ray or vLLM. app.py re-exports it, so genrm_model and other existing imports are unchanged.

Options considered

  • Decide from the config (base_url set means no Ray): the supervisor would need a per-server-type rule, and the server would have to repeat it in _connect_server_to_ray. That splits one decision across two places, and the Ray opt-out audit would no longer describe actual behavior.
  • Connect lazily, only when launching vLLM: while the class declares True, the supervisor still starts Ray, so this saves only the connect. Declaring False would launch the local path without a guaranteed cluster.
  • Point recipes at vllm_model: this works for evaluation-only external judges, but it drops the launcher's local fallback and still needs a launcher change.

Issue

No issue. This follows the Ray opt-out work in #4300, #4301, #4307, #4350 and #4470, which made Ray depend on each entrypoint's declaration.

Compatibility

Existing configs behave exactly as before; app.py still accepts base_url and skips the local launch. To opt in, a config sets entrypoint: external_app.py. For the NeMo RL launchers that inject base_url for this judge (examples/nemo_gym/nemotron-3.5-lightning/lightning35_launch.sh and examples/nemo_gym/nemotron-3-ultra/ultra_launch.sh), that is one more override inside the branch that sets base_url, so the local-launch fallback keeps using app.py:

++env.nemo_gym.nl2bash_judge_model.responses_api_models.local_vllm_model.entrypoint=external_app.py

Validation

Run locally on a workstation, in a worktree venv with the dev extra plus Ray 2.58.0:

PYTHONPATH=. pytest -n 8 tests/unit_tests/server_runtime/ tests/unit_tests/cli/test_cli.py \
  responses_api_models/local_vllm_model/tests/test_external_app.py responses_api_models/local_vllm_model_proxy/tests
pre-commit run --files <changed files>

The new tests check that:

  • running external_app.py in a subprocess loads neither ray nor vllm. The check first requires both to be installed, so an import behind try/except ImportError can't slip through. Adding import ray to the entrypoint, guarded or not, makes it fail;
  • the entrypoint's source declares ray_enabled = False, and the supervisor leaves it out of the Ray server list while still listing an app.py server in the same run;
  • the server does not join Ray even when the run has a cluster address;
  • the config rejects a missing or empty base_url, including a list with a blank entry, and accepts an unchanged local-launch block;
  • /get_inner_vllm_config reports the external endpoint and is a non-generating route.

The local_vllm_model server tests, including the existing ones that import vLLM, also pass in the server's own venv (Ray 2.58.0, vLLM 0.29.0), which gym env start built for the smoke run below:

PYTHONPATH=. responses_api_models/local_vllm_model/.venv/bin/python -m pytest responses_api_models/local_vllm_model/tests/

Measured on the workstation, for scale: starting a private Ray cluster took about 2.3 s and shutting it down about 1.1 s; ray.init against a running local head took 0.05 to 0.27 s; importing vLLM took 4 to 8 s.

Rollout evidence

Smoke run on a workstation (local, not Slurm), 2026-11-11. A vLLM 0.29.0 server on one RTX 6000 Ada served Qwen/Qwen3-4B-Instruct-2507 as judge-model and stood in for the external pool. gym env start started equivalence_llm_judge, the simple agent, a vllm_model policy and a judge_model instance of local_vllm_model with entrypoint: external_app.py, base_url pointing at that server and num_workers: 2. gym eval run --no-serve then collected 4 rows of resources_servers/equivalence_llm_judge/data/example.jsonl.

  • All 5 servers came up. The supervisor log has no Ray start or connect line.
  • The judge's parent process and both uvicorn workers run with RAY_ENABLE_AUTO_CONNECT=0, and none of them has a Ray or vLLM shared library mapped.
  • No Ray process started for this run.
  • Every row got a judge verdict from judge_model: 3 [[A=B]] and 1 [[A!=B]], mean reward 0.75, no failed rows, no judgement parsing issues.
  • GET /get_inner_vllm_config on the judge returned the external base_url, the dummy API key and judge-model.

The local_vllm_model venv still installs vLLM and Ray, because a venv belongs to the server directory and not the entrypoint. Deployments that build venvs on the fly still pay that install once.

Docs

fern/versions/latest/pages/model-server/local-vllm.mdx gains a section on serving an external endpoint without Ray.
It says that external_app.py supports num_workers > 1, and that a launcher which injects base_url should set entrypoint=external_app.py in the same place, keeping app.py on its local-launch path.

@copy-pr-bot

copy-pr-bot Bot commented Nov 12, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

@ananthsub

Copy link
Copy Markdown
Contributor Author

Adopting external_app.py in NeMo RL

Nothing changes for existing configs until they opt in, so NeMo RL can adopt this in a follow-up PR after this one merges. The order matters: if a config selects external_app.py before NeMo RL's Gym pin includes this PR, Gym fails at startup because the entrypoint doesn't exist.

Changes needed in NVIDIA-NeMo/RL:

  1. Bump the Gym submodule. 3rdparty/Gym-workspace/Gym must point at a Gym main commit that includes this PR.

  2. Select the entrypoint where the launchers inject base_url. examples/nemo_gym/nemotron-3.5-lightning/lightning35_launch.sh and examples/nemo_gym/nemotron-3-ultra/ultra_launch.sh set base_url for nl2bash_judge_model only when a pool URL exists. Otherwise they let Gym launch vLLM locally. Add the entrypoint override inside the branch that sets base_url, so the local-launch branch keeps app.py:

    ++env.nemo_gym.nl2bash_judge_model.responses_api_models.local_vllm_model.entrypoint=external_app.py
  3. Set the entrypoint in YAML where the judge always uses a pool. In examples/nemo_gym/nemotron-3.5-super/rlvr_v43.yaml, nl2bash_judge_model and safety_judge_model always take their base_url from a pool placeholder, so they can set entrypoint: external_app.py directly. Their vllm_serve_kwargs and vllm_serve_env_vars blocks become optional there and can be removed.

What needs no change:

  • Checkpoint resume. nemo_rl/algorithms/rollout_checkpointing/manifest.py already leaves env.**.entrypoint and these base_url keys out of the resume identity, so switching the entrypoint does not block resuming a run.
  • NeMo RL code. Nothing under nemo_rl/ assumes app.py.
  • Prefetch configs. The prefetch_*_all_envs.yaml configs only build venvs. A venv belongs to the server directory, not the entrypoint, so they work unchanged.
  • Configs that leave the choice to the launcher. Recipes that leave base_url empty for the launcher to fill keep entrypoint: app.py in YAML, because the launcher override above makes the switch.

genrm_model has the same issue for the GenRM pool (lightning35_launch.sh, ultra_launch.sh, rlvr_v43.yaml). Its non-Ray entrypoint is a separate Gym PR, so those lines need a second, equally small change once that PR merges.

@ananthsub
ananthsub requested review from oyilmaz-nvidia and snivertynv and removed request for adil-a and pthombre November 12, 2026 09:08
@linear-code linear-code Bot mentioned this pull request Nov 12, 2026
8 of 26 tasks
@ananthsub
ananthsub force-pushed the ananthsub/local-vllm-external-no-ray branch 2 times, most recently from 24ef1fb to 872ad2c Compare November 12, 2026 22:57
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 13, 2026
@snivertynv

Copy link
Copy Markdown
Contributor

Looks good to me. Reading ray_enabled from the entrypoint's class body is the right way to opt out of Ray, and declaring it in external_app.py rather than inheriting it is what makes the supervisor see it.

Verified locally on the PR head with a fresh root venv (dev + ray extras): tests/unit_tests/server_runtime/test_ray_opt_out.py and local_vllm_model/tests/test_external_app.py pass, except test_entrypoint_imports_neither_ray_nor_vllm. That one fails only because vLLM isn't installed in the root venv, which the test requires on purpose, so it needs the server venv.

Notes, none blocking:

  1. Adoption. Recipes that inject base_url into a local_vllm_model block but keep entrypoint: app.py see no change. Getting the benefit needs a follow-up in those recipes that also overrides entrypoint=external_app.py where the pool URL is injected. Could the docs section say so?
  2. Multiple workers. app.py only starts through __main__, so it serves a single worker. external_app.py adds the module-level app that num_workers > 1 needs. For a busy judge, the proxy's CPU use can matter more than skipping Ray, so this may be worth calling out in the PR description and docs as a second benefit.
  3. Nit: _require_base_url rejects "" and [] but accepts [""]. Optional: also reject empty entries.

snivertynv
snivertynv previously approved these changes Nov 13, 2026
@ananthsub

ananthsub commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

@snivertynv Thanks for the review. All three notes are addressed in 4ac1bf4.

  1. Adoption. The docs section now says a config only changes when it selects external_app.py. It shows a launcher setting base_url and entrypoint=external_app.py together, and keeping app.py on its local-launch path.
  2. Multiple workers. The docs section and the PR summary now name num_workers > 1 as a second benefit, since app.py serves a single worker.
  3. Blank entries. _require_base_url now also rejects a list with a blank entry, such as [""], with the same error message. The test covers "", " ", [], [""] and a list with one blank URL. The old check accepts " ", [""] and the blank URL.

The import test stays as it is. It needs the server venv, like test_app.py in the same directory, which imports vLLM at module level.

local_vllm_model declares ray_enabled = True, and Gym reads that flag from
the entrypoint's source before any config exists. So a server whose
base_url points at an external vLLM pool still makes Gym start or join
Ray, joins Ray itself, and imports Ray and vLLM, even though it launches
nothing.

Add external_app.py, a sibling entrypoint for that case:

- It declares ray_enabled = False and imports neither Ray nor vLLM.
- It requires a non-empty base_url.
- It accepts every app.py config key, with the vLLM launch settings
  optional, so a config switches between a local launch and an external
  pool by changing entrypoint and base_url.
- It keeps the /get_inner_vllm_config route that the local vLLM proxy
  reads.
- It supports num_workers > 1.

The shared config moves to server_config.py, so external_app.py can load
it without app.py. app.py re-exports it, so existing imports keep
working.

The test that external_app.py loads neither Ray nor vLLM first requires
both to be installed. Without them, an entrypoint that imports Ray behind
a try/except ImportError would pass.

Signed-off-by: Ananth Subramaniam <[email protected]>
- Reject a base_url list with a blank entry, such as [""], which a launcher
  produces when it interpolates an unset variable.
- Document that external_app.py supports num_workers > 1.
- Document that a launcher which injects base_url should also set
  entrypoint=external_app.py there, keeping app.py for the local launch.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/local-vllm-external-no-ray branch from 4ac1bf4 to 7fb129b Compare November 13, 2026 14:40
@ananthsub
ananthsub merged commit 2d5d8f7 into main Nov 13, 2026
60 checks passed
@ananthsub
ananthsub deleted the ananthsub/local-vllm-external-no-ray branch November 13, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants