Skip to content

[Render][Speculator] Add return_loss_mask to render endpoint for training data generation#46846

Merged
vllm-bot merged 1 commit into
vllm-project:mainfrom
WindChimeRan:speculators/render-loss-mask
Jun 28, 2026
Merged

[Render][Speculator] Add return_loss_mask to render endpoint for training data generation#46846
vllm-bot merged 1 commit into
vllm-project:mainfrom
WindChimeRan:speculators/render-loss-mask

Conversation

@WindChimeRan

@WindChimeRan WindChimeRan commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Purpose

Adds a return_loss_mask field to ChatCompletionRequest and a loss_mask field to GenerateRequest, so POST /v1/chat/completions/render can return a per-token assistant/trainable mask alongside token_ids. This is needed by downstream training frameworks (e.g. [speculators](vllm-project/speculators#652)) that use the render endpoint to delegate tokenization to vLLM instead of duplicating it locally with HF apply_chat_template. The mask is computed in a single apply_chat_template call (no second pass) via HF's return_assistant_tokens_mask when the chat template has {% generation %} tags; otherwise loss_mask is null and the caller handles the fallback.

Test


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

@mergify

mergify Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @WindChimeRan.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@benchislett

Copy link
Copy Markdown
Member

Why deviate from the established naming convention of "return_assistant_tokens_mask"? I think this is more aligned with the functionality this service would provide, rather than "return_loss_mask" which just reflects what a training server would want to do with it

Comment thread tests/entrypoints/serve/render/test_render.py Outdated
Comment thread vllm/renderers/hf.py Outdated
@benchislett

Copy link
Copy Markdown
Member

Besides the naming, this generally LGTM. Ideally would like a review from a codeowner here though

@WindChimeRan WindChimeRan requested a review from benchislett June 26, 2026 18:56
Comment thread vllm/renderers/params.py Outdated
Comment thread tests/entrypoints/serve/render/test_render.py
Comment thread vllm/renderers/hf.py
@mergify mergify Bot added deepseek Related to DeepSeek models llama Related to Llama models multi-modality Related to multi-modality (#4194) mistral Related to Mistral models qwen Related to Qwen models nvidia rocm Related to AMD ROCm labels Jun 27, 2026
@mergify mergify Bot added intel-gpu Related to Intel GPU cpu Related to CPU backends labels Jun 27, 2026
@mergify mergify Bot added the v1 label Jun 27, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Jun 27, 2026
@mergify mergify Bot added the tool-calling label Jun 27, 2026
Add a `return_assistant_tokens_mask` field to ChatCompletionRequest and
an `assistant_tokens_mask` field to GenerateRequest, so the render
endpoint can return a per-token mask marking assistant-generated tokens.

The mask is computed in a single apply_chat_template call when the chat
template uses {% generation %} tags; otherwise assistant_tokens_mask is
null. Downstream consumers (e.g. speculators) use this for training
data generation without duplicating tokenization locally.

Co-authored-by: Benjamin Chislett <chislett.ben@gmail.com>
Signed-off-by: Ranran Haoran Zhang <ranzhang@redhat.com>
@WindChimeRan WindChimeRan force-pushed the speculators/render-loss-mask branch from cc37059 to 27e7c17 Compare June 27, 2026 05:51
@github-project-automation github-project-automation Bot moved this to Ready in NVIDIA Jun 27, 2026
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) June 27, 2026 06:27
@github-actions github-actions Bot added the ready ONLY add when PR is ready to merge/full CI is needed label Jun 27, 2026
@vllm-bot vllm-bot merged commit 09841ae into vllm-project:main Jun 28, 2026
79 of 83 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to Done in NVIDIA Jun 28, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in AMD Jun 28, 2026
wincent8 pushed a commit to wincent8/vllm that referenced this pull request Jun 29, 2026
…ning data generation (vllm-project#46846)

Signed-off-by: Ranran Haoran Zhang <ranzhang@redhat.com>
Co-authored-by: Benjamin Chislett <chislett.ben@gmail.com>
rjrock pushed a commit to rjrock/vllm that referenced this pull request Jul 1, 2026
…ning data generation (vllm-project#46846)

Signed-off-by: Ranran Haoran Zhang <ranzhang@redhat.com>
Co-authored-by: Benjamin Chislett <chislett.ben@gmail.com>
noooop pushed a commit to noooop/vllm that referenced this pull request Jul 9, 2026
…ning data generation (vllm-project#46846)

Signed-off-by: Ranran Haoran Zhang <ranzhang@redhat.com>
Co-authored-by: Benjamin Chislett <chislett.ben@gmail.com>
Signed-off-by: wang.yuqi <yuqi.wang@daocloud.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/build cpu Related to CPU backends deepseek Related to DeepSeek models documentation Improvements or additions to documentation frontend intel-gpu Related to Intel GPU llama Related to Llama models mistral Related to Mistral models multi-modality Related to multi-modality (#4194) nvidia qwen Related to Qwen models ready ONLY add when PR is ready to merge/full CI is needed rocm Related to AMD ROCm tool-calling v1

Projects

Status: Done
Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants