Skip to content

qwen36: decode the non-special added tokens (think and tool tags) - #1724

Merged
JustVugg merged 2 commits into
devfrom
fix/qwen36-decode-added-tokens
Sep 23, 2026
Merged

JustVugg merged 2 commits into
devfrom
fix/qwen36-decode-added-tokens

Conversation

@JustVugg

Copy link
Copy Markdown
Owner

The decoder half of #1723 (GenericRikka), split out so it can ship in 1.12.1 while the tool-calling half is rebased.

The bug, on dev. Qwen3.6's tokenizer.json keeps <think>, </think>, <tool_call>, </tool_call>, <tool_response> and </tool_response> only in added_tokens, not in model.vocab. load_tokenizer built the id-to-piece table from model.vocab alone, so those ids decoded to zero bytes. The gateway splits reasoning from the answer on </think> in the engine's text, so with thinking on the closing tag never arrived and the whole answer was returned as reasoning_content.

What changes.

  • GenericRikka's commit: the decoder table also takes added_tokens, and a real-adapter test pins the six protocol tokens against the full tokenizer.
  • One commit on top: only the non-special added tokens are decoded. <|im_start|>, <|endoftext|> and <|im_end|> are special: true and keep decoding to nothing, as on dev; without this the chat markers showed up in generated text.

Measured on the real Qwen3.6-35B-A3B (ds, 60 tokens, What is 2+2? Answer briefly.): dev prints the answer with the think block missing; with this PR the output carries <think>\n\n</think> before 4, and no <|im_start|> or <|endoftext|> appears, exactly as on dev. test_qwen36_tokenizer passes.

GenericRikka and others added 2 commits September 23, 2026 23:22
Include tokenizer.json added_tokens in the ID-to-piece table so
generated protocol tokens such as </think> and <tool_call> survive
detokenization.
<think>, </think>, <tool_call> and <tool_response> are text the gateway
parses. Special tokens (<|im_start|>, <|endoftext|>, <|im_end|>) keep
decoding to nothing, as on dev and as reference decoding does with
skip_special_tokens; decoding them would put chat markers in the text a
client receives.
@JustVugg
JustVugg merged commit 20183ac into dev Sep 23, 2026
29 checks passed
JustVugg added a commit that referenced this pull request Sep 23, 2026
GenericRikka pushed a commit to GenericRikka/colibri that referenced this pull request Sep 24, 2026
@JustVugg
JustVugg deleted the fix/qwen36-decode-added-tokens branch September 24, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants