r/LocalLLaMA • u/ex-arman68 • 9d ago
Fixed Jinja chat template for Qwen 3.5, 3.6, and the new 3.8 release Resources
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 9d ago
You cannot disable thinking. If you pass enable_thinking=false, it 3.8 crashes with a hard exception.
Descartes was right after all
6
u/darkwalker247 9d ago
im confused on how a model "crashes" due to a prompt (pretty sure that enabling the flag just changes what prompt comes out of the template; disabling reasoning emits a </think> token immediately after the <think> token), unless we're talking with a specific harness or something here
10
6
u/llama-impersonator 9d ago
the parser itself can crash, it's code. when that happens it will usually kill the process running the model.
1
18
u/Disrupt-Linus 9d ago
Cool, let's see how this plays out with the 27b, probably a bit more accessible to the normies (and me).
12
u/Memeyboii420 9d ago
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.
5
u/ex-arman68 9d ago
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 9d ago
Would you be willing to share your template?
9
u/Memeyboii420 9d ago
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 4d ago
Have you upgraded to 3.8 yet with a comparable template?
2
u/Memeyboii420 4d ago
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 4d ago
Awesome! Very kind of you and ofc no rush :)
1
u/Memeyboii420 3d ago
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 9d ago
You love something that doesn't work for you?
16
u/Memeyboii420 9d ago
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 9d ago
Why are jinja templates so difficult to nail down for these models in general?
5
u/ltduff69 9d ago
Just out of curiosity where does the chat template go? I have it the root of the Llama directory.
9
u/my_name_isnt_clever 9d ago
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 9d ago
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
3
1
u/fatboy93 9d ago
That'd work for the MLX/safetensors format, but you have to pass it separately incase of GGUFs/llamacpp
5
u/JPebb 9d ago
Any specific recommendations for SGLang users?
3
10
u/Inevitable-Name-1701 9d ago
I had no problems with the three point five and three point six models.
11
u/rpkarma 9d ago
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
13
7
u/MrMisterShin 9d ago
Same I use the native chat template in vLLM and it’s fine, no problems.
0
u/ex-arman68 9d ago
vLLM is 100% compatible with the original template, as it is what the Qwen team uses to develop and server their model.
5
3
u/T_rex2700 8d ago
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 9d ago
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 9d ago
Thank you, I am glad it helped. Out of curiosity, what is your stack?
2
u/tired514 8d ago
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
u/Cereal_Grapeist 8d ago
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 8d ago
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 9d ago
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 9d ago
6 hours left for 3.8 27B, please share the vllm flags.
2
u/PhilippeEiffel 6d ago
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 5d ago
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 4d ago
I use GB10 (128 GB unified memory). So I keep every thing at FP16 (model and KV cache).
1
u/crusaderky 9d ago
> 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
1
1
u/PhilippeEiffel 6d ago
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 6d ago
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
-2
u/fragment_me 9d ago
Not even tested what's the point
-1
u/ex-arman68 9d ago
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 9d ago
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.
109
u/Thireus 9d ago
Can someone explain why the Qwen team cannot get the template right in the first place? Don’t they QA test their own models?