[Bugfix] complete VLLMValidationError migration in chat_utils.py (#50254)

Signed-off-by: shaolila <shaolila@buaa.edu.cn>
Co-authored-by: shaolila <shaolila@buaa.edu.cn>
This commit is contained in:
Adababy
2026-09-05 17:56:12 +08:00
committed by GitHub
co-authored by shaolila
parent e473e9036f
commit 2902ca17e3
3 changed files with 12 additions and 7 deletions
+2 -1
View File
@@ -11,6 +11,7 @@ from vllm.entrypoints.launchers.cli_args import (
validate_parsed_serve_args, validate_parsed_serve_args,
) )
from vllm.entrypoints.openai.models.protocol import LoRAModulePath from vllm.entrypoints.openai.models.protocol import LoRAModulePath
from vllm.exceptions import VLLMValidationError
from vllm.utils.argparse_utils import FlexibleArgumentParser from vllm.utils.argparse_utils import FlexibleArgumentParser
LORA_MODULE = { LORA_MODULE = {
@@ -204,7 +205,7 @@ def test_chat_template_validation_for_happy_paths(serve_parser):
def test_chat_template_validation_for_sad_paths(serve_parser): def test_chat_template_validation_for_sad_paths(serve_parser):
"""Ensure validation fails if the chat template doesn't exist""" """Ensure validation fails if the chat template doesn't exist"""
args = serve_parser.parse_args(args=["--chat-template", "does/not/exist"]) args = serve_parser.parse_args(args=["--chat-template", "does/not/exist"])
with pytest.raises(ValueError): with pytest.raises(VLLMValidationError):
validate_parsed_serve_args(args) validate_parsed_serve_args(args)
+2 -1
View File
@@ -6,6 +6,7 @@ import pytest
from vllm.config import ModelConfig from vllm.config import ModelConfig
from vllm.entrypoints.chat_utils import load_chat_template from vllm.entrypoints.chat_utils import load_chat_template
from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest
from vllm.exceptions import VLLMValidationError
from vllm.renderers.hf import ( from vllm.renderers.hf import (
_consolidate_system_messages, _consolidate_system_messages,
_convert_developer_to_system, _convert_developer_to_system,
@@ -97,7 +98,7 @@ def test_no_load_chat_template_filelike():
# Testing chatml template # Testing chatml template
template = "../../examples/does_not_exist" template = "../../examples/does_not_exist"
with pytest.raises(ValueError, match="looks like a file path"): with pytest.raises(VLLMValidationError, match="looks like a file path"):
load_chat_template(chat_template=template) load_chat_template(chat_template=template)
+8 -5
View File
@@ -1446,10 +1446,11 @@ def validate_chat_template(chat_template: Path | str | None):
builtin_template_path = CHAT_TEMPLATES_DIR / chat_template builtin_template_path = CHAT_TEMPLATES_DIR / chat_template
if not builtin_template_path.exists(): if not builtin_template_path.exists():
raise ValueError( raise VLLMValidationError(
f"The supplied chat template string ({chat_template}) " f"The supplied chat template string ({chat_template}) "
f"appears path-like, but doesn't exist! " f"appears path-like, but doesn't exist! "
f"Tried: {chat_template} and {builtin_template_path}" f"Tried: {chat_template} and {builtin_template_path}",
parameter="chat_template",
) )
else: else:
@@ -1497,7 +1498,7 @@ def _load_chat_template(
f"Tried: {chat_template} and {builtin_template_path}. " f"Tried: {chat_template} and {builtin_template_path}. "
f"Reason: {e}" f"Reason: {e}"
) )
raise ValueError(msg) from e raise VLLMValidationError(msg, parameter="chat_template") from e
# If opening a file fails, set chat template to be args to # If opening a file fails, set chat template to be args to
# ensure we decode so our escape are interpreted correctly # ensure we decode so our escape are interpreted correctly
@@ -1575,7 +1576,8 @@ def _get_full_multimodal_text_prompt(
logger.debug("Input prompt: %s", text_prompt) logger.debug("Input prompt: %s", text_prompt)
raise VLLMValidationError( raise VLLMValidationError(
f"Found more '{placeholder}' placeholders in input prompt than " f"Found more '{placeholder}' placeholders in input prompt than "
"actual multimodal data items." "actual multimodal data items.",
parameter="messages",
) )
missing_placeholders.extend([placeholder] * placeholder_counts[placeholder]) missing_placeholders.extend([placeholder] * placeholder_counts[placeholder])
@@ -1833,7 +1835,8 @@ def _reject_reserved_placeholder_in_text(text: str, model_config: ModelConfig) -
raise VLLMValidationError( raise VLLMValidationError(
_RESERVED_PLACEHOLDER_IN_TEXT_ERROR.format( _RESERVED_PLACEHOLDER_IN_TEXT_ERROR.format(
token=PROMPT_EMBEDS_PLACEHOLDER_TOKEN token=PROMPT_EMBEDS_PLACEHOLDER_TOKEN
) ),
parameter="messages",
) )