Skip to content

fix(orchestration): spread Ray Serve gateway requests over every vLLM instance - #4905

Merged
wprazuch merged 2 commits into
mainfrom
wprazuch/ray-serve-spread-replicas
Oct 22, 2026
Merged

wprazuch merged 2 commits into
mainfrom
wprazuch/ray-serve-spread-replicas

Conversation

@wprazuch

Copy link
Copy Markdown
Contributor

Problem

With use_ray_serve on a multi-node job, the Ray Serve proxy on the head node prefers the replica on its own node. It only routes elsewhere once that replica is full. A gateway replica never fills, because max_ongoing_requests is 65536. So every request lands on the head-node instance and the other instances sit idle.

Fix

Set RAY_SERVE_PROXY_PREFER_LOCAL_NODE_ROUTING=0:

  • exported in the multi-node ray symmetric-run wrapper, before Ray starts;
  • defaulted in ray_serve_gateway.main() for the single-node path.

Test

  • New unit test test_build_vllm_ray_serve_command_multi_node_spreads_requests_over_all_replicas. It fails without the fix.
  • tests/unit_tests/test_slurm_script.py: 243 passed. Pre-commit --all-files passes.
  • End-to-end on a 4-node Slurm job (MMLU-ProX, TP4, 4 instances, use_ray_serve: true): all 4 replicas served traffic. Each engine reported Running: 100 reqs, Waiting: 0, including the head-node replica.

… instance

Ray Serve's proxy prefers the replica on its own node until that replica is
full, and a gateway replica never fills (max_ongoing_requests 65536). With a
replica on the head node, every request went to it and the other instances
sat idle. Turn the preference off before Ray starts, as is already done for
the queue-length deadline.

Signed-off-by: Wojciech Prazuch <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:orchestration Job submission, deployment, services, and lifecycle management bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer labels Oct 22, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 22, 2026 08:09
@wprazuch

Copy link
Copy Markdown
Contributor Author

/ok to test 704c134

@wprazuch
wprazuch added this pull request to the merge queue Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/39756152358

Merged via the queue into main with commit 504f332 Oct 22, 2026
50 of 56 checks passed
@wprazuch
wprazuch deleted the wprazuch/ray-serve-spread-replicas branch October 22, 2026 09:55
jthomson04 added a commit to jthomson04/Gym that referenced this pull request Oct 25, 2026
… lift R3 routes

From the NeMo RL NVIDIA-NeMo#4905 review:
- dynamo_frontend now rejects request_prompt_and_generation_token_ids: Gym
  sends return_token_ids for it, which the frontend refuses with a 400.
- It also rejects reasoning_field: both when reasoning is echoed: the frontend
  reads `reasoning` as an alias of `reasoning_content` and 400s a message
  that carries both.
- _lift_dynamo_engine_data copies routed_experts onto the message when the
  engine sends it (router replay on), as the native endpoint attaches it.
- Comments name NeMo RL's engine, not Dynamo, as the engine_data producer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
jthomson04 added a commit to jthomson04/Gym that referenced this pull request Oct 26, 2026
… lift R3 routes

From the NeMo RL NVIDIA-NeMo#4905 review:
- dynamo_frontend now rejects request_prompt_and_generation_token_ids: Gym
  sends return_token_ids for it, which the frontend refuses with a 400.
- It also rejects reasoning_field: both when reasoning is echoed: the frontend
  reads `reasoning` as an alias of `reasoning_content` and 400s a message
  that carries both.
- _lift_dynamo_engine_data copies routed_experts onto the message when the
  engine sends it (router replay on), as the native endpoint attaches it.
- Comments name NeMo RL's engine, not Dynamo, as the engine_data producer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
jthomson04 added a commit to jthomson04/Gym that referenced this pull request Oct 30, 2026
… lift R3 routes

From the NeMo RL NVIDIA-NeMo#4905 review:
- dynamo_frontend now rejects request_prompt_and_generation_token_ids: Gym
  sends return_token_ids for it, which the frontend refuses with a 400.
- It also rejects reasoning_field: both when reasoning is echoed: the frontend
  reads `reasoning` as an alias of `reasoning_content` and 400s a message
  that carries both.
- _lift_dynamo_engine_data copies routed_experts onto the message when the
  engine sends it (router replay on), as the native endpoint attaches it.
- Comments name NeMo RL's engine, not Dynamo, as the engine_data producer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
jthomson04 added a commit to jthomson04/Gym that referenced this pull request Nov 13, 2026
… lift R3 routes

From the NeMo RL NVIDIA-NeMo#4905 review:
- dynamo_frontend now rejects request_prompt_and_generation_token_ids: Gym
  sends return_token_ids for it, which the frontend refuses with a 400.
- It also rejects reasoning_field: both when reasoning is echoed: the frontend
  reads `reasoning` as an alias of `reasoning_content` and 400s a message
  that carries both.
- _lift_dynamo_engine_data copies routed_experts onto the message when the
  engine sends it (router replay on), as the native endpoint attaches it.
- Comments name NeMo RL's engine, not Dynamo, as the engine_data producer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
tayunvidia pushed a commit to tayunvidia/Gym that referenced this pull request Nov 13, 2026
…andler (NVIDIA-NeMo#4817)

* feat(vllm_model): Dynamo frontend dialect and dynamo_worker capture handler

Let the vLLM model server talk straight to an ai-dynamo 1.5.1 frontend,
replacing NeMo RL's Dynamo token wrapper proxy. The frontend rejects
unknown top-level request fields and returns token data only under
nvext.engine_data, when nvext.extra_fields asks for it.

- VLLMModelConfig.dynamo_frontend: strip echoed per-message token fields
  from requests and mark every request with the "nemo_gym:rollout"
  annotation in nvext.annotations, so the engine can tell Gym rollout
  traffic from the training framework's own requests. With
  return_token_id_information, request engine_data and copy
  nvext.engine_data.{prompt_token_ids, completion_token_ids,
  completion_logprobs} onto the message token fields, failing clearly when
  engine data is missing or the log probability count mismatches.
- token_id_capture.external_staging_backend "dynamo_worker": the
  admission rides in nvext.annotations as "ng_capture:<admission JSON>",
  no top-level ng_capture or required_prefix_token_ids and no logprobs are
  sent, and the acknowledgement is lifted from
  nvext.engine_data.ng_commit_coords.
- ExternalCaptureHandler.request_headers(), threaded through
  NeMoGymAsyncOpenAI.create_chat_completion(extra_headers=...) on top of
  default_headers. The Dynamo handler sets x-dynamo-session-id to the
  rollout id, since Dynamo 1.5.1 router affinity is header-only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>

* feat(vllm_model): send the echoed prefix to Dynamo engines without capture

vLLM's NeMo RL server splices the last echoed assistant turn's
prompt_token_ids + generation_token_ids into each multi-turn prompt
(required_prefix_token_ids). The Dynamo dialect strips those message
fields because the frontend rejects them, so without capture a turn-2
prompt was a fresh re-render and could diverge from the tokens the model
generated (e.g. Qwen3 dropping the empty think block).

Without an external capture handler, carry that prefix in
nvext.annotations as "ng_prefix:<JSON list>", for the engine to splice.
Capture calls still resolve their prefix from staging.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>

* fix(vllm_model): reject Dynamo dialect settings the frontend refuses; lift R3 routes

From the NeMo RL NVIDIA-NeMo#4905 review:
- dynamo_frontend now rejects request_prompt_and_generation_token_ids: Gym
  sends return_token_ids for it, which the frontend refuses with a 400.
- It also rejects reasoning_field: both when reasoning is echoed: the frontend
  reads `reasoning` as an alias of `reasoning_content` and 400s a message
  that carries both.
- _lift_dynamo_engine_data copies routed_experts onto the message when the
  engine sends it (router replay on), as the native endpoint attaches it.
- Comments name NeMo RL's engine, not Dynamo, as the engine_data producer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>

* fix(vllm_model): check the dynamo_worker pairing only on dialect servers

The token-capture block is global, so a judge such as local_vllm_model
sees external_staging_backend=dynamo_worker too and failed at startup.
Only a server that sets dynamo_frontend=true must pair with dynamo_worker;
the error now names it. A judge never gets a capture context, so its
handler stays idle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>

* feat(vllm_model): carry NeMo RL's Dynamo call extras and results as one object each

With dynamo_frontend on, NeMo RL's request fields and call results now
cross Dynamo's frontend as one JSON object per direction, under the
native vLLM server's field names. The frontend accepts only OpenAI fields
plus nvext, so both objects ride in nvext.

Request: every request carries one `nemo_rl:gym:<JSON object>` entry in
nvext.annotations, holding only the fields that apply: `ng_capture` (the
admission, as the native top-level field), `required_prefix_token_ids`
(no capture, from the last echoed turn's tokens) and `ng_measure`
(context measurement). It replaces the `nemo_gym:rollout`, `ng_capture:`
and `ng_prefix:` annotations and the nvext.extra_fields engine_data
request. The x-dynamo-session-id header is unchanged.

Response: the engine's nvext.nemo_rl result is lifted to where the native
server puts each field. Token fields and routed_experts go onto the
message, and ng_commit_coords goes where the capture handler reads it.
_DYNAMO_ENGINE_DATA_FIELDS and the completion_* renames are gone.

/context/measure: the frontend has no /tokenize, so the dialect measures
with a chat call marked ng_measure and reads prompt_token_count and
ng_context_measured from nvext.nemo_rl, with the same reply validation.
The route exists only under parent_resolution: source_history, which now
accepts external_staging_backend: dynamo_worker as well as vllm_worker.

DYNAMO_GYM_EXTRAS_ANNOTATION_PREFIX replaces
DYNAMO_CAPTURE_ANNOTATION_PREFIX, DYNAMO_GYM_REQUEST_ANNOTATION and
DYNAMO_PREFIX_ANNOTATION_PREFIX.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>

* fix(vllm_model): ask for the sampled tokens' logprobs on a Dynamo capture call

NeMo RL's engine behind Dynamo now generates what the request asks for, as
its vLLM worker does, so a captured call must ask for the sampled tokens'
log probabilities that the worker stages, as the vLLM and Megatron capture
handlers do. Score centering's top_logprobs is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
(cherry picked from commit 4c84f17)
Signed-off-by: jthomson04 <[email protected]>

* fix(vllm_model): settle a context refusal acknowledged through Dynamo's frontend

Natively, the worker acknowledges a token-capture call it refused before
generation (a context-length 400) with the x-ng-capture-refused header, and
only then does source_history settle the call as refused. Dynamo's frontend
forwards only an error's status and message, so behind it the acknowledgement
never arrived and the refused call stayed pending.

NeMo RL's chat engine now ends the message with
dynamo_capture_refusal_suffix(model_call_id). With dynamo_frontend, the dialect
moves it back onto the header before the refusal is settled, so the harness
gets the engine's own message, as natively.

The worker-ack test runs each case through both dialects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>

* refactor(vllm_model): import the Dynamo dialect names from nemo_gym.models

Code outside nemo_gym/ imports a package's public names from its public
API. The model server and its tests took the dialect's helpers from
token_capture.external_capture directly, so export them from
nemo_gym.models, beside the other external-capture names, and import
them from there.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>

* fix(vllm_model): address the Dynamo dialect review

Two startup and request checks, from the review of the dialect:

- reasoning_field "both" is rejected with dynamo_frontend only when the
  server replays reasoning onto assistant messages. With
  uses_interleaved_reasoning off no message carries both keys, so that
  config now starts.
- A top-k capture call that also sets logprob_token_ids keeps its HTTP 400
  under Dynamo. The Dynamo capture handler sends the admission in the
  annotation, so the check no longer relies on a top-level ng_capture.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>

* docs(vllm_model): document the Dynamo frontend dialect

Adds a section to the vLLM guide for dynamo_frontend: what serves it (an
ai-dynamo frontend running NeMo RL's chat engine), the settings refused at
startup, how a call differs from one to a vLLM server, and the dynamo_worker
capture backend. The capture guide points to it.

Also corrects the comments that describe NeMo RL's side: its chat engine in
the frontend reads the annotation, resolves the capture prefix and measures,
and the session header keeps a rollout on one engine's KV cache.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>

* fix(vllm_model): reject conversation ids and skip the refit's prompt count under Dynamo

Two more cases for the Dynamo dialect, from review:

- forward_session_id_as_conversation_id adds a top-level conversation_params
  to every request, which the Dynamo frontend rejects. The combination is now
  refused at startup, like the other settings whose fields it rejects.
- The output-budget refit no longer asks the frontend for a /tokenize count,
  which it does not serve. NeMo RL's chat engine lowers a budget that does not
  fit and refuses only a prompt that fills the window, so no count would lead
  to a resend.

The vLLM guide's Dynamo section lists the new rejected setting, and words the
error-message and request-field notes for both ai-dynamo 1.5.1 and 1.7.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>

* test(vllm_model): cover every rejected setting, the empty annotation and the Dynamo capture handler

Three gaps in the Dynamo dialect's tests, from review:

- Each setting dynamo_frontend rejects now has its own case, so dropping
  one from the check fails a test.
- A call with no capture and no echoed turn is checked to carry the empty
  nemo_rl:gym: annotation, which NeMo RL's chat engine requires.
- DynamoWorkerCaptureHandler joins the shared capture-handler suite: the
  lifecycle cases and the factory selection.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>

---------

Signed-off-by: jthomson04 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 704c1343 Deployed Oct 22, 2026 by copy-pr-bot[bot] via release / finalize / notify #6585
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:orchestration Job submission, deployment, services, and lifecycle management bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants