Repository navigation
Description
Environment
- Unsloth Studio
2026.10.8, Windows 11, desktop app (unsloth studio --api-only -H 127.0.0.1 -p 8888) - llama-server
b11798-ec0da70e9(bundled,~/.unsloth/llama.cpp/build/bin/Release/llama-server.exe) - Model:
unsloth/Qwen3.8-27B-GGUF:UD-Q5_K_S, custom chat template set through
app_settings.openai_api_auto_switch_overrides["unsloth/Qwen3.8-27B-GGUF:UD-Q5_K_S"].chat_template_override - Client: opencode 2.1.4 against
http://127.0.0.1:8888/v1(an ordinary API client, not the Studio chat UI)
Summary
For any model whose identifier matches qwen3.8, Studio appends --chat-template-kwargs {"preserve_thinking": true} to the llama-server launch line (core/inference/llama_cpp.py:3182, :3369, :31922-31924). Because that value is part of the launch default template kwargs, llama-server defines preserve_thinking for every request on that port. Consequences:
- A user-supplied
chat_template_overridethat decides for itself — e.g.{%- if preserve_thinking|default(false) or loop.index0 > ns.last_query_index %}— can never take its own default, because the variable is always defined. The template is silently neutralised. --no-reasoning-preserve(the documented llama.cpp knob, and the one the server itself tells you to use: "disable via --no-reasoning-preserve") has no effect. Passing it throughllama_extra_argschanges nothing.- There is no Studio setting to turn the launch default off:
preserve_thinking_defaultis derived only from the model-name regex, and the chat-sidepreserveThinkingpreference is forwarded per request by the Studio frontend, so it never reaches API clients.
Net effect for agent clients: every request re-sends the reasoning of all previous turns. In a coding agent this grew the prompt from 41k → 79k → 88k tokens within one session and forced auto-compaction (measured: a 409 s compaction pass with cache.read=0).
I understand this default is deliberate — #9096 follows Qwen's documented default for Qwen3.8 — so this is not a request to change the default. It is a request to make it overridable and to stop it from silently beating the user's own template.
Reproduction
- Set a custom template on a
qwen3.8model containing the line above (preserve_thinking|default(false)), and reload the model. - Confirm the launch line carries both
--chat-template-kwargs {"preserve_thinking": true}and (optionally)--no-reasoning-preserve; the server logschat template supports preserving reasoning, it is enabled by default. - Render a prompt with a historical assistant turn carrying
reasoning_content:
POST http://127.0.0.1:<port>/apply-template
{"messages": [
{"role": "user", "content": "q1"},
{"role": "assistant", "content": "a1", "reasoning_content": "MARKER"},
{"role": "user", "content": "q2"}
]}
body -> MARKER present: True (len 142)
+ chat_template_kwargs {"preserve_thinking": false} -> MARKER present: False (len 117)
+ chat_template_kwargs {"preserve_reasoning": false} -> MARKER present: True (len 142, ignored)
+ chat_template_kwargs {"preserve_reasoning": "false"} -> MARKER present: True (len 142, ignored)
The template itself is correct: rendered offline with the sandboxed Jinja environment, the same messages produce no <think> block with no kwarg, and block(s) with preserve_thinking=true.
--no-reasoning-preserve writes preserve_reasoning (common/arg.cpp:3793-3805 → caps_apply_preserve_reasoning, common/chat.cpp:993), but common_chat_template_direct_apply_impl then calls jinja::global_from_json(ctx, inp) after that, which re-applies preserve_thinking: true from --chat-template-kwargs (common/chat.cpp:993-1009). So a launch-time chat_template_kwargs entry always wins over --no-reasoning-preserve.
Suggested fix (any one of these)
- Prefer the user's template: when
chat_template_overrideis set by the user, do not emitpreserve_thinkingin--chat-template-kwargs, and let the template decide its own default. - Or expose a per-model
preserve_thinkingkey in the launch overrides (openai_api_auto_switch_overrides, next tocustom_context_length/reasoning_budget), keeping the Qwen3.8 default as the initial value. - Or make the chat-surface
preserveThinkingpreference also drive the launch default for that model, instead of being a per-request value only.
Workaround (for anyone hitting this now)
Every API client must send the override per request:
// opencode.json, per model
"body": { "chat_template_kwargs": { "preserve_thinking": false } }chat_template_kwargs is honoured on the chat-completions routes (_normalize_chat_reasoning_controls, routes/inference.py:32444), so this reaches llama-server — verified above. Clients that cannot send extra body fields are stuck with the default.
Activity
debojyoti-dev commentedon Oct 24, 2026
I'm working on this. Plan: honour --reasoning-preserve / --no-reasoning-preserve (and LLAMA_ARG_REASONING_PRESERVE) when building the launch preserve_thinking kwarg, and stop forcing the Qwen3.8 default onto a chat_template_override so it falls back to the off default.
danielhanchen commentedon Oct 25, 2026
Fixed! Studio's launch-time
preserve_thinkingvalue now follows--no-reasoning-preserve/--reasoning-preservein your extra args (orLLAMA_ARG_REASONING_PRESERVE), and a custom chat template gets the default its own text sets, so yourpreserve_thinking|default(false)template no longer replays old reasoning to API clients. Fixed in #15170.To update: Unsloth Desktop will have an update banner. For Studio, use
unsloth studio update. For Docker, usedocker exec <container> unsloth-studio-update. Reopen if it still happens.Studio: let --no-reasoning-preserve and a custom chat template turn o…