Skip to content

feat(vllm_model): default template kwargs and Dynamo session affinity - #5161

Draft
jthomson04 wants to merge 5 commits into
NVIDIA-NeMo:mainfrom
jthomson04:jthomson04/dynamo-dialect-defaults-affinity
Draft

jthomson04 wants to merge 5 commits into
NVIDIA-NeMo:mainfrom
jthomson04:jthomson04/dynamo-dialect-defaults-affinity

Conversation

@jthomson04

Copy link
Copy Markdown
Contributor

Stacked on #4817. The branch includes #4817's three commits (through a5f936c). Review only the last commit, e6800bb (diff). This PR stays a draft until #4817 merges.

What

Two changes to vllm_model, both follow-ups to the Dynamo frontend dialect in #4817.

  1. default_chat_template_kwargs: a new config field with the lowest precedence. Every other source of chat_template_kwargs overrides a key set here: the configured chat_template_kwargs, the request's own kwargs (with forward_request_chat_template_kwargs), metadata.chat_template_kwargs, and extra_body. It is applied after the extra_body | body merge on the chat path and on the Responses-native path. In the completions-render path it is the base layer of the kwargs passed to apply_chat_template.
  2. Dynamo session affinity on every call. With dynamo_frontend: true, every chat call now sends x-dynamo-session-id, not only token-capture calls. The value uses the same key _resolve_client uses to pick an endpoint: the rollout id, else the Gym session. The key expression now lives in one _routing_session_id helper that both use. A capture call keeps the header the capture handler sets (its admission's rollout id).

Why

  1. NeMo RL passes its default template kwargs to Gym by merging them into the model server's chat_template_kwargs. Gym's config merge (nemo_gym/global_config.py) then lets them override an environment YAML's own chat_template_kwargs. Because a body that carries chat_template_kwargs wins the shallow extra_body | body merge, they also drop extra_body.chat_template_kwargs. Native vLLM does the opposite: request kwargs override the server's defaults. With this field, NeMo RL can supply its defaults without replacing the environment's kwargs.
  2. Without capture, the Dynamo engine splices a rollout's echoed prefix (the ng_prefix: annotation from feat(vllm_model): Dynamo frontend dialect and dynamo_worker capture handler #4817) only after the router has picked an engine. So the router can send a rollout's later turns to an engine that does not cache its earlier ones. Pinning each rollout to one engine keeps its turns together, as the capture path already does.

No issue. This continues the Dynamo parity work in #4817 and NVIDIA-NeMo/RL#4905. The NeMo RL side, which writes the defaults into the new field and re-pins Gym, follows in a separate RL PR.

Compatibility

Validation

  • pytest responses_api_models/vllm_model/tests/test_app.py: 402 passed. Run on Python 3.13.14, importing nemo_gym and responses_api_models from this branch.
  • The new and changed tests fail on feat(vllm_model): Dynamo frontend dialect and dynamo_worker capture handler #4817's app.py, except the capture case, which already sent the header:
    • test_default_chat_template_kwargs_have_lowest_precedence (new): the configured chat_template_kwargs and extra_body.chat_template_kwargs each win over a default, and a key that no other source sets keeps its default.
    • test_chat_template_kwargs_merged_with_metadata_override (extended): the same precedence on the completions-render path.
    • test_dynamo_frontend_dialect (extended): every case sends x-dynamo-session-id, keyed on the session without capture and on the admission's rollout id with capture.
  • pre-commit run --files <changed files>: passed.

Rollout evidence

Not run yet. This PR changes only the request body and headers the model server builds, and the unit tests above check both. The end-to-end check is a NeMo RL GRPO run through Dynamo (NVIDIA-NeMo/RL#4905), once NeMo RL is re-pinned to this commit. Results will be added here.

🤖 Generated with Claude Code

@copy-pr-bot

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

@jthomson04 jthomson04 added feature New capabilities, enhancements, or enablement work area:model Model servers, inference providers, and model adapters labels Oct 27, 2026
jthomson04 added a commit to jthomson04/RL that referenced this pull request Oct 27, 2026
…ery Gym rollout

Re-pins Gym to NVIDIA-NeMo/Gym#5161 (e6800bb), on top of Gym#4817, and uses it:

- The native server's default chat template kwargs now go to Gym's new
  `default_chat_template_kwargs`, which Gym applies under every other source
  of template kwargs. Writing them into `chat_template_kwargs` overrode a Gym
  YAML's own kwargs through Gym's config merge, and dropped its
  `extra_body.chat_template_kwargs`, the opposite of the native server.
- Gym sends `x-dynamo-session-id` on every Dynamo call, not only on token
  capture calls, so the frontend keeps each rollout on one engine; the engine
  splices the echoed prefix after routing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
@jthomson04
jthomson04 force-pushed the jthomson04/dynamo-dialect-defaults-affinity branch 3 times, most recently from aa808b7 to 05101d0 Compare October 29, 2026 21:54
jthomson04 and others added 5 commits October 30, 2026 15:47
…andler

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]>
…pture

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]>
… 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]>
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]>
Add default_chat_template_kwargs, applied under every other source of
chat_template_kwargs: the configured value, the request's own kwargs,
metadata.chat_template_kwargs and extra_body. It covers the chat,
completions-render and Responses-native paths. A training framework that
writes its defaults into chat_template_kwargs replaces an environment's
own kwargs, and because a body that carries chat_template_kwargs wins the
shallow extra_body merge, it also drops extra_body.chat_template_kwargs.

With dynamo_frontend, send x-dynamo-session-id on every chat call, not
only on token-capture calls. It is keyed like the client choice: the
rollout id, else the Gym session. The engine splices the echoed prefix
after the router has picked it, so a rollout's later turns could reach an
engine that does not cache its earlier ones. Capture calls keep their
admission's rollout id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
@jthomson04
jthomson04 force-pushed the jthomson04/dynamo-dialect-defaults-affinity branch from 05101d0 to b0fff97 Compare October 30, 2026 22:49

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:model Model servers, inference providers, and model adapters feature New capabilities, enhancements, or enablement work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant