Repository navigation
feat(vllm-model): consume native Dynamo token data - #1784
jthomson04 wants to merge 4 commits into
Conversation
683aa26 to
0be56ef
Compare
cbe8edc to
f622f9f
Compare
eddd5e9 to
56228a4
Compare
56228a4 to
73f3f68
Compare
#1558) ## Summary - Consume a complete token bundle from `choice.message` without making a second `/tokenize` request. - Support opt-in vLLM response token IDs for endpoints that return top-level `prompt_token_ids` and choice-level `token_ids`. - Retain `/tokenize` for integrations that return neither inline representation. - Reject partial or conflicting sources. Token capture supports one completion choice per request (`n` omitted or set to `1`). ## Why Gym needs the prompt token IDs, generated token IDs, and selected-token log probabilities used during generation. The previous adapter reconstructed prompt IDs through a second awaited `/tokenize` request. That request adds inter-turn latency and can reproduce a different prompt when prompt-affecting inputs are omitted. NeMo RL [#3390](NVIDIA-NeMo/RL#3390) attaches the token bundle to the assistant message. Gym reads that bundle directly and does not request duplicate response-level IDs by default. Gym cannot require that message shape from every training integration. Other integrations, including Verl, can request vLLM's response token IDs or continue using the compatibility fallback. ## Source precedence 1. A complete token bundle on `choice.message`. 2. Top-level `prompt_token_ids`, choice-level `token_ids`, and `choice.logprobs` from the vLLM response. 3. Generation metadata from `choice.logprobs` and prompt IDs from `/tokenize`. `request_prompt_and_generation_token_ids: true` enables the second source by sending `return_token_ids=true` to compatible vLLM endpoints. The option defaults to `false`. If both inline sources are present, their token IDs must agree. The selected training message is validated once to avoid repeated list scans and copies at long sequence lengths. The fallback forwards `model`, `messages`, `tools`, `chat_template_kwargs`, `mm_processor_kwargs`, and `required_prefix_token_ids`. This keeps fallback tokenization aligned with the generation prompt. `prompt_logprobs` is not requested. vLLM returns prompt IDs independently when `return_token_ids` is enabled, and Gym does not consume prompt-token log probabilities. ## Related work - Gym [#700](#700) is superseded by this change. - Gym [#2576](#2576) is superseded by this change. - NeMo RL [#3390](NVIDIA-NeMo/RL#3390) produces the message-level token bundle consumed by the first source. - NeMo RL [#3581](NVIDIA-NeMo/RL#3581) reuses replayed token metadata across turns. - Gym [#1784](#1784) can add the Dynamo `nvext.engine_data` source independently. - Gym [#2324](#2324) can retain its video-specific schema, conversion, and adapter behavior independently. --------- Signed-off-by: Ananth Subramaniam <[email protected]>
73f3f68 to
9607560
Compare
9607560 to
3e7528c
Compare
jthomson04
left a comment
There was a problem hiding this comment.
Code review
14 findings from a recall-oriented pass over the diff and the enclosing functions in responses_api_models/vllm_model/app.py.
Blocking (1-3):
nvextis never popped from the response. Lines 817-818 deliberately stripprompt_token_idsandchoice.token_idsas transport details, but thenvext.engine_databundle read at line 879 is left in place.NeMoGymChatCompletioninherits openai'sextra="allow"base model, so the full token payload ships back to every caller a second time, roughly doubling stored rollout size.- The message-vs-Dynamo cross-check ignores
generation_log_probs. Only token IDs are compared, and the message bundle wins on a tie. Stale message-level logprobs silently override Dynamo's authoritative values, corrupting the importance-sampling ratio with no error raised. required_prefix_token_idsis derived for every capture-mode server with no config gate. It now reaches both/chat/completionsand/tokenize. The prior turn's generation is not a byte-prefix of the re-rendered prompt for reasoning models (historical<think>is dropped) or tool-call turns (tool_callsare re-serialized), so this regresses previously-working configurations.
Also flagged (4-14): partial engine_data hard-failing instead of falling through; Gym-injected token_id: pseudo-tokens now returned to callers on the native path (and locked in by a new test); a lower-priority source able to veto a complete Dynamo bundle; stale-older-turn prefix selection; error messages naming Gym field names rather than Dynamo's; the feature being unreachable without the NeMo-RL wrapper since Gym never requests engine_data; test gaps; and reuse/efficiency cleanups.
Two comments (#1 and #5) concern lines 817 and 814, which fall between diff hunks and cannot be anchored exactly; each is attached to the nearest changed line in the same function and states the line it refers to.
Generated with Claude Code.
3e7528c to
fad304d
Compare
acc3c35 to
eb423d2
Compare
eb423d2 to
0130c1e
Compare
Signed-off-by: jthomson04 <[email protected]>
…newest turn Gate required_prefix_token_ids derivation behind a new derive_prefix_token_ids_from_messages flag (default false). Stock vLLM ignores the field, but strict frontends such as Dynamo reject unknown request fields, and the field is also forwarded to /tokenize. Keep the flag apart from supply_prefix_token_ids, which owns the field when enabled, and never put the token array in an external-staging body. Derive only from the newest assistant message. If it has no token bundle, send no prefix instead of falling back to an older turn's tokens, which may no longer be a prefix of the prompt. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
… test gaps Restore the container-only token list checks from NVIDIA-NeMo#1558 for message and vLLM token sources. Scanning every prompt token ID in Python costs about 3.4 ms per 100k IDs on the event loop. The final training-message model still checks those element types. Check element types only for nvext.engine_data, which has no Gym-side schema, and report the Dynamo field name in each error. Keep one Gym-to-Dynamo field map as a ClassVar so no inverse map is built per response. Document that callers opt in to engine data through extra_body.nvext.extra_fields. Add tests for engine-data token ID element errors, a Dynamo bundle that disagrees with vLLM token IDs, and stripping token_id:<int> logprobs on the message-bundle path. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
0130c1e to
2a80b8d
Compare
|
We’re doing some cleanup of the open PR list. This PR has had no activity for over a month, so I’ve moved it back to draft. If this change is still needed, please resolve any merge conflicts and mark the PR ready for review again when it’s ready to merge. Thanks! |
|
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. |
Summary
Depends on #2836. This branch stacks on it, so until #2836 merges, this PR also shows #2836's two commits.
Move native Dynamo response-token handling into NeMo-Gym's shared vLLM token-selection path.
prompt_token_ids,completion_token_ids, andcompletion_logprobsfromnvext.engine_data.prompt_token_ids,generation_token_ids, andgeneration_log_probsbundle.choice.logprobsplus/tokenize.engine_data(nvext.extra_fields) and the response doesn't include it, fail clearly instead of falling back to/tokenize.token_id:<int>choice.logprobsentries andnvext.engine_dataon every capture path. Othernvextfields (e.g.timing) and message extensions such asrouted_expertspass through.Prefix derivation lives only in #2836's opt-in helper. Dynamo deployments set
derive_prefix_token_ids_from_messages: truealongsideextra_body.nvext.extra_fields: ["engine_data"].Motivation
NeMo-Gym needs the model's original token IDs and log probabilities for training. Dynamo already returns these values in
nvext.engine_data. Consuming that native bundle in Gym removes duplicate response conversion from NeMo-RL and avoids an unsupported/tokenizefallback.Gym owns response interpretation. The NeMo-RL wrapper continues to render exact prompt tokens, splice the prior prefix, send
nvext.token_data, and requestengine_data.Compatibility
choice.logprobs. When a complete native bundle is present, partial vLLM token fields are ignored, and complete ones are still cross-checked./tokenizefallback are unchanged when native data is absent.engine_data, which has no Gym-side schema.Changes since the last revision
main, on top of perf(vllm): derive required prefix token IDs in Gym #2836.engine_data-gated call site._DYNAMO_ENGINE_DATA_FIELDSClassVar.Validation
responses_api_models/vllm_model/tests/gives 436 passed. The subclass suites (vllm_model_with_compaction,azure_openai_model,local_vllm_model_proxy) also pass.pre-commit run --all-filespasses.The end-to-end managed Dynamo smoke runs from NVIDIA-NeMo/RL#3763, which pins this PR's head.
Related