Skip to content

Commit 9ae3c55

Browse files
authored
SigLIP example add chat_template (#29902)
Signed-off-by: piood <[email protected]>
1 parent 9bcf922 commit 9ae3c55

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

examples/pooling/embed/openai_chat_embedding_client_for_multimodal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def run_siglip(client: OpenAI, model: str):
150150
Start the server using:
151151
152152
vllm serve google/siglip-base-patch16-224 \
153-
--runner pooling
153+
--runner pooling \
154+
--chat-template template_basic.jinja
154155
"""
155156

156157
response = create_chat_embeddings(

vllm/entrypoints/chat_utils.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,11 +1139,19 @@ def validate_chat_template(chat_template: Path | str | None):
11391139
not any(c in chat_template for c in JINJA_CHARS)
11401140
and not Path(chat_template).exists()
11411141
):
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,
11451145
)
11461146

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+
11471155
else:
11481156
raise TypeError(f"{type(chat_template)} is not a valid chat template type")
11491157

@@ -1173,12 +1181,23 @@ def _load_chat_template(
11731181

11741182
JINJA_CHARS = "{}\n"
11751183
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,
11801187
)
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
11821201

11831202
# If opening a file fails, set chat template to be args to
11841203
# ensure we decode so our escape are interpreted correctly

0 commit comments

Comments
 (0)