Repository navigation
feat(kv-int8): paged attention reads the int8 pool - #361
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
|
4addf95 to
a45a2e7
Compare
7613a32 to
f2e9d03
Compare
The paged attention kernels (v1, v2, varlen, and the grouped Qwen3.5 D256 route) read int8 pages with their per-row scales in Splash order: key scale then Scale on the score, P = bf16(p * value scale) with masked tokens exactly zero, f32 PV products and f32 partials combined in partition order. The read validators take the scale planes and the int8 refusals are gone. The dense gather and read_kv_range dequantize int8 rows with the flat cache's op (now head size 128 or 256); the raw decode route sends int8 through the graph op; an int8 pool always takes the varlen cache-hit prefill. Pool planes are bound with a budget of the distinct blocks the tables reach, so a big pool no longer commits after every read. The default pool stays bf16. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A dense int8 gather that covers one page reshapes V without a copy, so the rows reach the dequantize kernel with a head-dimension stride of the block size. The kernel read src[j] and mixed neighbouring tokens; its validator checked the strides of a lazy array, which are always row-major. The kernel now reads at q_strides[3], so every caller is correct without an extra copy. Tests: a strided-input op test (D 128 and 256, lazy and evaluated) and one-page dense gather parity for block sizes 16 and 32 against the flat int8 rows. Mutation U1 (stride 1 reads) turns both red. Co-Authored-By: Claude Opus 5.5 <[email protected]>
a45a2e7 to
244ed11
Compare
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-format` does. The default is int8 where the kernels serve the model. ``` kv_format unset ──► int8 if head 128/256, block 16/32, BF16 compute, else bf16 kv_format int8 ──► int8, or the load fails (Splash compiledAttention refuses a layout with no kernel) kv_format bf16 ──► bf16 ``` ## Changes - **Pool format:** the pool, the memory plan (layout, bytes per block, transient) and the load-free estimate follow the format. The runway uses Splash `kvRunwayPages`: 275 blocks for bf16 (unchanged), 546 for int8. - **Int8 varlen prefill tiles its query rows** (rows × partitions ≤ 2,048), as Splash `PagedAttention::prefillWorkspace` does. Each row's math is unchanged. This removes the 87,040-token cap (130,560 on the 35B) and the host `read_kv_range` fallback past it. An int8 pool returns errors instead of taking the legacy write or the host read. - **GDN sidecar:** the sidecar is labelled with the activation dtype, not the pool dtype. Before this, an int8 pool turned off the whole cold tier with no log. Int8 blocks round-trip the cold tier with their scales (S5 blob layout, no `CACHE_ABI` change). - **One window:** every non-DFlash2 turn takes the pool window. A load with MTP heads prices the MTP state into it once (`PoolInput.state`). DFlash2 keeps its own window until S8. - **`mlx eval` reads pages** on a paged load (`paged_teacher_forced_hidden`, dense and MoE), so the live KL gate runs the production path. - **Paged FP8 is deleted** (Rust, C++, Metal, tests, docs). `kv_dtype` code 2 is refused. `Int8` keeps code 3. - `kv_format` is never saved to a config. - The load-free context estimate reads the compute dtype from the checkpoint header (safetensors header or GGUF import types), with the same rule as the load. An f16 checkpoint no longer shows an int8-sized window that its load (bf16 pages) cannot serve. ## Window (27B, M3 Pro inputs) | case | window (tokens) | |---|---| | bf16 pool, no MTP (before) | 48,601 | | int8 pool, no MTP | 102,393 | | int8 pool, MTP, serial | 55,207 | | int8 pool, MTP, `MLX_CONTINUOUS_BATCHING=1` | 20,473 | | DFlash2 lane (unchanged) | 32,761 | ## Gaps - The serial paged-MTP prompt-hidden capture is not priced or capped. Only `held_bytes(W)` is. - With continuous batching, the MTP state is charged both outside and inside the pool (S11). - The int8 prefill tile count grows with context (S10). - The first prefill chunk (no prefix) attends over the in-flight bf16 K/V, not its own int8 pages (S10, Splash `QwenTarget::addPrefillMixer`). So `mlx eval` on rows that fit one chunk scores int8 like bf16. - No MoE twins for the pool-format, sidecar and eval tests. The sidecar test covers capture only. ## Tests - 15 named mutations, each red when on and green when off (D1–D3, S1, W1, W2, B1, K1, V1, C1, G1, P1, O1, O2, E1). - `cargo fmt --check`, `cargo clippy --all-targets -D warnings`, `yarn build:native`, `yarn typecheck`: clean. - mlx-paged-attn: 15 binaries + doctests, 323 passed. mlx-core `--lib` (`RUST_TEST_THREADS=1`): 4,879 passed, 0 failed. `vp test` cli eval / serve / agent-args: 122 passed. ## Not in this PR (live, not run) - L1: teacher-forced KL on qwen3.8-27b, int8 pages vs bf16 pages, through `mlx eval`. - L2: native-MTP acceptance. L3: speed at 8K and 32K. L4: an image turn. L5: a 35B turn. L6: a prompt past the old 87,040 cap. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Stage S6 of the Splash int8 KV alignment (stack #344). Base: S5 (#360).
Paged attention reads the int8 pool, with Splash's op order (
splash_attention_page_softmax). Only tests build an int8 pool; S7 makes the pool followkv_format.Changes
paged_attention.metal: int8 generic and varlen kernels (D128/D256, bs16/bs32), int8 reducers, and a grouped D256 bs16 int8 kernel. Scale planes use buffers 6 and 7. The Qwen3.5 grouped gate accepts Int8.mlx_paged_ops.cpp: onevalidate_kv_scalesfor the write and both reads. The S5 read refusals are deleted.gather_kv_dense_rangeandread_kv_rangeunpack x=16 and call the flatdequantize_kv_rows(now templated on D 128/256). A qwen3_5 cache-hit prefill on an int8 pool takesPagedVarlen.PageStorage::writeTable):bind_pool_planebinds K, V and the scale planes withset_input_array_with_budget(live blocks). The live-block count is deduplicated, so a shared prefix counts once. This changes the commit points of every paged family, bf16 included. Values do not change.Measured (synthetic, Metal)
read_kv_rangevs flat dequantizeThe grouped route fires at context 9,000 (2 rows) and 17,000 (1 and 2 rows).
Gaps vs Splash
num_seqs == 1). S8 measures.Tests
cargo fmt --check,cargo clippy --all-targets -D warnings,yarn build:native,yarn typecheck: clean.RUST_TEST_THREADS=1): paged_int8_tests 4, adapter 187, qwen4_exp 231, qwen3_5 690, engine:: 559, memory_plan 32,paged471.Not in this PR (live, not run)
🤖 Generated with Claude Code