@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 9ae3c55b10
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 12, 02:15 UTC

SigLIP example add chat_template (#29902)

Signed-off-by: piood <2477084691@qq.com>

Yu Jiaqi committed Dec 4, 2025 at 00:12 UTC 9ae3c55b10318ad7b0c19becb0dc8ad41c171db2
2 files changed +29 -9
examples/pooling/embed/openai_chat_embedding_client_for_multimodal.py
+2 -1
@@ -150,7 +150,8 @@ def run_siglip(client: OpenAI, model: str):
150 Start the server using:
151
152 vllm serve google/siglip-base-patch16-224 \
153 - --runner pooling
153 + --runner pooling \
154 + --chat-template template_basic.jinja
155 """
156
157 response = create_chat_embeddings(
vllm/entrypoints/chat_utils.py
+27 -8
@@ -1139,11 +1139,19 @@ def validate_chat_template(chat_template: Path | str | None):
1139 not any(c in chat_template for c in JINJA_CHARS)
1140 and not Path(chat_template).exists()
1141 ):
1142 - raise ValueError(
1143 - f"The supplied chat template string ({chat_template}) "
1144 - f"appears path-like, but doesn't exist!"
1142 + # Try to find the template in the built-in templates directory
1143 + from vllm.transformers_utils.chat_templates.registry import (
1144 + CHAT_TEMPLATES_DIR,
1145 )
1146
1147 + builtin_template_path = CHAT_TEMPLATES_DIR / chat_template
1148 + if not builtin_template_path.exists():
1149 + raise ValueError(
1150 + f"The supplied chat template string ({chat_template}) "
1151 + f"appears path-like, but doesn't exist! "
1152 + f"Tried: {chat_template} and {builtin_template_path}"
1153 + )
1154 +
1155 else:
1156 raise TypeError(f"{type(chat_template)} is not a valid chat template type")
1157
@@ -1173,12 +1181,23 @@ def _load_chat_template(
1181
1182 JINJA_CHARS = "{}\n"
1183 if not any(c in chat_template for c in JINJA_CHARS):
1176 - msg = (
1177 - f"The supplied chat template ({chat_template}) "
1178 - f"looks like a file path, but it failed to be "
1179 - f"opened. Reason: {e}"
1184 + # Try to load from the built-in templates directory
1185 + from vllm.transformers_utils.chat_templates.registry import (
1186 + CHAT_TEMPLATES_DIR,
1187 )
1181 - raise ValueError(msg) from e
1188 +
1189 + builtin_template_path = CHAT_TEMPLATES_DIR / chat_template
1190 + try:
1191 + with open(builtin_template_path) as f:
1192 + return f.read()
1193 + except OSError:
1194 + msg = (
1195 + f"The supplied chat template ({chat_template}) "
1196 + f"looks like a file path, but it failed to be opened. "
1197 + f"Tried: {chat_template} and {builtin_template_path}. "
1198 + f"Reason: {e}"
1199 + )
1200 + raise ValueError(msg) from e
1201
1202 # If opening a file fails, set chat template to be args to
1203 # ensure we decode so our escape are interpreted correctly