Repository navigation
feat(vllm_model): Dynamo frontend dialect and dynamo_worker capture handler - #4817
Conversation
|
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. |
Temporarily pin the Gym submodule to the Gym#4817 head (5e2fb03), which adds the Dynamo frontend dialect, the dynamo_worker capture backend and the non-capture ng_prefix annotation, so the L1 Dynamo Gym runs exercise them. Re-pin to the merge commit before this lands. The bump picks up Gym's new `requests` dependency in uv.lock. Add a test tying the engine host's annotation strings to the constants Gym's dialect sends. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
Temporarily pin the Gym submodule to the Gym#4817 head (5e2fb03), which adds the Dynamo frontend dialect, the dynamo_worker capture backend and the non-capture ng_prefix annotation, so the L1 Dynamo Gym runs exercise them. Re-pin to the merge commit before this lands. The bump picks up Gym's new `requests` dependency in uv.lock. Add a test tying the engine host's annotation strings to the constants Gym's dialect sends. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
jthomson04
left a comment
There was a problem hiding this comment.
These come from the team review of NeMo-RL #4905, which pins Gym to this PR's head. Each fix lands in this repo, so they are filed here rather than there.
- (G1)
dynamo_frontendwithrequest_prompt_and_generation_token_idspasses validation, then every call gets a 400 forreturn_token_ids. - (G2) The default
reasoning_field: bothpasses validation, then every echoed reasoning turn gets400 duplicate field 'reasoning'. - (G3) Low: NeMo RL's default template kwargs override a Gym YAML's kwargs, the opposite of native vLLM.
- (G4) Nit: two comments name Dynamo as the source of the
engine_datakeys.
Follow-up, no action here: Gym sends x-dynamo-session-id only from the capture handler (external_capture.py#L450-L455), so multi-turn calls without token capture get no session affinity from Dynamo's router, although their echoed prefix is also spliced after routing. Unmeasured.
Generated by Claude Code
a369e28 to
a5f936c
Compare
a5f936c to
71c17f2
Compare
At review request, NeMo-Gym through the Dynamo frontend moves to a follow-up PR that waits on NVIDIA-NeMo/Gym#4817, so this PR no longer needs a Gym bump: - Gym's submodule is back on main's pin. - The engine's Gym path (_generate_gym, capture staging, prefix splice), the Gym dialect setup, session affinity, client_base_urls and the Gym-only startup checks move to the follow-up. - NeMo-Gym with policy.generation.dynamo=true is refused at startup in should_use_nemo_gym, before any cluster starts. - The Dynamo L1 keeps its SingleController math and reload-refit overlays; the swe1 Dynamo + Gym nightly is disabled until the follow-up. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
71c17f2 to
b0e681c
Compare
jthomson04
left a comment
There was a problem hiding this comment.
Two comments from the NVIDIA-NeMo/RL#4979 review: G5 (judge servers and the Dynamo pairing check) and G6 (reply on the G3 thread).
Generated by Claude Code
1b10ce6 to
3f33ac1
Compare
…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]>
…ne 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]>
…ture 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]>
…'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]>
…odels 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]>
54bc326 to
234bb55
Compare
NVIDIA-NeMo#5195 moves the Gym submodule to 23557b7c2 (Gym main on 2026-11-12) and makes the recipe and test changes that bump needs. This branch pinned the Dynamo dialect (NVIDIA-NeMo/Gym#4817) on the old Gym base, so the two pins conflict. The submodule is now 234bb55da, the head of Gym#4817: the dialect rebased onto Gym main 0aedecf12, which contains 23557b7c2. Gym's dependencies are the same at both commits, so uv.lock is NVIDIA-NeMo#5195's plus this branch's own entries. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
|
/ok to test bb38b1d |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE — three RISK findings and one NOTE.
I reviewed all seven changed files and their directly affected capture, conversion, measurement, and error paths. The current source addresses the earlier return_token_ids and judge-server pairing failures. I didn't execute tests or verify the external NeMo RL/Dynamo implementation.
RISK — Output-budget refitting still calls /tokenize through Dynamo
Failure: With dynamo_frontend=true, no external capture, and the default refit_output_budget_to_window=true, send max_tokens=131072 to an 8192-token model. If the engine replies max_tokens=131072 cannot be greater than max_model_len=8192, the refusal names no prompt count. _refit_output_budget consequently calls _count_prompt_tokens, which still requests /tokenize. The new dialect explicitly has no such endpoint and supplies a chat-based measurement path. A 404 therefore prevents refitting, leaving an empty length completion or propagated refusal instead of the configured single resend. This affects uncaptured Dynamo calls whose length error omits the prompt count.
Correction: Make the prompt-count fallback in _refit_output_budget dialect-aware. For Dynamo, copy the fully prepared outbound request, add ng_measure=true to its existing annotation, issue the measurement chat call, and accept only a nonnegative integer prompt_token_count with ng_context_measured=true. Preserve the existing fail-safe refusal when measurement fails. The external engine isn't mounted, so I can't verify whether measurement requires removing generation-only controls; confirm that contract before adopting an implementation. Don't route this through measure_context, which requires external capture.
Preservation: Keep counts stated in the error as the first choice, native vLLM's /tokenize fallback, the one-resend limit, and the existing prohibition on refitting externally staged calls. Measurement must retain the prepared messages, rendering options, and echoed token prefix without generating or staging tokens.
Acceptance — proposed tests, not executed: Extend the existing fallback regression with Dynamo enabled. Stub the initial refusal above, a measurement result of 100 tokens, and a successful generation. Assert no /tokenize call, one measurement, and exactly one generation resend with max_tokens=8076; execution metadata must record requested 131072 and applied 8076. Retain the native test's /tokenize assertion, and verify failed/unacknowledged measurements and externally staged calls do not resend.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
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]>
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]>
…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]>
…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]>
|
On the review's first finding, that the output-budget refit still calls It does not measure through an |
Moves the Gym submodule from 234bb55da to 6dc68d2fa, the head of NVIDIA-NeMo/Gym#4817. The four new Gym commits answer that PR's review: - reasoning_field "both" is rejected with dynamo_frontend only when the server replays reasoning; - a top-k capture call that also sets logprob_token_ids keeps its HTTP 400 under Dynamo; - forward_session_id_as_conversation_id is rejected with dynamo_frontend, and the output-budget refit no longer asks the frontend for a /tokenize count; - the vLLM guide documents the dialect, and its tests cover every rejected setting, the empty annotation and the Dynamo capture handler. Gym's dependencies are the same at both commits, so uv.lock is unchanged. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
Brings the branch up to date with main (33 commits). No file this branch changes was changed on main, so there are no conflicts. The harness conformance workflow on this branch was older than the script it runs after NVIDIA-NeMo#5367, which made every probe report unavailable. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43490338243 |
NVIDIA-NeMo/Gym#4817 merged as 440104210. Move the pin from that PR's branch (6dc68d2fa) to Gym main at 9e2e5d0ad. Gym's dependencies are the same at both commits, so uv.lock does not change. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
What
Lets the vLLM model server call NeMo RL's vLLM engines through an ai-dynamo frontend (1.5.1 or later), with and without external token capture. This is the Gym half of NVIDIA-NeMo/RL#4979, which serves NeMo-Gym through Dynamo's frontend and KV-aware router.
How NVIDIA-NeMo/RL#4979 uses it. There the Dynamo frontend runs NeMo RL's own chat engine in place of Dynamo's renderer and parsers. That chat engine reads Gym's fields, resolves and splices the token prefix, and builds the reply. The vLLM engine behind it generates and stages the captured tokens. NeMo RL turns the dialect on for its policy model, so a NeMo RL recipe sets none of this by hand:
dynamo_frontend: true,reasoning_field: reasoning_contentunless the config sets one, andexternal_staging_backend: dynamo_workerwhen token capture is on.Why a dialect. NeMo RL's vLLM server takes its extra request fields at the top level (
ng_capture,required_prefix_token_ids) and returns token data on the message. The Dynamo frontend rejects request fields it does not know and drops response fields it does not know, so neither survives it. The frontend does passnvextthrough in both directions, so the dialect carries the same fields there, under the same names.VLLMModelConfig.dynamo_frontend(defaultfalse)When set:
nemo_rl:gym:<JSON object>entry innvext.annotations. The object holds NeMo RL's request fields (ng_capture,required_prefix_token_ids,ng_measure) and is empty when none applies. NeMo RL's chat engine refuses a chat call without the entry; NeMo RL's own rollouts use/v1/completions.nvext.nemo_rl. The server moves each field to where NeMo RL's vLLM server puts it: token IDs, log probabilities androuted_experts(router replay) onto the message. Withreturn_token_id_information, a response without the required token fields fails with an error that names what is missing.prompt_token_ids + generation_token_idsgo in the annotation asrequired_prefix_token_ids, which NeMo RL's vLLM server derives from the messages itself./context/measuremeasures through a chat call markedng_measure, because the frontend has no/tokenize. NeMo RL's chat engine answers it with the prompt length, without reaching a vLLM engine.x-ng-capture-refusedheader before the refusal is settled. The harness gets NeMo RL's own message.top_logprobsandlogprob_token_idsis refused with HTTP 400, as it is against a vLLM server. The frontend acceptslogprob_token_idsbut does not hand it to NeMo RL's chat engine, and feat(dynamo): serve NeMo-Gym through the Dynamo frontend RL#4979 rejects it at startup only in its own policy-model overlay.refit_output_budget_to_windowandrefit_output_budget_to_prompthave no call to resend, and the server does not ask the frontend for a/tokenizecount, which it does not serve. NeMo RL's chat engine lowers a budget that does not fit to what the context window leaves, and refuses only a prompt that fills the window by itself.use_completions_api,is_responses_native,supply_prefix_token_ids,request_prompt_and_generation_token_idsandforward_session_id_as_conversation_id, whose calls or fields the frontend refuses. Alsoreasoning_field: bothon a server that replays reasoning onto assistant messages (reasoning parser on,uses_interleaved_reasoningon, reasoning not kept in content), which the frontend answers with400 duplicate field 'reasoning'.token_id_capture.external_staging_backend: dynamo_workerDynamoWorkerCaptureHandler:ng_capturein the annotation, with no top-levelng_captureorrequired_prefix_token_ids. NeMo RL's chat engine reads the prefix from the staging chain;logprobs: true, andtop_logprobs: 0unless the call set it), which the engine stages;x-dynamo-session-idheader to the capture key, so Dynamo's router can keep a rollout's calls on one engine, whose KV cache holds the rollout's prefix. NeMo RL enables that withfrontend_args.session_affinity_ttl_secs. It takes effect from ai-dynamo 1.7 (feat(dynamo)!: Dynamo 1.8 nightly, high session cap, frontends across nodes RL#5115): 1.5.1 drops the session id of a chat call served by NeMo RL's chat engine;nvext.nemo_rl.ng_commit_coords.ExternalCaptureHandlergainsrequest_headers()for that header.source_historyparent resolution acceptsdynamo_workeras it doesvllm_worker. With external staging on, a server that setsdynamo_frontendmust usedynamo_worker; other servers under the same capture block, such as judges, are not checked.The names the model server and NeMo RL share (
add_dynamo_gym_extras,pop_dynamo_call_result,split_dynamo_capture_refusal,dynamo_capture_refusal_suffixand the two constants) are exported fromnemo_gym.models.Docs
The vLLM guide gains "Use VLLMModel through a Dynamo frontend", with "Token capture through Dynamo" for the
dynamo_workerpairing. The capture guide points to it.Compatibility
Opt-in only.
dynamo_frontenddefaults tofalse,dynamo_workeris a new backend value, andrequest_headers()returns{}for the vLLM and Megatron handlers. Current configs behave as before.Dynamo versions. The checks above hold on ai-dynamo 1.5.1, which NVIDIA-NeMo/RL#4979 pins, and on 1.7 (
release/1.7.0), which NVIDIA-NeMo/RL#5115 moves to: the same fields are refused or accepted, and neither serves/tokenize. One thing differs, on NeMo RL's side and not in this dialect. 1.5.1 forwards the message of every 4xx error. From 1.7 the frontend forwards it only for an error raised as one of Dynamo's typed errors, and otherwise sends the status's reason phrase. The refusal acknowledgement and the context-length text then do not reach Gym, which fails the call instead of settling it. NVIDIA-NeMo/RL#4979 records it; NeMo RL has to raise those refusals as typed errors.Issue
None filed. NVIDIA-NeMo/RL#4979 describes the design. Its merge order is NVIDIA-NeMo/RL#5195 (the Gym bump), then this PR, then #4979 re-pinned to this PR's merged commit.
Validation
Run locally. The first three ran on this head (
4ad93ce15, which mergesmainatb4f6a0d44); the last ran on6dc68d2fa, the commit before that merge:pre-commit run --all-files: clean.responses_api_models/vllm_model/tests: 1,188 passed.tests/unit_tests/models/test_external_capture_handlers.py,tests/unit_tests/test_public_api.pyandtests/unit_tests/models/test_token_capture.py: 382 passed.tests/unit_tests -m "not sandbox": 21,159 passed and 221 skipped. 47 failed and 9 errored, none in a file this PR touches. 55 of them fail the same way on this PR's base commit (0aedecf12) in this environment, which lacks optional packages (mlflow, wandb, Pillow, jinja2, cloudpickle). The other one, a process-shutdown timing test (test_cli_server_shutdown.py), passed when rerun with nothing else running on the machine.Tests this PR adds or extends:
test_dynamo_frontend_dialect: the request and response transforms with and without capture, a response withoutnvext.nemo_rl, and one with fields missing.test_dynamo_frontend_rejects_settings_it_cannot_serveandtest_dynamo_worker_backend_pairing: the startup checks, with one case for every rejected setting.test_dynamo_frontend_sends_an_empty_annotation_for_a_plain_call: a call with no capture and no echoed turn still carries the annotation.test_a_refusal_through_dynamo_is_not_counted_with_tokenize: the refit makes no/tokenizecall.tests/unit_tests/models/test_external_capture_handlers.pynow runs its lifecycle and factory cases forDynamoWorkerCaptureHandler.test_topk_capture_rejects_specific_logprob_idsnow runs for the vLLM and the Dynamo capture handler.test_measurement_uses_same_candidate_without_ledger_writesandtest_context_refusal_settles_capture_only_with_worker_acknow run for both the vLLM server and the Dynamo frontend.Rollout evidence
NVIDIA-NeMo/RL#4979 pins
6dc68d2fa, this PR's last commit beforemainwas merged in, and its Validation section records the runs:0d95075213): the vLLM lane with Gym installed gave 66 passed, and the Gym lane 1,191 passed and 14 errors. The 14 arecode_genrollout cases that fail at setup since refactor(code-gen): replace legacy Ray execution with sandboxes #4958 requiressandbox_config.image; that check is onmainand not part of this PR.1.7.0.dev20261106: workplace_assistant with score centering, forest training with context compaction, a multimodal config and a Nemotron Nano config. Each test's own gates come out the same either way.The functional and cluster runs used the dialect commits on an older Gym base (
9aac609) and were not repeated after the rebase ontomainor after the review fixes. Neither changes a request or response those recipes make. The rebase changed import paths, the client's per-request header parameter (_headers, whichmainnow has) and one renamed test argument. The review fixes change a startup check and a refusal that those recipes do not reach. The later merge ofmaintouches no file this PR changes.🤖 Generated with Claude Code