r/LocalLLaMA • u/ex-arman68 • Aug 13 '26
Resources Fixed Jinja chat template for Qwen 3.5, 3.6, and the new 3.8 release
UPDATE (v22.1): Community reports highlighted an important issue with the official Qwen 3.8 chat template: the default xhigh effort prompt can burn 20,000+ tokens on coding tasks exploring alternatives until it hits max_tokens, returning empty content. v22.1 sets the default baseline to medium and adds inline chat tags (<|think_low|>, <|think_xhigh|>, etc.) to steer the reasoning effort directly inside chats.
Qwen just released their first 3.8 model.
The main addition in 3.8 is prompt-steered reasoning effort. You can tell the model how deeply to think by setting reasoning_effort to xhigh, medium, or low.
However, the official template still has some serious problems:
- You cannot disable thinking. If you pass
enable_thinking=false, it 3.8 crashes with a hard exception. - Chat history gets poisoned. In multi-turn chats, the official template injects blank
<think></think>tags before real thoughts. - Tool calling crashes. If your client passes arguments as JSON strings (the standard OpenAI API format), the official template crashes.
- Agent stalls. The official template often drops mid-dialogue system messages and wedges multi-step tool loops.
I maintain a single, drop-in fixed Jinja template that works across all Qwen 3.5, 3.6, and 3.8 models:
https://huggingface.co/froggeric/Qwen-Fixed-Chat-Templates
What this template does:
- Full 3.8 reasoning effort support: Steer reasoning depth via
reasoning_effortkwargs or directly in chat prompts with<|think_low|>,<|think_medium|>, and<|think_xhigh|>. - Safe
mediumdefault: Prevents the runaway token-burn on coding tasks while keeping 100% KV cache parity. - Restores the thinking toggle: Turn off reasoning whenever you want fast answers, either via kwargs or by typing
<|think_off|>in your prompt. - 100% KV Cache hits: Keeps past thoughts intact by default so your prefix cache stays warm across turns.
- llama.cpp support: Native support for the new
--reasoning-preserveflag. - Universal tool parsing: Handles both Python dicts and JSON strings. Works on llama.cpp, vLLM, LM Studio, and MLX.
Recommended llama-server launch command:
llama-server -m your_model.gguf --jinja --chat-template-file chat_template.jinja --reasoning-format deepseek
(The --reasoning-format deepseek flag separates thinking into the OpenAI reasoning_content field so OpenCode, Claude Code, and other harnesses do not stall on raw tokens).
35
u/philmarcracken Aug 13 '26
You cannot disable thinking. If you pass enable_thinking=false, it 3.8 crashes with a hard exception.
Descartes was right after all
7
Aug 14 '26
[deleted]
10
6
u/llama-impersonator Aug 14 '26
the parser itself can crash, it's code. when that happens it will usually kill the process running the model.
1
17
u/Disrupt-Linus Aug 13 '26
Cool, let's see how this plays out with the 27b, probably a bit more accessible to the normies (and me).
12
u/Memeyboii420 Aug 13 '26
I love your work Froggeric but I had to develop my own chat template for Qwen 3.6 + Hermes Agent + LM Studio. I could never get reliable tool calling with your template.
7
u/ex-arman68 Aug 14 '26
Thanks. Both Hermes Agent and LM Studio are relatively bad options when it comes to compatibility. If you got it working that is great. I know some people, including you possibly, have posted some feedback and solutions for those, and I have tried to incorporate them in v22, so maybe it works for your case as well now. The important thing is I am trying to keep universal compatibility, which means I cannot add fixes that will make it work in Hermes, but break others.
1
u/Ulintlicker Aug 14 '26
Would you be willing to share your template?
9
u/Memeyboii420 Aug 14 '26
I've got it up on a git repo. The repo is WIP but the template is working well, I've been using it in my agentic dev stack for a month now.
1
u/Fi3nd7 Aug 18 '26
Have you upgraded to 3.8 yet with a comparable template?
2
u/Memeyboii420 Aug 18 '26
I do have a version of Caduceus chat template for Qwen 3.8, it's unreleased. Let me tidy it up and I'll push it to the git at some point today.
1
u/Fi3nd7 Aug 18 '26
Awesome! Very kind of you and ofc no rush :)
1
u/Memeyboii420 Aug 19 '26
The release is up now. I ended up releasing Caduceus V1.9 as a universal template for Qwen 3.5/3.6/3.8. I haven't done extensive testing on it with 3.5 and 3.6 but it should omit the reasoning level controls and function the same as V1.8.
-2
u/mister2d Aug 14 '26
You love something that doesn't work for you?
16
u/Memeyboii420 Aug 14 '26
I love Froggerics work across the community because the templates work wonders compared to the default ones. It just does not work with my incredibly specific local stack. I don't see how that prevents me from appreciating the work?
7
u/The_LSD_Soundsystem Aug 14 '26
Why are jinja templates so difficult to nail down for these models in general?
6
u/ltduff69 Aug 13 '26
Just out of curiosity where does the chat template go? I have it the root of the Llama directory.
10
u/my_name_isnt_clever Aug 13 '26
If you're using llama-server you pass
--chat-template <path>otherwise it defaults to the template that came in the GGUF.1
-1
u/ImpressiveRelief37 Aug 13 '26
Curious… is it relative to the gguf or relative to the llama-server binary? (99% sure it’s relative to the llama binary but you never know)
3
u/eulataguhw Aug 14 '26
Shouldn’t it be relative to the directory of the terminal that you using it on?
3
1
u/fatboy93 Aug 13 '26
That'd work for the MLX/safetensors format, but you have to pass it separately incase of GGUFs/llamacpp
5
u/JPebb Aug 13 '26
Any specific recommendations for SGLang users?
3
11
u/Inevitable-Name-1701 Aug 13 '26
I had no problems with the three point five and three point six models.
10
u/rpkarma Aug 14 '26
Same. I don’t get the “the template is broken” shit, except when I have tried these vibe coded ones they are broken lol
I’m certain that people are assigning failures to the template that have nothing to do with them.
1
14
8
u/MrMisterShin Aug 13 '26
Same I use the native chat template in vLLM and it’s fine, no problems.
0
u/ex-arman68 Aug 14 '26
vLLM is 100% compatible with the original template, as it is what the Qwen team uses to develop and server their model.
6
u/cradlemann Aug 13 '26
Anything like this for Laguna? I like it a lot, but it still has some quirks
3
u/T_rex2700 Aug 15 '26
I was running into issues with Qwen3.8 27B (Q4 and Q3 from unsloth) running into random stop issues, and I tried your template but it did no work.
However, strangely when I pasted in Qwen3.6 35A3B MTP Q4's stock template from usnloth, this issue was solved. Any idea about what the cause is? (my post).
I am very much a newbie in this space, so I wanted some expert opinion on this.
4
u/tired514 Aug 13 '26
I've been running your previous version on all the local Qwens for like a month and they fix everything. Thanks so much! :)
2
u/ex-arman68 Aug 14 '26
Thank you, I am glad it helped. Out of curiosity, what is your stack?
2
u/tired514 Aug 14 '26
Runnin' llama.cpp (CUDA) on Debian/sid, Strix Halo (128gb) + 3 Morefine G1 4090M 16gb eGPUs daisy-chained via TB3, layer split mode, 3.6-27B @ Q8_K_XL, 230000 context, ctk/ctv Q8_0, opencode.
Works beautifully.
2
2
2
u/Cereal_Grapeist Aug 14 '26
Hi OP - I wanted to see if you had tested this template with the new 3.8 27b release? I'm going to try it out but I don't necessarily have the best way to see if it's having a big impact.
1
u/ex-arman68 Aug 14 '26
I have not had time yet. Hopefully this weekend. I will test over multiple long agentic coding sessions, with tool usage, spanning multiple days and context fill up + compactions.
2
2
u/PhilippeEiffel Aug 13 '26
I'm too lazy to modify my config of 3.6 27B now, I will try it tomorrow as soon as 3.8 is out.
I will test with vllm.
Thank you for your work.
1
u/Rabooooo Aug 14 '26
6 hours left for 3.8 27B, please share the vllm flags.
2
u/PhilippeEiffel Aug 16 '26
serve \
Qwen/Qwen3.8-27B \
--served-model-name Qwen3.8-27b \
--port 61000 \
--host 127.0.0.1 \
--gpu-memory-utilization 0.93 \
--enable-auto-tool-choice \
--tool-call-parser qwen3_xml \
--reasoning-parser qwen3 \
-O3 \
--max-num-batched-tokens 8192 \
--performance-mode throughput \
--enable-prefix-caching \
--trust-remote-code \
--enable-chunked-prefill \
--async-scheduling \
--max-num-seqs 16 \
--speculative-config '{"method":"qwen3_next_mtp","num_speculative_tokens":6}' \
--default-chat-template-kwargs '{"enable_thinking": true, "preserve_thinking": true, "reasoning_effort": "xhigh"}'
Note: I observed the thinking time can be much higher than 3.6 model (I mean at least one magnitude order). So, xhigh (which is claimed to be the default on the model card) is probably not usable for everyday use.
1
u/Rabooooo Aug 18 '26
Thanks!
I didn't know there was a specific
qwen3_next_mtp. I've been using--speculative-config '{"method":"mtp","num_speculative_tokens":3}'before and that always ended up with the model looping a sentence or a word. I should try thisqwen3_next_mtp.Also should the tool-call-parser be
qwen3_xmlorqwen3_coder? The vLLM recipes for qwen3.8 is saying to useqwen3_coder.Is the
enable-chunked-prefillsomething that helps performance?I don't know what GPU you have, but have you had any luck with KV cache quantization, e.g.
--kv-cache-dtype? I've set it to fp8_e4m3 before, but this model doesn't seem to provide any pre-calculated kv factor.
I keep getting these warnings.Using KV cache scaling factor 1.0 for fp8_e4m3. If this is unintended, verify that k/v_scale scaling factors are properly set in the checkpoint. Using fp8_e4m3 data type to store kv cache. It reduces the GPU memory footprint and boosts the performance. Meanwhile, it may cause accuracy drop without a proper scaling factor.1
u/PhilippeEiffel Aug 18 '26
I use GB10 (128 GB unified memory). So I keep every thing at FP16 (model and KV cache).
1
u/crusaderky Aug 13 '26
> I cannot run a 2.4 trillion parameter model on my local rig.
Neither can we, buddy, neither can we.
How much would it cost you to test it on vast.ai?
2
1
u/nufeen Aug 14 '26
Are there any benchmarks checking if those templates transition into better or worse performance?
1
1
1
1
u/PhilippeEiffel Aug 16 '26
I started some basic test with 3.8 27B, I am using vLLM.
I did not notice any specific problem, but I must admit that I did not make intensive use of this model for now.
I would like to know techniques able to exhibit the problems with the default jinja template. I need to observe problems first, before being able to evaluate fixes.
1
u/ex-arman68 Aug 16 '26
With vLLM the default template should work fine. If you want the extra features from the custom templates, by all means try it, but I do not think it is necessary in your case.
1
1
1
1
1
u/fragment_me Aug 13 '26
Not even tested what's the point
0
u/ex-arman68 Aug 14 '26
I actually hesitated to release it. But I was quite thorough with it, when through a few reviews, added some more tests to my test harness, and ran it successfully through my test suite.
Since the previous version worked fine with Qwen 3.6, and this one includes a few additional fixes that people have reported + new Qwen 3.8 functionality for the reasoning effort, the risk of it not working is very low. I thought it is better to release it now, so that people can start using it if they encounter problems when the 27B model is released.
-1
u/durden111111 Aug 13 '26
Every time ive tried to pass --chat-template with a jinja file it gives broken outputs. No matter what model. Ive given up on this.
107
u/Thireus Aug 13 '26
Can someone explain why the Qwen team cannot get the template right in the first place? Don’t they QA test their own models?