Repository navigation
feat(kv-int8): gqa-16 models default to int8 KV - #366
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. |
736aa42 to
48f3c52
Compare
f39eac4 to
5c6f1f7
Compare
48f3c52 to
42c28ea
Compare
The paged int8 reads map query head h to KV head h / gqa at any gqa, so the geometry default needs only whole GQA groups: Qwen3.6-122B (32 query / 2 KV heads, D 256) now defaults to int8 pages. The flat int8 cache takes the segmented kernels only for a block they can split (rows <= 2 x the widest query chunk); a 5..8-row block at gqa 16 reads the dequantized prefix like a prefill chunk instead of failing. Tests cover 32 / 2 paged reads against an f64 reference, the adapter reads, the eager flat path and the 122B estimate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
5c6f1f7 to
ac26334
Compare
Stage S9 of the Splash int8 KV alignment (stack #344). Base: S32 (#366). **S8 (#364) and S9 must merge together.** S8 moved DFlash2 to the int8 pool and dropped parked states. S9 brings them back on pages. A parked DFlash2 state now holds no target KV. It keeps its prefix chain alive by marking the block it sits on (Splash `StateMarks`, the same marks the GDN ladder uses). Two sessions that branch from the same replay point share those pool blocks. ``` before (S8): no parked state → a prefix hit without the live draft window prefills from 0 before (S7): parked state = GDN + draft window + private target KV (~2.44 GiB at 78.6K) after: parked state = GDN cell + draft window at a whole block, KV stays in the shared pool (marked) ``` ## How a state lives ``` tapped prefill ──chunk ends at R = promptReplayBoundary (Splash workEndOf)──▶ capture GDN cell + window at R └─ publish to the store, marked, in use for the turn finalize: keep it only if block R is in the prefix cache │ abort or discard: drop it next DFlash2 prime: deepest parked state that beats the live window → release the live request → deep-copy cell + window in → KV lookup capped at the state's block → block gone → the turn fails ("outlived its target KV block", Splash acquireBlock) take order: a parked state is one unit; dropping it re-syncs the marks ``` ## Changes - `dflash2_state` store: `Entry` has no KV. A paged backing replaces `FlatKv`. The KV eviction ladder (compact, lossy steps, evict helpers) and the KV headroom helpers are deleted. - As in Splash, a state is published only during prefill, at the replay point (`Engine::publishReachedStateBoundaries`). No end-of-turn state is parked, so a state is never a partial block. AR, media, reset and session-switch sites stay plain drops. - A marked chain counts once, as ordinary pool blocks. State bytes stay in the 3072 MiB budget until S12. At the pool cap, a parked state counts as reclaimable only if no ladder rung marks its block. - Installing a state clears the image lineage. A capture is skipped when the GDN state is dirty or the turn carries image positions. A pool swap or weight update clears the store. - Deleted (no caller left): `MemoryPlan::live_headroom`, `dflash2_memory_snapshot`, `KVCache::compact`, `GdnCell`, `DFlash2Target::memory_plan`. ## Tests (13 named mutations, each red when on, green when off) | mutation | test | shows | |---|---|---| | MK1 | `parked_anchor_resume_matches_an_uninterrupted_run` | park A, run an unrelated turn, resume A: tokens equal an AR reference, resumed on the installed GDN cell | | GI1 | same test | the install must fill the GDN slots (no replay fallback) | | CP1 | `two_sessions_share_the_parked_prefix_blocks` | B sits on A1's 13 block ids | | KV1 | `parked_state_bytes_have_no_kv_term` | equal bytes at 1,600 and 78,592 tokens (27B End+Anchor: 397,139,968 B) | | LK1 | `dropping_a_parked_state_returns_its_blocks` | dropping a state returns its 6 blocks | | CA1 | `tapped_prefill_parks_the_replay_point` | chunks end at 128/192/208; a twin prompt parks the same bits | | CU1, RS1, EV1 | park tests | cap rule, reset clears, missing block fails the turn | | PB1, DD1, BG1 | store tests | whole block only, one state per block, budget trim | | MS1 | `moe_parked_replay_point_resumes_the_next_session` | MoE resume | - After the rebase onto S32 f39eac4: `cargo fmt --check`, `cargo clippy --all-targets -D warnings`, `yarn build:native`, `yarn typecheck` clean; mlx-core `--lib` (`RUST_TEST_THREADS=1`) 4,766 passed, 0 failed. `mlx-paged-attn` all binaries passed before the rebase. ## Gaps (S11 / S12) - Only replay-point captures: no capture at the KV hit, no rolling checkpoints. Two sessions with the same document but different questions still prefill from 0 until S12. - A cancelled turn keeps no state. Splash publishes after every prefill chunk, so it keeps one. - A session switch resumes at the other session's replay point, not at its exact turn end. - One extra prefill chunk edge per DFlash2 turn (the cut at the replay point). Not measured. - A ladder rung and a state can share one GDN cell on one block. No resume-point keep. ## Not in this PR (live, not run) - L0 sanity; L1 two sessions on a shared 16K prefix (fork), prefix-hit tokens and pool blocks recorded, with a before row on S8; L2 the S8 L3 speed re-check. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
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_geometryallowed int8 only up to gqa 8.Why no tile parts
Splash
SPLASH_ATTENTION_TILE_PARTSsplits 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.generate_sync, calibration prefills, training generation):forward_int8_cachedtakes the segmented kernels only for a block they can split (rows <= 2 × max_q(gqa), newsegmented_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.[0, P+T), so its new rows are read int8, as a 1-row decode reads them (SplashPagedAttention::addVerify: store, then attend). Prefill chunks keep the bf16 own-rows read; S10 owns that.Tests
paged_int8_attention_gqa16(32/2 at 300 / 600 / 17,000 / 33,000 tokens; 1, 2, 8, 64 rows) vs f64 referenceint8_adapter_reads_serve_gqa_16(D256, 32/2)eager_forward_over_an_int8_cache_tracks_the_bf16_cache(adds 32x2)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])gqa <= 8): redcargo 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
_kv2_g16as 2 parts. Its speed gain for parts is not captured here; it belongs to the S10 prefill split kernel and the compiled paged verify.Not in this PR (live, not run)
🤖 Generated with Claude Code