Repository navigation
feat(kv-int8): the Flash Next pool follows kv_format - #363
Conversation
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. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
56a979f to
d0d71b7
Compare
024c989 to
4c801c5
Compare
qwen4_exp takes kvFormat: int8 by default where the int8 page kernels serve the head (128 or 256), bf16 elsewhere; an explicit int8 they cannot serve fails the load. The pool uses Splash's Flash Next page: K and V token-major (new _vt store instances, int8 and bf16) and a bf16 index plane of the indexer's pooled block keys inside the block, so a pool block is the priced page (int8 423,936 B, bf16 811,008 B). The qwen4 page gathers read the token-major page and dequantize int8 rows to BF16 with their scales. The plan and the load-free estimate price the format's page and runway. A load with MTP weights has one lane and one window: the MTP draft state is charged once in the plan, and PoolPlan::window_with and the speculative window fields are gone. The TS loader, server estimate and CLI pass kvFormat to qwen4_exp. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A decode step and every MTP verify row write their K/V row to the pages before attention and read every selected row, their own included, back from the pages (Splash PagedAttention::addVerify, "Encode the store before attention"). On an int8 pool a verify row read its window's earlier rows unquantized while AR read them as int8, so MTP could change greedy tokens. The prefill window keeps its fresh rows (S10). Co-Authored-By: Claude Opus 5.5 <[email protected]>
d0d71b7 to
7834c3f
Compare
Stage S8 of the Splash int8 KV alignment (stack #344). Base: FN2 (#363). DFlash2 on qwen3_5 and qwen3_5_moe verifies on the paged pool (int8 by default), as Splash does. The flat DFlash2 lane is deleted, and every turn kind shares one pool window. ``` before: DFlash2 turn ──► flat K/V + flat compiled verify ──► own window (32,761) after: DFlash2 turn ──► paged pool (int8) ──► anchor + 7 rows, one 8-row verify ──► the one pool window (94,201) ``` ## Changes - **Turn on the pool:** dense and MoE DFlash2 plans publish `supports_paged_attention: true`. `run_paged_turn` sends DFlash2 to `run_paged_dspark_turn`. The shared driver uses `args.params` (so the window clamp holds) and gets two hooks whose defaults keep gemma4 unchanged. - **Verify** (Splash `QwenTarget` verify, `PagedAttention::addVerify`): the draft always proposes the full block (7). Every cycle verifies anchor + 7 = 8 rows. `run_paged_dflash2_verify_step` refuses a chunk that is not 8 rows, or a page table shorter than committed + 8, with the Splash error text. - **Booking:** each cycle books committed + 8 and commits through `open_core_write_cycle` / `commit_cycle`. The cursor moves back 8 − keep, and no page is freed. The DFlash2 prefill books each chunk end (Splash `Engine::workEndOf`; `exactTokens` leaves out the pending anchor). GDN blob adopt/commit stays, with `replay_mtp_snapshot_to(paged = true)` as the fallback. Each DFlash2 prefill chunk books through `reclaiming` (Splash `Engine::growLane` → `Engine::allocate` frees, then retries). A cold DFlash2 prime keeps no prefix chain, so marked checkpoint pages can be reclaimed. - **MoE:** the row budget reaches the paged verify as `row_budget`, clamped to min(budget, 1 + L). - **One window:** with a draft, the pool lane also charges the DFlash2 state (a second GDN cell + the draft ring, 201,273,344 B). The transient is the larger of the tapped prefill chunk and the 8-row verify cycle with its free pool. - **Load:** a DFlash2 companion with no pool fails the load (CUDA, dense sym8, paged cache off). Splash has no flat path. - **Deleted:** the flat DFlash2 turn, its KV booking and growth, parking, the flat compiled verify (`forward_dflash2_compiled`, `COMPILED_VERIFY_*`) and its Rust helpers, MoE deferred GDN, the `MLX_MOE_DFLASH2_*` env switches, the separate speculative window, the runway hold, and the speculative fields of the published limits (napi + TS). ## Window (27B + DFlash2, M3 Pro inputs) | turn | before | after | |---|---|---| | DFlash2 | 32,761 | 94,201 | | AR / MTP / image, on a load with a draft | 102,393 | 94,201 | 6,391 blocks (3,245 MiB). The S4 live capacity gate (LIVE L4) checks this number on the real load. ## Gaps - **Speed is not measured.** The flat compiled verify took the flat K/V as graph inputs, so it could not stay as an A/B arm. The eager paged verify reads the device ids back to the host and never adopts the GDN blobs. If LIVE L3 is below 0.90× of the FN2 build, RULES #9 says: build the compiled paged verify (one fixed 8-row tape) before this merges. The plan is in LIVE.md. - **S8 and S9 must merge together.** Until S9, parked DFlash2 states have no store on the pool. An AR, image or MTP turn drops the live draft window, and a prefix hit without it prefills the draft from 0. The store code stays, unused, for S9. The 13 scheduler tests over parked states and `dflash2_state/tests.rs` are deleted (each one drove a flat DFlash2 turn); S9 brings them back. - A turn that ends on the length budget runs one extra 1-row forward, so the last token has a KV row. Splash emits that token without a KV row. - A refused verify or prefill booking after reclaim fails the turn. Splash waits or suspends (S11). - The AR prefill still books the whole prompt (S11). - The MoE bitwise row-budget test needs a quantized grouped MoE fixture. The clamp is tested. - `mlx_segmented_sdpa_forward` (bf16 segmented verify, C++/Metal) has no library caller now. Its deletion needs a metallib rebuild (follow-up). ## Tests - 21 named mutations, each red when on and green when off (M1 M2 A1 R1 K1 P1 T0 L1 MM1 B2 W1 W2 T1 C1 LB1 NP1 O3 C11 W0 R0, and R1 of the reclaim fix: `cold_dflash2_prefill_reclaims_a_marked_live_chain`, dense and MoE). - New tests include `paged_dflash2_matches_paged_ar_for_every_keep` (dense and MoE), `dflash2_cycle_runs_eight_rows_and_commits_keep`, `paged_dflash2_verify_refuses_a_chunk_that_is_not_eight_rows`, `dflash2_prefill_books_each_chunk_end`, `dflash2_takes_the_one_pool_window`, `draft_without_a_pool_is_refused` and `second_dflash2_turn_resumes_the_live_window`. - `cargo fmt --check`, `cargo clippy --all-targets -D warnings`, `yarn build:native`, `yarn typecheck`: clean. - mlx-paged-attn: 16 binaries, 324 passed. mlx-core `--lib` (`RUST_TEST_THREADS=1`): 4,753 passed, 0 failed. `vp test` on the 7 touched TS test files: 605 passed. - Reclaim fix (ef025f7): qwen3_5, qwen3_5_moe, engine, transformer::paged: 1,321 passed, 0 failed. - After the rebase onto FN2 56a979f: fmt, clippy, `yarn build:native`, `yarn typecheck` clean; qwen4_exp 238, qwen3_5 445, qwen3_5_moe 139, engine 543, transformer::paged 192 passed ## Not in this PR (live, not run) - L0 sanity, L1 lossless DFlash2 vs AR on the pool, L2 teacher-forced acceptance against the FN2 build, L3 speed at 8K and 64K (RULES #9 gate), L4 S4 capacity at the M3 Pro budget. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Stage FN2 of the Splash int8 KV alignment (stack #344). Base: S7 (#362).
The Flash Next (
qwen4_exp) paged pool takes its page format fromkv_format, and its pages take Splash's layout.Changes
Config.kv_format(never saved) is set at load byresolve_kv_format. It does not usedefault_for_geometry, because that needs GQA ≤ 8 and Flash Next has GQA 12. No new kernel instance is needed (H 2, D 256, bs 32).kv::LayoutvaluesTokenMajor/indexDimension):LayerKVPool::new_with_layout._vtstore variants (int8 hd128/256, bf16), as Splash's_store_kv2_vtstores do.PagedIndexStore; plane row = page · rows + block % rows, as Splashindexer_index_keysdoes). The plane grows, shrinks, moves and stays resident with the K/V planes.write_kv,gather_attentionand the dense gather refuse a token-major page.mlx_qwen4_gather_pagesandmlx_qwen4_gather_windowread token-major pages. On an int8 pool they unpack K with x = 16, read the f32 scale planes and return bf16. The S5 refusals are deleted.draft_state_bytes(W)) once.mtp_windowandPoolPlan::window_withare deleted. The limits publishkv_format.PagedAttention::addVerify):attention_projectedwrites the row to the pool, then reads every row back from pages, the current row too. An MTP verify row now reads its window exactly as AR decode does, so speculation stays lossless on an int8 pool. AR numerics on an int8 pool change (the current row is read as int8, as in Splash); bf16 pools are bit-identical.qwen4_expacceptskvFormat. The loader and the server estimate pass it on.Windows (Splash's 36 GB M5 Max input)
On an MTP load the window drops from 95,225 to 65,536, and the bytes go to the expert store. This is Splash's one-lane rule. With a 128 GiB working set the window is 262,144 in both formats.
Gaps
attention_window, thebatch.rsfallback) reads the current chunk's own rows unquantized, so window-prefill logits depend on the chunking.mlx evalbackend, so the KL gate is an ignored Rust test.Tests
cargo fmt --check,cargo clippy --all-targets -D warnings,yarn build:native,yarn typecheck: clean (re-run after the rebase onto S7 59a0cb3, with the touched modules: qwen4_exp 237, load_plan 23, memory_plan 31, mtp_drafter 24, persistence 44 + 28, paged_construction 99, gguf_import 26, transformer::paged 193).--lib(RUST_TEST_THREADS=1): 4,884 passed, 0 failed.vp testmodel-loader-gguf + inference-host: 83 passed.Not in this PR (live, not run)
🤖 Generated with Claude Code