How a NeMo-Gym model call runs through Dynamo, compared with the native vLLM server

NVIDIA-NeMo/RL #4979 (stacked on #4905), with NVIDIA-NeMo/Gym#4817. Permalinks pin head 0b7d378.

Nine pages on this stack (#4905, #4979 and #5115), one question each. This one: how a NeMo-Gym call runs through Dynamo vs the native vLLM server.

Before
With policy.generation.dynamo: true, any NeMo-Gym run was refused at startup (base nemo_gym.py). Gym talked only to each vLLM shard's own OpenAI server.
This PR
Gym calls one Dynamo frontend URL in a new "Dynamo dialect". Dynamo's own renderer applies the chat template, and the same vLLM workers run a copy of the native capture steps on the token ids.
Status
Open: changes requested, not merged. Rewards match the native server on the author's small runs, but the published review found these gaps, none fixed yet: the prefix splice counts fewer turn-end tokens than native (C16, below); forest training fails (C26); score centering fails (C29); Dynamo's renderer can build different prompts than vLLM (C28); images can be processed twice (C30). The proposed fix is one shared copy of the steps, run by NeMo RL's own chat engine inside the Dynamo frontend (C27, picture).
Background. Dynamo puts one HTTP frontend in front of all vLLM engines and sends each request to the engine that already holds most of its prompt in cache. NeMo-Gym needs more than text back: the exact prompt and generated token ids and their log-probs, so training sees the same tokens the model produced. A multi-turn call also sends back the earlier turns' exact tokens (the echoed prefix), which the server splices in place of its own re-rendered history. Dotted words have a short explanation: hover or tap them.

Natively, Gym gets one URL per vLLM shard and calls that shard's /v1/chat/completions. With Dynamo, client_base_urls hands Gym the frontend URL instead, and _apply_dynamo_dialect turns on Gym's dialect. The frontend renders and tokenizes the chat, so the engine sees only token ids plus Gym's annotations. _generate_gym then redoes, on tokens, what the native chat endpoint does on messages.

One Gym call, two paths

Native vLLM server (dynamo: false) Dynamo frontend (dynamo: true) 1 · Gym's vllm_model POSTs to one shard shard_k/v1/chat/completions {messages, tools, last assistant msg + prompt/generation token ids} 1 · Gym's vllm_model (dynamo_frontend) POSTs frontend/v1/chat/completions {messages, tools, nvext.annotations: ["nemo_gym:rollout", "ng_prefix:[ids]" or "ng_capture:{…}"]} 2 · The shard's own server renders the chat template(all messages) → prompt ids template(history only) → history ids preprocess_chat · vllm_worker_async.py:1416 2 · Frontend (Rust) renders, parses, routes template(all messages) → token_ids KV router picks the engine; no history render engine: annotation → _generate_gym · :400 3 · Splice in the echoed prefix boundary = turn-end count in history ids turn-end ids = tokenizer EOS + generation-config EOS + stop_token_ids splice_prefix_tokens · :1432-1441 3 · Splice in the echoed prefix boundary = turn-end count in Gym's prefix itself turn-end ids = tokenizer EOS only ✗ fewer ids than native: a turn ending on another stop id (gpt-oss <|call|>) fails the call :559-564 ─── from here both paths run the same worker code ─── 4 · Same vLLM worker: on-policy sampling check, context clamp, AsyncLLM.generate, token capture temperature/top_p must match train or val profile · top_k = -1 · n = 1 · capture: begin_call → finish_call _begin_request_capture · vllm_worker_async.py:811 same call from the engine · native_engine.py:624 5 · Token fields on the response message message.generation_token_ids message.generation_log_probs (+ routed_experts) chat_generation_tokens · vllm/utils.py:711 5 · Same helpers, carried in nvext.engine_data {prompt_token_ids, completion_token_ids, completion_logprobs, routed_experts} → Gym lifts _gym_message → engine_data · :656-661 same code in both paths differs from native, review item C16 differs on purpose (who renders the chat)

Where they meet, and what still differs

The two paths join at the vLLM worker. On-policy sampling, the context clamp, generation, token capture and the token-field helpers are the same code. Everything before that differs, because the frontend renders the chat and the engine never sees messages.

PieceNative vs Dynamo
Sampling, generation, token capture, log-probs, routed expertssameThe same worker methods and helpers.
Which engine serves the calldiffersNative: Gym picks a shard. Dynamo: the frontend routes by cached prefix, and a capture session stays on one engine for up to session_affinity_ttl_secs (300 s).
Where the echoed prefix endsdiffersNative renders the history and counts turn-end tokens in it. Dynamo counts them in Gym's own prefix, and counts only the tokenizer EOS.

🟠 review comment C16: native_engine.py:559

Default chat-template kwargsdiffersNative merges server defaults under each request's kwargs. Dynamo has Gym send them, so a key a Gym YAML also sets loses to the default (documented in the guide).
Stop stringsdiffersDynamo refuses more than 4 stop strings or stop_token_ids (HTTP 500).
Why keep both. The native server needs no extra services and renders the history itself. Dynamo adds prefix-aware routing across the whole fleet behind one URL, which is the point of running it, but it needs etcd, NATS and the frontend, and it rejects a few settings at startup (the generation router, top_logprobs > 0, extra_body.bad_words). The PR shows matching rewards and gen_kl_error on small 2-GPU runs. No speed comparison is posted yet, and the review asks for one swe1 run at head, Dynamo vs native.