Commit 919794500 for llama.cpp
commit 919794500475862f6768c353255469dc661cb734
Author: Xuan-Son Nguyen <son@huggingface.co>
Date: Fri Nov 20 20:54:57 2026 +0100
convert: qwen3-asr: put "language ..." output into thinking block (#32571)
* convert: qwen3-asr: put "language ..." output into thinking block
* convert: qwen3-asr: read the chat template from models/templates
The converter embedded its own copy of Qwen3-ASR.jinja. Read the
bundled file instead, as the Kimi-K3 and Kokoro converters do, so
the GGUF and test-chat share a single template.
---------
Co-authored-by: Pascal <admin@serveurperso.com>
diff --git a/conversion/qwen3vl.py b/conversion/qwen3vl.py
index 9458366b1..c15959bc4 100644
--- a/conversion/qwen3vl.py
+++ b/conversion/qwen3vl.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import json
+from pathlib import Path
from typing import Any, Callable, Iterable, TYPE_CHECKING
if TYPE_CHECKING:
@@ -393,8 +394,10 @@ class Qwen3ASRTextModel(Qwen3VLTextModel):
def set_vocab(self):
super().set_vocab()
- # fix chat template, use correct chatml format
- self.gguf_writer.add_chat_template("{% for message in messages %}{{'<|im_start|>' + message['role'] + '\\n' + message['content'] + '<|im_end|>' + '\\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\\n' }}{% endif %}")
+ # the model outputs "language <lang><asr_text><transcript>", the template renders the language prefix as reasoning_content
+ # so that the chat parser can separate it from the transcript
+ template_path = Path(__file__).parent.parent / "models" / "templates" / "Qwen3-ASR.jinja"
+ self.gguf_writer.add_chat_template(template_path.read_text(encoding="utf-8"))
# correct BOS/EOS tokens
with open(self.dir_model / "tokenizer_config.json", "r", encoding="utf-8") as f:
tokenizer_config = json.load(f)
diff --git a/models/templates/Qwen3-ASR.jinja b/models/templates/Qwen3-ASR.jinja
new file mode 100644
index 000000000..0342d9e7e
--- /dev/null
+++ b/models/templates/Qwen3-ASR.jinja
@@ -0,0 +1,8 @@
+{%- for message in messages -%}
+{{- '<|im_start|>' + message.role + '\n' -}}
+{%- if message.role == 'assistant' and message.reasoning_content is defined and message.reasoning_content -%}
+{{- message.reasoning_content + '<asr_text>' -}}
+{%- endif -%}
+{{- message.content + '<|im_end|>\n' -}}
+{%- endfor -%}
+{%- if add_generation_prompt -%}{{- '<|im_start|>assistant\n' -}}{%- endif -%}
diff --git a/tests/test-chat.cpp b/tests/test-chat.cpp
index efffae530..302ef319f 100644
--- a/tests/test-chat.cpp
+++ b/tests/test-chat.cpp
@@ -7006,6 +7006,28 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
.run();
}
+ // Qwen3-ASR: "language <lang><asr_text><transcript>", the language prefix is delimiter-style reasoning
+ {
+ auto tst = peg_tester("models/templates/Qwen3-ASR.jinja", detailed_debug);
+
+ tst.test("language English<asr_text>And so, my fellow Americans, ask not.")
+ .reasoning_format(COMMON_REASONING_FORMAT_AUTO)
+ .expect(simple_assist_msg("And so, my fellow Americans, ask not.", "language English"))
+ .expect_reconstruction()
+ .run();
+
+ tst.test("language None<asr_text>")
+ .reasoning_format(COMMON_REASONING_FORMAT_AUTO)
+ .expect(simple_assist_msg("", "language None"))
+ .run();
+
+ // reasoning_format none keeps the raw output
+ tst.test("language English<asr_text>Hello")
+ .reasoning_format(COMMON_REASONING_FORMAT_NONE)
+ .expect_content("language English<asr_text>Hello")
+ .run();
+ }
+
// Mistral Small 3.2 - FUNC_BRACKET_TAG format: [TOOL_CALLS]func_name[CALL_ID]id[ARGS]{...}
{
auto tst = peg_tester("models/templates/Mistral-Small-3.2-24B-Instruct-2506.jinja", detailed_debug);
diff --git a/tools/server/server-task.cpp b/tools/server/server-task.cpp
index 9b2ba5ac5..595e57ffb 100644
--- a/tools/server/server-task.cpp
+++ b/tools/server/server-task.cpp
@@ -1327,11 +1327,17 @@ json server_task_result_cmpl_partial::to_json_oaicompat_resp() {
}
json server_task_result_cmpl_partial::to_json_oaicompat_asr() {
- json event = json {
- {"type", "transcript.text.delta"},
- {"delta", content.text},
- };
- return event;
+ // only the parsed content is the transcript, e.g. the "language XXX" prefix of Qwen3-ASR is reasoning
+ json events = json::array();
+ for (const auto & diff : oaicompat_msg_diffs) {
+ if (!diff.content_delta.empty()) {
+ events.push_back({
+ {"type", "transcript.text.delta"},
+ {"delta", diff.content_delta},
+ });
+ }
+ }
+ return events;
}
json server_task_result_cmpl_partial::to_json_anthropic() {