Skip to content

fix: message resume points for templates that drop a reply's think block from history - #83

Closed
philip-pentatonic wants to merge 1 commit into
ashhart:mainfrom
machinegenieorg:q36/qwen36-resume
Closed

philip-pentatonic wants to merge 1 commit into
ashhart:mainfrom
machinegenieorg:q36/qwen36-resume

Conversation

@philip-pentatonic

Copy link
Copy Markdown
Contributor

Qwen3.6's chat template, like Qwen3.5's, gives the reply after the last user message an empty think block and drops it once a user message follows. So the render of [user, reply] is no prefix of [user, reply, user]. message_markers read only pairs that extend the render before them, never saw a user message, and returned no markers: resume_points was None for Vontra/Qwen3.6-35B-A3B-MLX-4bit-MTP. The engine kept no state at the second message's start or the last assistant start, so prompts sharing a system block, and each chat turn, prefilled from scratch. The recipe's resume sentence did not hold.

A pair that does not extend now gives the new message from the only opener past where the two renders differ. Openers come from the pairs that do extend. Templates whose renders all extend take the same path as before. Qwen3.5 and 3.6 get Qwen3.8's markers.

Templates (CUDA and mlx_lm tokenizers) Before After
21 with markers (Qwen3.8, Flash Next, GLM-4.5–5.3, Gemma 2/3/4, Llama 3.x, Nemotron 3/3.5, Granite, Mistral, MiniMax, QwQ, Qwen2.5, SmolLM3) and the test fixtures markers unchanged
Qwen3.6, Qwen3.5 none `<
Qwen3, Nemotron-Nano-9B-v2, gpt-oss none their role opener and assistant header

Qwen3.6-35B-A3B, revision 81169a9, NVIDIA PyTorch 26.07, --context 8192, prompts from tools/shared_prefix_prompts.py (the CPython standard library):

GB10, 0.3.6.2 GB10, this PR RTX PRO 6000, 0.3.6.2 RTX PRO 6000, this PR
20 prompts sharing a 2,858-token system block: TTFT median of the 19 after the first 0.391 s 0.082 s 0.141 s 0.031 s
the cold first request 0.396 s 0.443 s 0.140 s 0.159 s
3-turn chats, turns 1 / 2 / 3 (median of 3) 0.367 / 0.421 / 0.466 s 0.446 / 0.148 / 0.148 s 0.131 / 0.151 / 0.170 s 0.161 / 0.056 / 0.057 s
drafted == "draft": false (token SHA-256) 49/49 49/49 49/49 49/49

Every reply's token SHA-256 is the same on both GPUs, before and after (49/49). A cold prompt pays for the states it now keeps, as extra prefill chunks: 47–79 ms on GB10 and 18–30 ms on the RTX PRO 6000.

Tests: tests/test_prefill_plan.py (Qwen3.6-like and Phi-like fakes) and tests/test_cuda_markers.py (a Qwen3.6-style Jinja template through the CUDA tokenizer path). The Qwen3.6 cases fail before and pass after. Full suite: 2186 passed, 413 skipped (macOS); the two files pass on GB10.

Notes:

  • Qwen3.5 (qwen3_5) and Nemotron-Nano-9B-v2 (nemotron_h) gain resume points too.
  • On the Mac, the snapshot key's plan name changes for templates that gained markers (grid2048 to grid2048+msg…), so snapshots already saved for them aren't reused.

…ock from history

Qwen3.5 and Qwen3.6 render the reply after the last user message with an empty think block and drop it
once a user message follows, so [user, reply] is no prefix of [user, reply, user]. message_markers only
read pairs that extend the render before them, found no user message, and returned no markers:
resume_points was None for Vontra/Qwen3.6-35B-A3B-MLX-4bit-MTP, so the engine kept no state at the second
message's start or the last assistant start. A prompt sharing a system block prefilled it again, and a
chat's next turn reused nothing.

A pair that does not extend now gives the new message from the only opener past where the two renders
differ, with openers read from the pairs that do extend. Qwen3.5 and 3.6 get Qwen3.8's markers
(<|im_start|>, and <|im_start|>assistant). Templates whose renders all extend take the same path as
before: markers are unchanged on the 21 templates that had them (29 checkpoints: Qwen3.8, Qwen3.8 Flash
Next, GLM-4.5 to 5.3, Gemma 2/3/4, Llama 3.1/3.2, Nemotron 3/3.5, Granite, Mistral, MiniMax, QwQ,
Qwen2.5, SmolLM3) and on the test fixtures. Qwen3, Nemotron-Nano-9B-v2 and gpt-oss, broken the same way,
get markers too.

Measured on an RTX PRO 6000 Blackwell Max-Q, Qwen3.6-35B-A3B at revision 81169a9, 20 chat prompts of
2,966-3,062 tokens sharing a 2,858-token system block: median time to first token 0.141 s -> 0.031 s
(2,858 tokens resumed); a 3-turn chat's turns 2 and 3: 0.151/0.170 s -> 0.056/0.057 s. A cold prompt
pays 18-30 ms for the states it keeps. Every drafted reply equaled its "draft": false reply (49/49).

Tests: tests/test_prefill_plan.py, tests/test_cuda_markers.py (a Qwen3.6-style Jinja template through the
CUDA tokenizer path); full suite 2186 passed, 413 skipped on macOS.
@ashhart

ashhart commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Landed in 0.4.0 as b29df86. Thank you! Qwen3.5 and Qwen3.6 chat templates now get the same resume points as Qwen3.8, so a second turn reuses the first.

@ashhart ashhart closed this Sep 29, 2026
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