Repository navigation
feat(kv-int8): a thinking budget ends thinking with the template close - #365
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
ef025f7 to
b93e8d6
Compare
736aa42 to
48f3c52
Compare
b93e8d6 to
1fb67c0
Compare
At load the tokenizer probes what the chat template writes after a reply's reasoning through its close (Qwen: "\n</think>"), as Splash's chat_templates._thinking_end and backend.thinking_end_tokens do. A close that holds another special token or more than 64 tokens fails the load; a template with no close ends thinking with the close token alone. Every decode path that cuts thinking (AR, decode_loop!, the qwen3_5 and MoE whole-turn cores, MTP, DSpark/DFlash2 verify, the hybrid scheduler and its speculation, the qwen3 scheduler) now forces that whole sequence one token per step, so the next request's re-render of the reply hits the paged prefix through the close. The single forced_token_id path is gone; reasoning_tokens counts budget + len(end) - 1 as Splash does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
48f3c52 to
42c28ea
Compare
Stage S32 of the Splash int8 KV alignment (stack #344). Base: S31 (#365). Models with gqa 16 (Qwen3.6-122B: 32 query / 2 KV heads, D 256) now default to int8 KV pages. Before this PR, `default_for_geometry` allowed int8 only up to gqa 8. ``` before: gqa <= 8 and whole groups ──► int8 gqa 16 ──► bf16 after: whole groups ──► int8 (122B window at 96 GiB: 118,393 ──► 262,137 tokens) ``` ## Why no tile parts Splash `SPLASH_ATTENTION_TILE_PARTS` splits the rows of one tile that packs 8 rows × every query head of a group, so that each part holds at most 64 packed (row, head) entries. The mlx-node pool kernels run one threadgroup for each query head and row. By Splash's own formula, each of them is already one part. The paged int8 reads map query head h to KV head h / gqa at any gqa, so the gqa ≤ 8 limit had no kernel reason. ## Changes - `default_for_geometry` (`transformer/kv_cache.rs`) needs only whole GQA groups. - The flat int8 cache (loads with no pool, MoE `generate_sync`, calibration prefills, training generation): `forward_int8_cached` takes the segmented kernels only for a block they can split (`rows <= 2 × max_q(gqa)`, new `segmented_int8_covers`). Any other block takes a dequantize route (below). Before, a 5..8-row block at gqa 16 threw "unsupported segmented SDPA verify block". The cache stays int8. - A 5..8-row verify that the segmented kernels cannot split (flat MTP at gqa 16, depth 4 or 5) dequantizes the cache's own rows `[0, P+T)`, so its new rows are read int8, as a 1-row decode reads them (Splash `PagedAttention::addVerify`: store, then attend). Prefill chunks keep the bf16 own-rows read; S10 owns that. - Doc text, generated TS types, CLI help and docs no longer say "GQA up to 8". - No Metal, C++ or metallib source changed. gqa ≤ 8 results stay bit-identical. ## Tests | test | clean | mutation (red) | |---|---|---| | `paged_int8_attention_gqa16` (32/2 at 300 / 600 / 17,000 / 33,000 tokens; 1, 2, 8, 64 rows) vs f64 reference | max ≤ 1.03, mean ≤ 0.13 bf16 ulps | G16 (heads 8+ read the next KV head): all 11 rows, 151–374 ulps; gqa ≤ 8 tests stay green | | `int8_adapter_reads_serve_gqa_16` (D256, 32/2) | max diff 0.125 | G16: diff 16.0 | | `eager_forward_over_an_int8_cache_tracks_the_bf16_cache` (adds 32x2) | worst 8.6e-3 | covers-check removed: the C++ throw | | `flat_int8_verify_at_gqa_16_reads_like_sequential_int8_decode` (32x2, 4..8 rows vs 1-row int8 decode, incl. V = [127, 0.5]) | ≤ 2 bf16 ulps | F1 (own rows read as bf16): verify 0.25 vs decode 0 | | 122B default, unset-format 32/2 rows, 122B estimate | green | D1 (keep `gqa <= 8`): red | - `cargo fmt --check`, `cargo clippy --all-targets -D warnings`, `cargo test -p mlx-paged-attn`, `yarn build:native`, `yarn typecheck`: clean. mlx-core `--lib` (`RUST_TEST_THREADS=1`): 4,767 passed, 0 failed. ## Gaps - At gqa 16 the pool reads run 16 threadgroups per KV head per decode row (128 per 8-row verify). Splash runs `_kv2_g16` as 2 parts. Its speed gain for parts is not captured here; it belongs to the S10 prefill split kernel and the compiled paged verify. - The grouped int8 route is enabled for 24/4 and 16/2, not 32/2. - Splash uses 32-token pages; mlx-node uses 16. - No gqa-16 checkpoint is on disk. The 122B window numbers come from a config-only fixture with Splash's Qwen3.5-122B-A10B geometry. - Out of scope, reported only: the MoE loader pins sym8 after the KV format. It matters only for a page size other than 16 or 32. ## Not in this PR (live, not run) - L0 download a 4-bit Qwen3.6-122B; L1 teacher-forced KL / top-1, int8 vs bf16 pages; L2 decode and verify speed, int8 vs bf16. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Stage S31 of the Splash int8 KV alignment (stack #344). Base: S8 (#364).
A thinking-budget cut now ends thinking with the chat template's own close, not with
</think>alone. The re-rendered history then has the same tokens as the reply, so the next turn's paged prefix hit goes through the forced close.Changes
thinking_end_tokens/_thinking_end): every tokenizer renders a 4-message conversation, slices from the end of the reasoning through the first</think>, and encodes it. The close must end with</think>, have no other added token, and be at most 64 tokens, or the load fails. A template with no close falls back to</think>alone, as Splash does.from_tokenizernow returnsResult.NativeBackend._thinking_budget,commitSelected): the end advances when a token is observed. A forced token is handed out only when no forced token is in flight. While thinking ends, the unforced budget is 0, with no drafts and no pipelining. A token past the budget is adebug_assert, because Splash throws there.decode_loop!, MTP, DSpark/DFlash2, the qwen3 scheduler, hybrid scheduler AR rows and scheduled speculation, the qwen3_5 and MoE whole-turn cores, and every family with a thinking budget. Speculative paths commit each forced token through its own one-row cycle, so their tokens and KV are the same as AR.forced_token_id,should_force_think_end,force_think_end_pending,end_scheduled,from_setup_multi.Probe survey (local templates, tokenizer only)
"\n</think>""</think>"No local template fails the load. Qwen3 also moves to
"\n</think>". This is deliberate.Gaps
also_endsrule: a<tool_call>opened inside a cut still gets the close after it. This was true before S31 too. There is no--thinking-end-textflag.docs/vllm_reasoning_control_flow_spec_for_mlx_node.mdstill describes the old single-token design (historical spec).Tests
</think>alone and the re-rendered history splits at the cut).tracker_ends_thinking_with_the_whole_close,probe_finds_the_template_close(Qwen3.8 + a new Qwen3.6 template fixture),probe_falls_back_and_refuses_a_bad_close,budget_cut_rerender_hits_through_the_close,scheduled_rows_end_thinking_with_the_whole_close,legacy_dense_cores_end_thinking_with_the_whole_closeanddecode_loop_ends_thinking_with_the_whole_close.cargo fmt --check,cargo clippy --all-targets -D warnings,yarn build:native,yarn typecheck,vp lint/vp fmton the touched files: clean. mlx-core--lib(RUST_TEST_THREADS=1): 4,762 passed, 0 failed.yarn build:native,yarn typecheckclean; mlx-core--lib4,764 passed, 0 failedNot in this PR (live, not run)
🤖 Generated with Claude Code