Skip to content

Commit 5783575

Browse files
authored
Fix chatml fallback for unsupported builtin templates (when --jinja not enabled) (#11533)
1 parent 4a2b196 commit 5783575

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

examples/server/server.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,12 @@ struct server_context {
18581858
llama_init_dft.context.reset();
18591859
}
18601860

1861-
chat_templates = common_chat_templates_from_model(model, params_base.chat_template);
1861+
if (params_base.chat_template.empty() && !validate_builtin_chat_template(params.use_jinja)) {
1862+
LOG_WRN("%s: The chat template that comes with this model is not yet supported, falling back to chatml. This may cause the model to output suboptimal responses\n", __func__);
1863+
chat_templates = common_chat_templates_from_model(model, "chatml");
1864+
} else {
1865+
chat_templates = common_chat_templates_from_model(model, params_base.chat_template);
1866+
}
18621867
GGML_ASSERT(chat_templates.template_default.get() != nullptr);
18631868

18641869
return true;
@@ -4435,14 +4440,6 @@ int main(int argc, char ** argv) {
44354440

44364441
LOG_INF("%s: model loaded\n", __func__);
44374442

4438-
// if a custom chat template is not supplied, we will use the one that comes with the model (if any)
4439-
if (params.chat_template.empty()) {
4440-
if (!ctx_server.validate_builtin_chat_template(params.use_jinja)) {
4441-
LOG_WRN("%s: The chat template that comes with this model is not yet supported, falling back to chatml. This may cause the model to output suboptimal responses\n", __func__);
4442-
params.chat_template = "chatml";
4443-
}
4444-
}
4445-
44464443
// print sample chat example to make it clear which template is used
44474444
LOG_INF("%s: chat template, chat_template: %s, example_format: '%s'\n", __func__,
44484445
ctx_server.chat_templates.template_default->source().c_str(),

0 commit comments

Comments
 (0)