Repository navigation
feat(kv-int8): the paged pool follows kv_format; delete paged FP8 - #362
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 93509f32cc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 88c2bd8e66
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
4addf95 to
a45a2e7
Compare
59a0cb3 to
024c989
Compare
a45a2e7 to
244ed11
Compare
The qwen3_5 and qwen3_5_moe block-paged pools take int8 or bf16 pages from kv_format (int8 by default where the kernels serve the model, as Splash --kv-format). An explicit int8 the kernels cannot serve fails the load. The memory plan, runway and transient follow the pool format, and int8 varlen prefill tiles its rows so its workspace stays bounded at any history. An int8 pool errors instead of taking the legacy write or the host read. The GDN sidecar is labelled with the activation dtype, so the cold tier stays on for an int8 pool; int8 blocks round-trip it with their scales. kv_format is never saved. Every non-DFlash2 turn takes one pool window; a load with MTP heads prices the MTP state into it once. mlx eval reads the pool on a paged load. Paged FP8 is deleted (Rust, C++, Metal, tests, docs); kv_dtype code 2 is refused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e load The estimate pinned kv_format with BF16 compute, and since the pool follows the format, an f16 checkpoint was priced with an int8 pool that the load never builds. An explicit int8 also passed the estimate, but the load refuses it. checkpoint_compute_dtype reads the safetensors headers, or the GGUF import's dtypes (imported_dtypes), and maps them onto the sanitizers' keys. It then applies the loaders' own rule: compute_dtype_of for dense, settled_compute_dtype (the MoE affine alignment) for MoE. The format pin, the pool dtype and the lane dtype all use the result. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The estimate charged the MTP state whenever config.json declared MTP layers, but the load turns the head off when its weights are incomplete (and for sym8, and for K-quant MoE). /v1/models then under-reported the window, and a max_context the load accepts could be refused. checkpoint_header (was checkpoint_compute_dtype) keeps the sanitized mtp.* keys from the same header pass: inline, else the dense sidecar, else the split drafter; MoE expert keys take the switch_mlp names (mtp_expert_keys). One completeness rule, missing_mtp_keys, now serves the estimate, the drafter merge and both loaders; the dense loader's own copy is deleted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
024c989 to
4c801c5
Compare
Stage FN2 of the Splash int8 KV alignment (stack #344). Base: S7 (#362). The Flash Next (`qwen4_exp`) paged pool takes its page format from `kv_format`, and its pages take Splash's layout. ``` kv_format unset ──► int8 if head 128/256 (every real Flash Next checkpoint), else bf16 kv_format int8 ──► int8, or the load fails page (Splash kv::Layout) K, V token-major [nb, H, bs, D] + int8 scale planes + bf16 index plane ``` ## Changes - **Format:** `Config.kv_format` (never saved) is set at load by `resolve_kv_format`. It does not use `default_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). - **Page layout** (Splash `kv::Layout` `valuesTokenMajor` / `indexDimension`): `LayerKVPool::new_with_layout`. - K and V are token-major, written by new `_vt` store variants (int8 hd128/256, bf16), as Splash's `_store_kv2_vt` stores do. - The index keys move into a bf16 plane inside the pool block (`PagedIndexStore`; plane row = page · rows + block % rows, as Splash `indexer_index_keys` does). The plane grows, shrinks, moves and stays resident with the K/V planes. - A pool block now costs exactly the priced page: int8 423,936 B, bf16 811,008 B. - Host transfers, `write_kv`, `gather_attention` and the dense gather refuse a token-major page. - **Gathers:** `mlx_qwen4_gather_pages` and `mlx_qwen4_gather_window` read 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. - **One window:** the pool lane charges the MTP state (`draft_state_bytes(W)`) once. `mtp_window` and `PoolPlan::window_with` are deleted. The limits publish `kv_format`. - **Plan:** the layout, runway (int8 256 pages, bf16 96) and extents follow the format. - **Decode and verify store before they read** (Splash `PagedAttention::addVerify`): `attention_projected` writes 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. - **TS:** `qwen4_exp` accepts `kvFormat`. The loader and the server estimate pass it on. ## Windows (Splash's 36 GB M5 Max input) | load | window | pool pages | expert cap (B) | |---|---|---|---| | bf16, no MTP (before) | 65,536 | 2,080 | 14,459,363,158 | | int8, no MTP | 65,536 | 2,304 | 15,228,690,262 | | int8, MTP, one window | 65,536 | 2,304 | 14,497,648,470 | 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 - S10: the prefill window (`attention_window`, the `batch.rs` fallback) reads the current chunk's own rows unquantized, so window-prefill logits depend on the chunking. - S26: SSD spill, slot records with scales. Until then a token-major page refuses every host transfer (qwen4 has no cold tier). - S17: the pool grows by 128 MiB extents, not Splash's 256-page extents. - S20: the MTP draft state is priced at the window. Splash's lane is 2 GDN cells + DFlash2 rings + a fixed draft window. - qwen4_exp has no `mlx eval` backend, so the KL gate is an ignored Rust test. ## Tests - 14 named mutations (G1, D1, D2, W1, O1, O2, V1, K1, X1, I1, H1 and two TS checks went red; G2 stays green because MLX runs the pending write before the gather, recorded). - `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). - mlx-paged-attn: 16 binaries, 324 passed. mlx-core `--lib` (`RUST_TEST_THREADS=1`): 4,884 passed, 0 failed. `vp test` model-loader-gguf + inference-host: 83 passed. ## Not in this PR (live, not run) - L0 sanity, L1 teacher-forced KL int8 vs bf16 pool, L2 AR speed at 8K and 32K, L3 one MTP turn. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Stage S7 of the Splash int8 KV alignment (stack #344). Base: S6 (#361).
The qwen3_5 and qwen3_5_moe paged pools take their page format from
kv_format, as Splash--kv-formatdoes. The default is int8 where the kernels serve the model.Changes
kvRunwayPages: 275 blocks for bf16 (unchanged), 546 for int8.PagedAttention::prefillWorkspacedoes. Each row's math is unchanged. This removes the 87,040-token cap (130,560 on the 35B) and the hostread_kv_rangefallback past it. An int8 pool returns errors instead of taking the legacy write or the host read.CACHE_ABIchange).PoolInput.state). DFlash2 keeps its own window until S8.mlx evalreads pages on a paged load (paged_teacher_forced_hidden, dense and MoE), so the live KL gate runs the production path.kv_dtypecode 2 is refused.Int8keeps code 3.kv_formatis never saved to a config.Window (27B, M3 Pro inputs)
MLX_CONTINUOUS_BATCHING=1Gaps
held_bytes(W)is.QwenTarget::addPrefillMixer). Somlx evalon rows that fit one chunk scores int8 like bf16.Tests
cargo fmt --check,cargo clippy --all-targets -D warnings,yarn build:native,yarn typecheck: clean.--lib(RUST_TEST_THREADS=1): 4,879 passed, 0 failed.vp testcli eval / serve / agent-args: 122 passed.Not in this PR (live, not run)
mlx eval.🤖 Generated with Claude Code