AI 模型未必出錯:Hugging Face 上的 GGUF 檔案可能帶有過時聊天模板
Your AI Model Isn't Broken. The File You Downloaded Is Out of Date.
作者檢查 Hugging Face 上六個熱門模型的 1,788 份 GGUF 上傳檔,並以 643 份原模型純重新打包檔分析,發現四個系列的大部分下載版本帶有不同於現行官方版本的聊天模板。
I checked 1,788 copies of six popular models on Hugging Face. Many carry an old chat layout that can crash some apps or hide the AI's tools. Here's how to check yours.
A note on how I made this: AI tools helped me run these tests and draft this article. The ideas are my own.
If you run AI models on your own computer, you've probably downloaded one from Hugging Face. Search for a popular model like Qwen3-8B and you'll find hundreds of copies, uploaded by different people. Same name, same size. It's natural to assume they're the same thing.
They aren't. Each download is a single file that holds two things: the model itself, and a small piece of code that decides how your conversation gets written out for the model to read.
Picture a restaurant. The model is the chef. Your app (Ollama, LM Studio, or your own code) is the waiter. The waiter writes every order on a ticket, and the chef can only read tickets in one exact layout. That ticket layout comes printed inside the model file. Engineers call it the chat template.
Model makers sometimes improve the ticket layout after release, for example by adding a box for special requests. Copies uploaded before the change keep the old layout forever.
Here's what that looks like in practice. Ask Mistral 7B "What's the weather in Adelaide?" and give it a weather tool. With the current layout, the model reads this (simplified):
[AVAILABLE_TOOLS] get_weather(city) [/AVAILABLE_TOOLS]
[INST] What is the weather in Adelaide right now? [/INST]
With the old layout, which is in the most downloaded copies, it reads this:
[INST] What is the weather in Adelaide right now? [/INST]
The tool is simply gone. No error, no warning. The chef never hears about the special request.
I wanted to know how many people are downloading old layouts, and whether it actually changes what the AI does. I tested two common ways to run these files: llama.cpp, and Python code (Hugging Face's transformers library and llama-cpp-python). Ollama and LM Studio have their own template handling, and I didn't test them directly.
In short
- I checked 1,788 uploaded copies of six popular models and kept the 643 clean copies of the original models (the rest are fine-tunes and remixes). For four of the six models, most downloads get a chat layout that differs from the official one today.
- Even Qwen's own official download of Qwen3-8B has an outdated layout. In Python apps it crashes the moment the AI uses a tool. In llama.cpp it works fine.
- For Mistral 7B, the outdated layout hides the AI's tools completely. The same file made 0 correct tool calls out of 60. With the current layout, it made 55.
- The model files themselves, from eight different uploaders, scored almost exactly the same. The layout is what makes the difference.
- The fix is simple, but it depends on how you run the model. I show it at the end, with a one-command check for your own downloads.
How the chat layout works
In engineering terms: the ticket layout is the chat template, and the model file is a GGUF file, the format most local AI apps use. Here is how the two fit together.
Your app sends a list of messages: a system prompt, a user turn, maybe a tool call and its result. The model never sees that list. It sees one long string, laid out in exactly the format it was trained on, with special tokens like <|im_start|> or [INST] in the right places.
The chat template is the small Jinja program that builds that string. The model's authors ship it in the base repo, in tokenizer_config.json or chat_template.jinja. When someone converts the model to GGUF, the template gets copied into the file as tokenizer.chat_template. From then on, the GGUF carries its own copy, frozen at the moment of conversion.
Base repos don't stand still. Authors fix templates after release: a crash on some message shape, a tool-calling format, a whitespace bug. The base repo gets the fix. The GGUF copies don't, unless someone re-uploads them.
So the question is simple: how many GGUF downloads carry a template that builds a different prompt from the one the authors ship today?
How I tested it
The Hub API can return the GGUF metadata for every repo in one listing call, template included. For six popular open model families, I pulled every upload tagged as a quantisation of the base model:
| Family | GGUF uploads | Pure repacks |
|---|---|---|
| Qwen3.8-27B | 813 | 188 |
| Qwen2.5-7B-Instruct | 280 | 90 |
| Qwen3-8B | 270 | 103 |
| Mistral-7B-Instruct-v0.3 | 195 | 134 |
| Phi-4-mini-instruct | 126 | 88 |
| gpt-oss-20b | 104 | 40 |
| Total | 1,788 | 643 |
The tag is set by uploaders, and plenty of fine-tunes, merges and uncensored variants use it too. Those are different models, so I kept only pure repacks, the clean copies: repos whose name is the base model's name plus quantisation words and nothing else. Every headline number below uses those 643 uploads, weighted by their downloads over the last 30 days.
Then, for each family, I walked the base repo's commit history and pulled every version of the official template. That matters: an upload that matches an older official template is stale, not edited, and those are very different stories.
Text comparison turned out to be useless on its own. Unsloth's Qwen3-8B template is 737 characters longer than the current base template, but it builds the same prompt. So I rendered every template against 12 test conversations: a plain question, a system prompt, multi-turn chat, tool definitions, a tool call and its result, parallel calls, thinking switched off, earlier reasoning in the history, and a tool call with null content (which is what the OpenAI API returns, and what most agent loops send straight back).
I rendered each template twice, in two engines:
-
Python Jinja, set up the way
transformersdoes it.llama-cpp-pythonuses the same approach, and it reads the template straight from the GGUF. -
llama.cpp itself (build b12359), through
llama-server's/apply-templateendpoint.
To make sure the API wasn't lying to me, I also read the real file header of 20 uploads with HTTP range requests. All 20 matched the API's template exactly.
Here's the overall result before the details. Each bar is one model, and the colours show how many of its downloads build the official prompt in each engine.
Qwen3-8B: even the official download is out of date
Here's the line that breaks. This is from the template Qwen shipped with Qwen3-8B on 28 April 2025:
{%- if '</think>' in message.content %}
When message.content is null, which it is for an assistant turn that only calls a tool, Python can't run in on it. On 19 May 2025, Qwen fixed the base repo:
{%- if message.content is string %}
{%- set content = message.content %}
{%- else %}
{%- set content = '' %}
{%- endif %}
The fix never reached Qwen/Qwen3-8B-GGUF, Qwen's own GGUF repo. It still carries the April template, and it's by far the most downloaded Qwen3-8B GGUF: 848,856 downloads in the last 30 days.
I checked this with the real libraries, not just my own renderer. With the current base template, transformers 5.24.0 renders the conversation fine. With the template inside Qwen's GGUF, it fails:
UndefinedError: 'dict object' has no attribute 'content'
llama-cpp-python 0.3.38, which takes its template from the GGUF by default, fails too:
TypeError: argument of type 'NoneType' is not iterable
The two errors look different because transformers removes the empty content field before it renders, so the template finds no content at all, while llama-cpp-python passes it on as None. It's the same bug: the old template expects every assistant turn to have text.
Across all Qwen3-8B pure repacks, 84% of downloads carry the stale template. In a Python Jinja stack (transformers, llama-cpp-python, or anything built on them), every one of them breaks the first time your agent sends back a tool call with null content, which is exactly what OpenAI-style clients do.
Then I ran the same templates through llama.cpp, and every one of them worked. llama.cpp's own Jinja engine detects what a template can and can't handle and fills the gaps itself, so the stale template builds exactly the same prompt as the fixed one. If you run Qwen3-8B in llama-server, or anything else that uses llama.cpp's own template engine, this bug never touches you.
That's the pattern for the whole study: whether a stale template hurts you depends on the engine you run it in.
The old template isn't going away, either. 17 Qwen3-8B uploads created after the fix still carry it. Since January 2026 a new one has appeared every month or so, the newest on 6 November 2026.
The two grey dots before the fix are Unsloth and ggml-org. ggml-org later updated its file to Qwen's fixed template, and Unsloth's file has its own edits that build the same prompt as the fix.
Mistral 7B: your tools disappear
Mistral's case is worse, because llama.cpp can't save it.
Mistral updated the v0.3 template five times between May and August 2024. The two most downloaded GGUF uploads (MaziyarPanahi with 60,608 downloads, lmstudio-community with 11,100) still carry the very first version from 22 May 2024. Across all pure repacks, 97% of downloads use a stale Mistral template. Only about 3% get the current one.
In Python Jinja, the old template rejects any system prompt:
TemplateError: Conversation roles must alternate user/assistant/user/assistant/...
llama.cpp handles that one by folding the system prompt into the first user turn. But the old template predates Mistral's tool format, and that's where it goes quiet. Send a request with tools and llama.cpp builds a prompt with no tools in it at all. No [AVAILABLE_TOOLS] block, no warning, no error. The model never learns the tools exist. Send a conversation that contains a tool result and you get this instead:
HTTP 400: Unable to generate parser for this template.
So with the most popular Mistral uploads, tool calling doesn't fail loudly. It just never happens.
Qwen2.5-7B: out of date by one day
Qwen's own Qwen2.5-7B-Instruct-GGUF (786,204 downloads) carries a template from 18 September 2024. The base repo replaced it the next day. The version in the GGUF shows the model a tool-call example with doubled braces:
{{"name": <function-name>, "arguments": <args-json-object>}}
instead of:
{"name": <function-name>, "arguments": <args-json-object>}
Both engines build the prompt with the doubled braces, so this one reaches everyone: 70% of Qwen2.5-7B GGUF downloads. Whether it changes how well the model calls tools is a question for the next section.
gpt-oss-20b: three versions in circulation
OpenAI's template for gpt-oss went through four versions in its first week. The GGUF uploads froze at different points:
-
ggml-org/gpt-oss-20b-GGUF(453,209 downloads) matches the current template. -
unsloth/gpt-oss-20b-GGUF(598,365) has its own edits. -
lmstudio-community(122,051) andbartowski(14,319) carry the 5 August 2025 version.
The differences are small but real. The current official template puts a blank line after the system message and passes a tool's result as an escaped JSON string. Unsloth's passes the raw JSON. lmstudio's and bartowski's add a blank line at the start of the tools block. One upload drops the Reasoning: medium line completely. 62% of gpt-oss-20b downloads build a different prompt from the current official template, in both engines.
The models without the problem
Not every family has this problem. Qwen3.8-27B is the most downloaded model in the study, with 13.8 million downloads of its clean copies in 30 days. Every one of those copies that carries a template builds exactly the official prompt: 183 of 188, and the other 5 have no template at all. So do all 88 Phi-4-mini uploads. Phi-4-mini's template never changed. Qwen3.8-27B's was fixed on release day itself, before the wave of uploads, and its one later edit didn't change any prompt I tested.
That's the real lesson. The risk isn't GGUF, and it isn't any one uploader. It's a template that changed after the first wave of uploads. Uploads made in the first week after a release end up with most of the downloads: 99% for Qwen3-8B, Qwen2.5-7B and gpt-oss-20b, 92% for Mistral and 90% for Qwen3.8-27B. That first week is exactly when authors are still fixing their templates.
Does it matter who uploaded the file?
Here's a small sign of how different these "identical" downloads are. I took the ten most downloaded Qwen3-8B files of the same type (Q4_K_M, a common 4-bit compression level) and computed their digital fingerprints (SHA-256 hashes). Ten files, ten different fingerprints.
A file's fingerprint covers everything in it, so part of that is metadata: the template text, the model name, notes from the uploader. Different fingerprints don't prove different weights. But each uploader can also compress the model in a different way, and llama.cpp builds exactly the same prompt from every clean Qwen3-8B copy, so any difference in the answers comes from the weights. Does it change the answers?
I ran Qwen's larger Q8_0 file as a reference, plus eight Q4_K_M files from different uploaders, on an RTX 5090 desktop. Same llama.cpp build, same settings with randomness switched off, Qwen's thinking mode off, and the same 300 tasks:
- 100 GSM8K maths problems
- 100 IFEval instruction-following prompts, graded with Google's checker code
- 60 BFCL function-calling tasks
- 20 multi-turn conversations with a system rule that has to hold for three turns
- 20 conversations where the model has to report a value from a tool's result
| File | Size | Score (300 tasks) | Tokens/s |
|---|---|---|---|
| Qwen Q8_0 (reference) | 8.71 GB | 92.7% | 165 |
| Qwen (official) | 5.03 GB | 92.0% | 241 |
| unsloth | 5.03 GB | 92.0% | 243 |
| MaziyarPanahi | 5.03 GB | 92.0% | 243 |
| bartowski | 5.03 GB | 91.0% | 243 |
| lmstudio-community | 5.03 GB | 92.0% | 243 |
| Aldaris | 5.03 GB | 92.0% | 243 |
| mradermacher | 5.03 GB | 92.3% | 243 |
| eaddario | 4.48 GB | 91.0% | 262 |
Every Q4_K_M file scored between 91.0% and 92.3%, and the Q8_0 reference scored 92.7%. None of those gaps is statistically significant with 300 tasks: the smallest p-value against the reference is 0.18, and the usual bar is 0.05.
The files don't write word-for-word the same answers, though. The runs themselves are repeatable: Qwen's own file, run twice with the same settings, gave identical replies on all 300 tasks. Most pairs of different files gave identical replies on only 23% to 34% of tasks, mostly the short function calls, and each file got 9 to 13 tasks right or wrong differently from the reference. A rerun changes nothing, so those differences come from the compression itself. They go both ways, so the scores barely move. Two uploads, Aldaris and MaziyarPanahi, gave identical replies on all 300 tasks, so their weights are effectively the same, with different metadata around them.
One useful detail: eaddario's file is 11% smaller and about 8% faster than the rest, with the same score.
So for Qwen3-8B, which uploader compressed the model barely matters. Which template you end up with is a different story.
Does an outdated layout change the answers?
For the three families where llama.cpp builds a different prompt, I kept the file fixed and swapped only the template:
-
Mistral-7B v0.3 (lmstudio-community
Q4_K_M): its own stale template against the current official one. -
Qwen2.5-7B (MaziyarPanahi
Q4_K_M, stale): the doubled-brace template against the current one. - gpt-oss-20b (ggml-org's file, current template): the official template against Unsloth's.
Mistral: same weights, two different products. With the template inside the file, the model made zero tool calls in 60 function-calling tasks. It answered in prose, or wrote Python that called nothing. All 20 conversations that contained a tool result came back as HTTP 400. With the current official template swapped in, the same file made a tool call in all 60 tasks, 55 of them correct, and used the tool result correctly in all 20 conversations. Over its 100 tasks (60 function calls, 20 tool results and 20 multi-turn chats), the score went from 12% to 87%: 78 tasks went from wrong to right, and 3 the other way. Rule-keeping across multi-turn chats stayed at 60% either way, because llama.cpp patches the system prompt into the old template.
Qwen2.5 and gpt-oss: nothing I could measure. With the doubled braces, Qwen2.5 actually got one more function-calling task right than with the current template (77 of 80 tasks against 76 of 80, p = 1.0). That isn't a significant difference. gpt-oss scored 92 of 100 with both templates, and not one task changed from right to wrong or back. The wording changed on some replies (95% and 65% stayed identical), but whether the answer was right didn't.
That's the clearest result in the whole study. A template difference in formatting, like whitespace, braces or how a tool result is quoted, didn't change anything I measured. A template difference in capability, like a tool format the template doesn't know, switches the feature off completely. In llama.cpp it does that without an error.
How to avoid it
The short version: check what a template can do, not how it looks. A template that differs by a blank line is probably fine. A template that predates tools, or crashes on null content, isn't.
If you run GGUF models in Python (llama-cpp-python, or your own Jinja), assume the template in the file can be stale. Pass the base model's template explicitly instead of trusting the file. In llama-cpp-python:
from llama_cpp import Llama
from llama_cpp.llama_chat_format import Jinja2ChatFormatter
template = open("chat_template.jinja").read() # from the base model repo
llm = Llama(model_path="Qwen3-8B-Q4_K_M.gguf")
llm.chat_handler = Jinja2ChatFormatter(
template=template, eos_token="<|im_end|>", bos_token="<|endoftext|>"
).to_chat_handler()
If you run llama.cpp, you're protected from crashes, not from differences. For tool calling, pass the base template with --chat-template-file, and check the prompt it builds for one of your real requests:
llama-server -m model.gguf --jinja --chat-template-file chat_template.jinja
curl -s localhost:8080/apply-template -d @my_request.json | jq -r .prompt
If you use Ollama or LM Studio, I didn't test them, because they handle templates their own way. A quick check still works: give the model a tool, ask a question that needs it, and see whether it calls the tool. If it never does, compare its template with the base repo's.
Before you pick an upload, check its template against the base repo's. I turned my scripts into a one-command checker that does this for any GGUF repo on Hugging Face, or a file you already have:
uv run check_template.py bartowski/Qwen_Qwen3-8B-GGUF
It tells you if the template is up to date, out of date (and since when) or edited, and shows which kinds of conversation break. Add --save chat_template.jinja and it writes the current official template, ready for --chat-template-file.
If you upload GGUFs, re-check your template when the base repo changes it. It's a metadata edit, not a re-quantisation.
And one suggestion for the Hub: it already parses the template out of every GGUF. A small "template differs from base model" note on the model page would catch every case in this article.
Limits
- "Pure repack" is a name rule. It's conservative, and it surely misses a few real repacks and lets a few renamed models through.
- Downloads are the Hub's 30-day counts on 23 November 2026, so the shares will move.
- I tested Python Jinja and one llama.cpp build. I didn't test Ollama, which converts templates to its own format, or LM Studio's MLX path.
- The 12 test conversations cover common shapes, not every one. A template can still differ on a message shape I didn't try.
- Some uploaders edit templates on purpose, to fix engine bugs or add features. "Different" isn't automatically worse, and the answer tests back that up.
- Each file ran once. A repeat run of Qwen's file gave identical replies on all 300 tasks, so reruns add no noise, but 300 tasks is still a small sample: gaps of a point or two in the table aren't statistically significant.
- The multi-turn and tool-result groups have 20 tasks each, so their intervals are wide.
- In the uploader test, 37 replies hit my 2,048-token length limit. 36 of them came from IFEval prompts that ask for very long answers, and only one was a real repetition loop.
- BFCL grading is a simpler version of BFCL's own checker: the function name, argument values from the accepted list, and optional arguments.
- The uploader test covers one model at one compression level. Smaller, more compressed files may separate the uploaders more.
Code and data
Everything is on GitHub at github.com/vanshaj1999/gguf-template-check: the checker, the Hub scan, the renderer, the llama.cpp check, the header check, the benchmark harness and every raw result.
來源:DEV Community · dev.to


