[Bugfix][Frontend] Check reused prompt token ids against the vocab before streaming (#59555)
Signed-off-by: Shijie Lyu <lshjhf@gmail.com>
This commit is contained in:
@@ -556,9 +556,6 @@ class InputProcessor:
|
||||
prompt_input: SingletonInput,
|
||||
prompt_type: Literal["encoder", "decoder"],
|
||||
) -> None:
|
||||
model_config = self.model_config
|
||||
tokenizer = self.tokenizer
|
||||
|
||||
prompt_ids = (
|
||||
None
|
||||
if prompt_input["type"] == "embeds"
|
||||
@@ -595,34 +592,9 @@ class InputProcessor:
|
||||
f"by setting --limit-mm-per-prompt at startup."
|
||||
)
|
||||
|
||||
if prompt_ids and tokenizer is not None:
|
||||
max_input_id = max(prompt_ids, default=0)
|
||||
min_input_id = min(prompt_ids, default=0)
|
||||
|
||||
# NOTE: tokenizer.max_token_id is the tokenizer’s vocab size while
|
||||
# self.model_config.get_vocab_size() is the model’s vocab size.
|
||||
# For Qwen3 models, the language model has extra tokens that do
|
||||
# not exist in the tokenizer, and vice versa for multimodal
|
||||
# placeholder tokens in some multimodal models.
|
||||
# See https://github.com/QwenLM/Qwen3/issues/29#issuecomment-1933720399 # noqa: E501
|
||||
# and https://github.com/vllm-project/vllm/pull/22471#discussion_r2312251421 # noqa: E501
|
||||
|
||||
# Here we take the max of the two to determine if a token id is
|
||||
# truly out-of-vocabulary.
|
||||
model_vocab_size = model_config.get_vocab_size()
|
||||
# A negative id is out of vocabulary just like an over-large one,
|
||||
# but is not caught by the upper-bound check below. Reject it here
|
||||
# so it is not used as an embedding index downstream. This
|
||||
# validation path is shared by generate, embedding and pooling
|
||||
# requests, so the check covers all three.
|
||||
if min_input_id < 0:
|
||||
raise VLLMValidationError(
|
||||
f"Token id {min_input_id} is out of vocabulary"
|
||||
)
|
||||
if max_input_id > max(tokenizer.max_token_id, model_vocab_size - 1):
|
||||
raise VLLMValidationError(
|
||||
f"Token id {max_input_id} is out of vocabulary"
|
||||
)
|
||||
# Shared by generate, embedding and pooling requests.
|
||||
if prompt_ids:
|
||||
self.renderer.validate_token_ids(prompt_ids)
|
||||
|
||||
def _validate_model_inputs(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user