Skip to content

fix(vllm_model): prefer inline token metadata over prompt tokenization - #1558

Merged
ananthsub merged 5 commits into
NVIDIA-NeMo:mainfrom
ananthsub:ansubramania/vllm-model-inline-prompt-token-ids
Aug 18, 2026
Merged

fix(vllm_model): prefer inline token metadata over prompt tokenization#1558
ananthsub merged 5 commits into
NVIDIA-NeMo:mainfrom
ananthsub:ansubramania/vllm-model-inline-prompt-token-ids

Conversation

@ananthsub

@ananthsub ananthsub commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

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 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 is superseded by this change.
  • Gym #2576 is superseded by this change.
  • NeMo RL #3390 produces the message-level token bundle consumed by the first source.
  • NeMo RL #3581 reuses replayed token metadata across turns.
  • Gym #1784 can add the Dynamo nvext.engine_data source independently.
  • Gym #2324 can retain its video-specific schema, conversion, and adapter behavior independently.

@copy-pr-bot

copy-pr-bot Bot commented Jun 10, 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.

@cmunley1

Copy link
Copy Markdown
Contributor

lgtm if its working in benchmarks and training validation

@ananthsub
ananthsub force-pushed the ansubramania/vllm-model-inline-prompt-token-ids branch from 83bf8e1 to 0898834 Compare July 20, 2026 21:28
@ananthsub
ananthsub marked this pull request as ready for review July 20, 2026 21:36
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Jul 20, 2026
@ananthsub
ananthsub force-pushed the ansubramania/vllm-model-inline-prompt-token-ids branch from 0898834 to f5e8354 Compare August 13, 2026 14:48
@ananthsub ananthsub changed the title vllm_model: prefer inline prompt/generation token IDs over /tokenize fix(vllm_model): normalize token metadata and avoid redundant tokenization Aug 13, 2026
@ananthsub
ananthsub requested a review from pthombre August 13, 2026 17:27
@ananthsub ananthsub changed the title fix(vllm_model): normalize token metadata and avoid redundant tokenization fix(vllm_model): prefer inline token metadata over prompt tokenization Aug 13, 2026
@ananthsub
ananthsub force-pushed the ansubramania/vllm-model-inline-prompt-token-ids branch 2 times, most recently from f800c69 to 1dcb166 Compare August 18, 2026 15:39
@copy-pr-bot

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

Prefer exact inline metadata while retaining a validated tokenization fallback for training integrations that do not return token IDs.

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
Use NeMo RL's message-level metadata by default while retaining standard inline IDs as an operator-enabled source and preserving the compatibility fallback.

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
Let hosted vLLM endpoints return prompt and generation IDs with the generation response while keeping the default payload free of duplicate token arrays.

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
Validate the selected training message once so long token sequences do not incur duplicate list scans and copies.

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
Keep the newly added implementation details after the public request handlers so the existing class API remains easy to scan.

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
@ananthsub
ananthsub force-pushed the ansubramania/vllm-model-inline-prompt-token-ids branch from 1dcb166 to aa5283b Compare August 18, 2026 19:47
@ananthsub
ananthsub merged commit 09afdc9 into NVIDIA-NeMo:main Aug 18, 2026
16 of 19 checks passed
@ananthsub
ananthsub deleted the ansubramania/vllm-model-inline-prompt-token-ids branch August 18, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants