Skip to content

fix(vllm_model): auto-derive required_prefix_token_ids on chat + toke… - #1294

Closed
jthomson04 wants to merge 3 commits into
NVIDIA-NeMo:mainfrom
jthomson04:jthomson04/required-prefix-token-ids
Closed

jthomson04 wants to merge 3 commits into
NVIDIA-NeMo:mainfrom
jthomson04:jthomson04/required-prefix-token-ids

Conversation

@jthomson04

Copy link
Copy Markdown
Contributor

…nize

When per-message prompt_token_ids/generation_token_ids are attached to assistant messages (training mode), populate the top-level required_prefix_token_ids field on both the chat-completion request and the separate tokenize request. Mirrors NeMoRLOpenAIChatRequestMixin auto-derive in nemo-rl's custom vLLM serving (vllm_worker_async.py).

Without this, Dynamo - which has the splice machinery server-side but no auto-derive - re-tokenizes the chat history each turn, breaking the byte-level token-contiguity invariant on multi-turn rollouts. The fix must apply to BOTH endpoints because the contiguity assert in nemo_rl/environments/nemo_gym.py reads prompt_token_ids from the tokenize response, not the chat response. Patching only chat fails at the tokenize step.

@copy-pr-bot

copy-pr-bot Bot commented May 11, 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.

Comment thread responses_api_models/vllm_model/app.py Outdated
# template-tokenized prefix, preserving byte-level token continuity
# across multi-turn replays. The vLLM mixin auto-derives from
# per-message `prompt_token_ids` itself (see
# `nemo_rl/models/generation/vllm/vllm_worker_async.py`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we add a permalink for this?

Comment thread responses_api_models/vllm_model/app.py Outdated
# `NeMoRLOpenAIChatRequestMixin.model_post_init`); Dynamo does not,
# so we set it server-agnostically here. When the vLLM mixin sees
# the field already populated, its auto-derive short-circuits.
if "required_prefix_token_ids" not in body_dict:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we gate this behind a config param so we don't send duplicate information? i.e. send_token_ids_via_required_prefix_token_ids which will add the "required_prefix_token_ids" and pop the prompt_token_ids and generation_token_ids?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe the param can be send_required_prefix_token_ids_dynamo then?

Comment thread responses_api_models/vllm_model/app.py Resolved
@cmunley1

cmunley1 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

can you add tests?

…nize

When per-message prompt_token_ids/generation_token_ids are attached to
assistant messages (training mode), populate the top-level
required_prefix_token_ids field on both the chat-completion request and
the separate tokenize request. Mirrors NeMoRLOpenAIChatRequestMixin
auto-derive in nemo-rl's custom vLLM serving (vllm_worker_async.py).

Without this, Dynamo - which has the splice machinery server-side but
no auto-derive - re-tokenizes the chat history each turn, breaking the
byte-level token-contiguity invariant on multi-turn rollouts. The fix
must apply to BOTH endpoints because the contiguity assert in
nemo_rl/environments/nemo_gym.py reads prompt_token_ids from the
tokenize response, not the chat response. Patching only chat fails at
the tokenize step.

Signed-off-by: jthomson04 <[email protected]>
@jthomson04
jthomson04 force-pushed the jthomson04/required-prefix-token-ids branch from 58d941b to feacd80 Compare June 9, 2026 03:24
@jthomson04 jthomson04 closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants