server : move chat-template thinking probe inside the init try/catch (#24093)
A model whose chat template parses at init but fails parser generation
at apply time (e.g. uses {% call %}) throws std::invalid_argument from
common_chat_templates_support_enable_thinking(), which ran outside the
try/catch guarding common_chat_templates_init(). The throw was uncaught
and llama-cli aborted (SIGABRT) instead of failing to load. Moved the
probe inside that try/catch so an apply-time error fails load the same
way an init parse error does.
Signed-off-by: Jesse LaRose <jesse@taey.ai>
This commit is contained in:
@@ -1444,6 +1444,7 @@ private:
|
|||||||
// populate chat template params
|
// populate chat template params
|
||||||
{
|
{
|
||||||
common_chat_templates_ptr chat_templates;
|
common_chat_templates_ptr chat_templates;
|
||||||
|
bool enable_thinking = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
chat_templates = common_chat_templates_init(model_tgt, params_base.chat_template);
|
chat_templates = common_chat_templates_init(model_tgt, params_base.chat_template);
|
||||||
@@ -1451,6 +1452,12 @@ private:
|
|||||||
SRV_TRC("%s: chat template, example_format: '%s'\n", __func__,
|
SRV_TRC("%s: chat template, example_format: '%s'\n", __func__,
|
||||||
common_chat_format_example(chat_templates.get(), params_base.use_jinja, params_base.default_template_kwargs).c_str());
|
common_chat_format_example(chat_templates.get(), params_base.use_jinja, params_base.default_template_kwargs).c_str());
|
||||||
|
|
||||||
|
// thinking is enabled if:
|
||||||
|
// 1. It's not explicitly disabled via --reasoning off
|
||||||
|
// 2. The chat template supports it
|
||||||
|
const bool template_supports_thinking = params_base.use_jinja && common_chat_templates_support_enable_thinking(chat_templates.get());
|
||||||
|
enable_thinking = params_base.enable_reasoning != 0 && template_supports_thinking;
|
||||||
|
SRV_TRC("%s: chat template, thinking = %d\n", __func__, enable_thinking);
|
||||||
} catch (const std::exception & e) {
|
} catch (const std::exception & e) {
|
||||||
SRV_ERR("%s: chat template parsing error: %s\n", __func__, e.what());
|
SRV_ERR("%s: chat template parsing error: %s\n", __func__, e.what());
|
||||||
SRV_ERR("%s: please consider disabling jinja via --no-jinja, or use a custom chat template via --chat-template\n", __func__);
|
SRV_ERR("%s: please consider disabling jinja via --no-jinja, or use a custom chat template via --chat-template\n", __func__);
|
||||||
@@ -1458,13 +1465,6 @@ private:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// thinking is enabled if:
|
|
||||||
// 1. It's not explicitly disabled via --reasoning off
|
|
||||||
// 2. The chat template supports it
|
|
||||||
const bool template_supports_thinking = params_base.use_jinja && common_chat_templates_support_enable_thinking(chat_templates.get());
|
|
||||||
const bool enable_thinking = params_base.enable_reasoning != 0 && template_supports_thinking;
|
|
||||||
SRV_TRC("%s: chat template, thinking = %d\n", __func__, enable_thinking);
|
|
||||||
|
|
||||||
// IMPORTANT: chat_params is reused across sleeping / resuming states,
|
// IMPORTANT: chat_params is reused across sleeping / resuming states,
|
||||||
// never store llama_context/llama_model pointers in chat_params,
|
// never store llama_context/llama_model pointers in chat_params,
|
||||||
// as they may be invalidated after sleeping
|
// as they may be invalidated after sleeping
|
||||||
|
|||||||
Reference in New Issue
Block a user