[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:
Shijie Lyu
2026-10-01 09:26:55 -07:00
committed by GitHub
parent 83cadd65d9
commit 9aaef4296f
4 changed files with 63 additions and 38 deletions
+37
View File
@@ -417,6 +417,43 @@ class BaseRenderer(ABC, Generic[_T]):
return self.tokenizer.eos_token_id
def validate_token_ids(
self, token_ids: Sequence[int], *, parameter: str | None = None
) -> None:
"""Raise VLLMValidationError if a token id is out of vocabulary.
Skipped when the tokenizer is not initialized.
"""
tokenizer = self.tokenizer
if not token_ids or tokenizer is None:
return
max_input_id = max(token_ids)
min_input_id = min(token_ids)
# 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 = self.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.
if min_input_id < 0:
raise VLLMValidationError(
f"Token id {min_input_id} is out of vocabulary", parameter=parameter
)
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", parameter=parameter
)
def get_dec_start_token_id(self) -> int:
"""Obtain the decoder start token id employed by an encoder/decoder model,
raising an error if it is not available.