Skip to content

feat(kv-int8): the Flash Next pool follows kv_format - #363

Merged
Brooooooklyn merged 2 commits into
mainfrom
feat/kv-int8-fn2-flash-next-int8
Nov 12, 2026
Merged

Brooooooklyn merged 2 commits into
mainfrom
feat/kv-int8-fn2-flash-next-int8

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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

@Brooooooklyn
Brooooooklyn added this pull request to stack #344 November 11, 2026 05:22
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T15:54:48.276315Z 7834c3f New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7c45792f-f959-4ecf-88f4-c9257a8c9925

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Passed Passed checks: 1 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-fn2-flash-next-int8 branch from 56a979f to d0d71b7 Compare November 12, 2026 13:41
@Brooooooklyn
Brooooooklyn removed this pull request from stack #344 November 12, 2026 15:43
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s7-pool-follows-format branch from 024c989 to 4c801c5 Compare November 12, 2026 15:51
Base automatically changed from feat/kv-int8-s7-pool-follows-format to main November 12, 2026 15:51
Brooooooklyn and others added 2 commits November 12, 2026 23:52
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]>
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-fn2-flash-next-int8 branch from d0d71b7 to 7834c3f Compare November 12, 2026 15:52
@Brooooooklyn
Brooooooklyn merged commit b77dc95 into main Nov 12, 2026
1 check failed
@Brooooooklyn
Brooooooklyn deleted the feat/kv-int8-fn2-flash-next-int8 branch November 12, 2026 15:52
Brooooooklyn added a commit that referenced this pull request Nov 12, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant