[Bugfix] Normalize malformed dict prompts that carry token IDs in prompt (#40339)

Signed-off-by: Alchuang22-dev <2584829494@qq.com>
This commit is contained in:
Zeyu Zhang
2026-04-21 07:44:36 +00:00
committed by GitHub
parent f95c11a848
commit 5a94a19824
3 changed files with 57 additions and 2 deletions
+20 -1
View File
@@ -4,7 +4,7 @@ Schemas and utilities for preprocessing inputs.
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from collections.abc import Sequence
from collections.abc import Mapping, Sequence
from typing import TYPE_CHECKING, NamedTuple, TypeAlias, TypedDict, overload
from vllm.inputs import (
@@ -116,6 +116,19 @@ that has been standardized into a dictionary.
"""
def _validate_prompt_dict(prompt: Mapping[str, object]) -> None:
"""Reject malformed dict prompts before renderer tokenization."""
if (
"prompt" not in prompt
or "prompt_token_ids" in prompt
or "prompt_embeds" in prompt
):
return
if not isinstance(prompt["prompt"], str):
raise TypeError("Prompt text should be a string")
def parse_dec_only_prompt(prompt: PromptType | object) -> DecoderOnlyDictPrompt:
"""
Parse a prompt for a decoder-only model and normalize it to a dictionary.
@@ -133,6 +146,8 @@ def parse_dec_only_prompt(prompt: PromptType | object) -> DecoderOnlyDictPrompt:
if "encoder_prompt" in prompt:
raise TypeError("Cannot pass encoder-decoder prompt to decoder-only models")
_validate_prompt_dict(prompt)
if (
"prompt" in prompt
or "prompt_token_ids" in prompt
@@ -156,6 +171,8 @@ def _parse_enc_prompt(prompt: PromptType | object) -> EncoderDictPrompt:
return TokensPrompt(prompt_token_ids=prompt)
if isinstance(prompt, dict):
_validate_prompt_dict(prompt)
if "prompt_embeds" in prompt:
raise TypeError("Cannot pass embeddings prompt to encoder-decoder models")
@@ -178,6 +195,8 @@ def _parse_dec_prompt(prompt: PromptType | object) -> DecoderDictPrompt:
return TokensPrompt(prompt_token_ids=prompt)
if isinstance(prompt, dict):
_validate_prompt_dict(prompt)
if "prompt_embeds" in prompt:
raise TypeError("Cannot pass embeddings prompt to encoder-decoder models")