Skip to content

feat(vllm-model): consume native Dynamo token data - #1784

Draft
jthomson04 wants to merge 4 commits into
NVIDIA-NeMo:mainfrom
jthomson04:codex/dynamo-native-token-transport
Draft

jthomson04 wants to merge 4 commits into
NVIDIA-NeMo:mainfrom
jthomson04:codex/dynamo-native-token-transport

Conversation

@jthomson04

@jthomson04 jthomson04 commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • Read prompt_token_ids, completion_token_ids, and completion_logprobs from nvext.engine_data.
  • Normalize them to Gym's existing prompt_token_ids, generation_token_ids, and generation_log_probs bundle.
  • Select token data in this order: assistant-message metadata, Dynamo engine data, standard vLLM token IDs, then choice.logprobs plus /tokenize.
  • If the request asked for engine_data (nvext.extra_fields) and the response doesn't include it, fail clearly instead of falling back to /tokenize.
  • Reject partial or malformed native data. Errors name the Dynamo fields. The message-vs-Dynamo cross-check covers token IDs and log probabilities.
  • Strip Gym's token_id:<int> choice.logprobs entries and nvext.engine_data on every capture path. Other nvext fields (e.g. timing) and message extensions such as routed_experts pass through.

Prefix derivation lives only in #2836's opt-in helper. Dynamo deployments set derive_prefix_token_ids_from_messages: true alongside extra_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 /tokenize fallback.

Gym owns response interpretation. The NeMo-RL wrapper continues to render exact prompt tokens, splice the prior prefix, send nvext.token_data, and request engine_data.

Compatibility

  • Existing NeMo-RL wrappers that copy matching token metadata onto the assistant message remain supported.
  • Native Dynamo data does not require choice.logprobs. When a complete native bundle is present, partial vLLM token fields are ignored, and complete ones are still cross-checked.
  • Standard vLLM token IDs and the existing /tokenize fallback are unchanged when native data is absent.
  • Non-Dynamo sources keep fix(vllm_model): prefer inline token metadata over prompt tokenization #1558's container-only checks. Per-element type checks apply only to engine_data, which has no Gym-side schema.

Changes since the last revision

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-files passes.

The end-to-end managed Dynamo smoke runs from NVIDIA-NeMo/RL#3763, which pins this PR's head.

Related

@copy-pr-bot

copy-pr-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@jthomson04
jthomson04 force-pushed the codex/dynamo-native-token-transport branch from 683aa26 to 0be56ef Compare June 26, 2026 20:08
@jthomson04 jthomson04 changed the title feat(vllm-model): support dynamo native token transport feat(vllm-model): consume native dynamo token data Jun 26, 2026
@jthomson04
jthomson04 force-pushed the codex/dynamo-native-token-transport branch from cbe8edc to f622f9f Compare June 29, 2026 22:23
@jthomson04
jthomson04 marked this pull request as ready for review June 29, 2026 23:38
@jthomson04
jthomson04 force-pushed the codex/dynamo-native-token-transport branch from eddd5e9 to 56228a4 Compare July 7, 2026 18:18
@jthomson04
jthomson04 requested a review from a team as a code owner July 7, 2026 18:18
@jthomson04
jthomson04 force-pushed the codex/dynamo-native-token-transport branch from 56228a4 to 73f3f68 Compare July 8, 2026 22:04
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Jul 17, 2026
ananthsub added a commit that referenced this pull request Aug 18, 2026
#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]>
@jthomson04
jthomson04 force-pushed the codex/dynamo-native-token-transport branch from 73f3f68 to 9607560 Compare August 21, 2026 19:31
@jthomson04 jthomson04 changed the title feat(vllm-model): consume native dynamo token data feat(vllm-model): consume native Dynamo token data Aug 21, 2026
@jthomson04
jthomson04 force-pushed the codex/dynamo-native-token-transport branch from 9607560 to 3e7528c Compare August 21, 2026 19:40

@jthomson04 jthomson04 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

  1. nvext is never popped from the response. Lines 817-818 deliberately strip prompt_token_ids and choice.token_ids as transport details, but the nvext.engine_data bundle read at line 879 is left in place. NeMoGymChatCompletion inherits openai's extra="allow" base model, so the full token payload ships back to every caller a second time, roughly doubling stored rollout size.
  2. 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.
  3. required_prefix_token_ids is derived for every capture-mode server with no config gate. It now reaches both /chat/completions and /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_calls are 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.

Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread responses_api_models/vllm_model/app.py Resolved
Comment thread responses_api_models/vllm_model/app.py Resolved
@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Aug 21, 2026
@jthomson04
jthomson04 force-pushed the codex/dynamo-native-token-transport branch from 3e7528c to fad304d Compare August 21, 2026 21:33
jthomson04 and others added 4 commits October 12, 2026 09:08
…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]>
… 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]>
@jthomson04
jthomson04 force-pushed the codex/dynamo-native-token-transport branch from 0130c1e to 2a80b8d Compare October 12, 2026 16:34
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 12, 2026 16:34
@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:model Model servers, inference providers, and model adapters blocked Work cannot move forward until an external dependency is cleared feature New capabilities, enhancements, or enablement work labels Oct 20, 2026
@yaoyu-33
yaoyu-33 marked this pull request as draft November 18, 2026 02:13
@yaoyu-33

Copy link
Copy Markdown
Contributor

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!

@copy-pr-bot

copy-pr-bot Bot commented Nov 18, 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.

This branch was previously deployed

1 inactive deployment
public — 2a80b8df Deployed Oct 12, 2026 by copy-pr-bot[bot] via release / finalize / notify #5058
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 blocked Work cannot move forward until an external dependency is cleared feature New capabilities, enhancements, or enablement work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants