diff --git a/common/arg.cpp b/common/arg.cpp index 79405b59e..2669cacd6 100644 --- a/common/arg.cpp +++ b/common/arg.cpp @@ -960,6 +960,11 @@ static bool common_params_parse_ex(int argc, char ** argv, common_params_context )); } + // if the preserve_reasoning kwarg was not specified explicitly, enable it by default + if (!params.default_template_kwargs.count("preserve_reasoning")) { + params.default_template_kwargs["preserve_reasoning"] = "true"; + } + return true; } @@ -3553,6 +3558,10 @@ common_params_context common_params_parser_init(common_params & params, llama_ex LOG_WRN("Setting 'enable_thinking' via --chat-template-kwargs is deprecated. " "Use --reasoning on / --reasoning off instead.\n"); } + if (item.key() == "preserve_reasoning") { + LOG_WRN("Setting 'preserve_reasoning' via --chat-template-kwargs is deprecated. " + "Use --reasoning-preserve / --no-reasoning-preserve instead.\n"); + } params.default_template_kwargs[item.key()] = item.value().dump(); } } @@ -3743,7 +3752,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex add_opt(common_arg( {"--reasoning-preserve"}, {"--no-reasoning-preserve"}, - "preserve reasoning trace in the full history, not just the last assistant message (default: template default)\n" + "preserve reasoning trace in the full history, not just the last assistant message (default: enabled)\n" "compatible with certain templates having 'supports_preserve_reasoning' capability\n" "example: https://docs.z.ai/guides/capabilities/thinking-mode#preserved-thinking", [](common_params & params, bool value) { @@ -3752,6 +3761,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex } else { params.default_template_kwargs["preserve_reasoning"] = "false"; } + params.preserve_reasoning_specified = true; } ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_REASONING_PRESERVE")); add_opt(common_arg( diff --git a/common/common.h b/common/common.h index 4e9448bb1..63d0badd0 100644 --- a/common/common.h +++ b/common/common.h @@ -270,7 +270,7 @@ struct common_params_sampling { COMMON_SAMPLER_TYPE_TEMPERATURE, }; - common_grammar grammar; // optional grammar constraint (user / output-format / tool-calls) + common_grammar grammar; // optional grammar constraint (user / output-format / tool-calls) bool grammar_lazy = false; std::vector grammar_triggers; // optional triggers (for lazy grammars) std::set preserved_tokens; @@ -657,6 +657,7 @@ struct common_params { std::string ssl_file_cert = ""; // NOLINT std::map default_template_kwargs; + bool preserve_reasoning_specified = false; // CLI params std::string server_base; // if set, connect to this server instead of starting a new one diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index f5477356d..f78cfb36d 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -1493,11 +1493,22 @@ private: auto caps = common_chat_templates_get_caps(chat_params.tmpls.get()); auto it = params_base.default_template_kwargs.find("preserve_reasoning"); bool supported = caps.at("supports_preserve_reasoning"); - bool enabled = it != params_base.default_template_kwargs.end(); + bool specified = params_base.preserve_reasoning_specified; + // note: the kwarg is enabled by default if not specified explicitly, so check the value + bool enabled = it != params_base.default_template_kwargs.end() && it->second == "true"; + if (supported) { + SRV_TRC("preserve_reasoning kwarg: %s\n", + it == params_base.default_template_kwargs.end() ? "unset (template default)" : it->second.c_str()); + } else { + SRV_TRC("%s", "preserve_reasoning kwarg: not supported by template\n"); + } + if (supported && !specified) { + SRV_WRN("%s", "chat template supports preserving reasoning, it is enabled by default (may use more tokens, disable via --no-reasoning-preserve)\n"); + } if (supported && !enabled) { SRV_INF("%s", "chat template supports preserving reasoning, consider enabling it via --reasoning-preserve\n"); } - if (!supported && enabled) { + if (!supported && specified && enabled) { SRV_WRN("%s", "chat template does NOT support preserving reasoning, --reasoning-preserve has no effect\n"); } }