@@ -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