Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions vllm/entrypoints/chat_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
from vllm.multimodal.utils import MEDIA_CONNECTOR_REGISTRY, MediaConnector
from vllm.tokenizers import MistralTokenizer, TokenizerLike
from vllm.transformers_utils.chat_templates import get_chat_template_fallback_path
from vllm.transformers_utils.chat_templates.registry import (
_SKIP_TOKENIZER_CHAT_TEMPLATE,
)
from vllm.transformers_utils.processor import cached_get_processor
from vllm.utils import random_uuid
from vllm.utils.func_utils import supports_kw
Expand Down Expand Up @@ -504,14 +507,15 @@ def resolve_hf_chat_template(
return chat_template

# 3rd priority: AutoTokenizer chat template
try:
return tokenizer.get_chat_template(chat_template, tools=tools)
except Exception:
logger.debug(
"Failed to load AutoTokenizer chat template for %s",
tokenizer.name_or_path,
exc_info=True,
)
if model_config.hf_config.model_type not in _SKIP_TOKENIZER_CHAT_TEMPLATE:
try:
return tokenizer.get_chat_template(chat_template, tools=tools)
except Exception:
logger.debug(
"Failed to load AutoTokenizer chat template for %s",
tokenizer.name_or_path,
exc_info=True,
)

# 4th priority: Predefined fallbacks
path = get_chat_template_fallback_path(
Expand Down
3 changes: 3 additions & 0 deletions vllm/transformers_utils/chat_templates/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def _get_minicpmv_chat_template_fallback(tokenizer_name_or_path: str) -> Path |
"siglip2": CHAT_TEMPLATES_DIR / "template_basic.jinja",
}

# These model types skip tokenizer chat template and use fallback directly
_SKIP_TOKENIZER_CHAT_TEMPLATE: set[str] = {"siglip", "siglip2"}


def register_chat_template_fallback_path(
model_type: str,
Expand Down