Repository navigation
[Bugfix][Frontend] Reject an empty conversation in every renderer - #62218
Open
albertoperdomo2 wants to merge 6 commits into
Open
albertoperdomo2 wants to merge 6 commits into
albertoperdomo2 wants to merge 6 commits into
Conversation
Signed-off-by: Alberto Perdomo <aperdomo@redhat.com>
Signed-off-by: Alberto Perdomo <aperdomo@redhat.com>
albertoperdomo2
requested review from
DarkLight1337 and
njhill
as code owners
October 17, 2026 19:36
| # the HF tokenizer refuses an empty conversation in apply_chat_template, | ||
| # but renderers with their own chat encoding render it to a bare BOS | ||
| # prompt. Refuse it here so every renderer answers the same way. | ||
| if any(not conversation for conversation in conversations): |
Contributor
There was a problem hiding this comment.
I don't think this is the right fix. As conversations grows larger, we should avoid introducing an additional loop.
Contributor
Author
There was a problem hiding this comment.
thanks for looking @chaunceyjiang! conversations here is the batch of conversations, not the messages in one, so the check is one O(1) emptiness test per conversation and it short-circuits
online serving always renders a single conversation (online_renderer.py:805), so there it's one check; only offline LLM.chat passes a batch
measured: 0.14µs for one conversation of any length, 16µs for 1000 conversations, which can be considered negligible next to rendering and tokenizing each of them IMHO
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Renderers with their own chat encoding (DeepSeek V3.2/V4/V4.1) render an empty conversation to a bare BOS prompt, so
/v1/responseswithinput: []returns 200 with text generated from nothing. This returns the same 400 that HF-tokenizer models already return.Claims
BadRequestError("Cannot apply chat template to an empty conversation. Provide at least one message.") for every renderer.input: []plusinstructionsorprevious_response_id.Validation
New
tests/renderers/test_empty_conversation.py: the 3 rejection cases fail onmainand pass with this change; the 2 controls pass on both.Details
transformersrefuses an empty conversation inapply_chat_template, but the DeepSeek tokenizers override that method and skip the check. The check now runs at the start ofBaseRenderer.render_chatandrender_chat_async, after each endpoint has built its messages. The Rust frontend already rejects an empty conversation (ChatRequest::validate); this brings the Python frontend in line.Claude Code used to create the new tests.
Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.