Repository navigation
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
Closed
philip-pentatonic wants to merge 1 commit into
philip-pentatonic wants to merge 1 commit into
Conversation
…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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_markersread only pairs that extend the render before them, never saw a user message, and returned no markers:resume_pointswas 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.
Qwen3.6-35B-A3B, revision 81169a9, NVIDIA PyTorch 26.07,
--context 8192, prompts fromtools/shared_prefix_prompts.py(the CPython standard library):"draft": false(token SHA-256)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) andtests/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) and Nemotron-Nano-9B-v2 (nemotron_h) gain resume points too.grid2048togrid2048+msg…), so snapshots already saved for them aren't reused.