Skip to content

feat(kv-int8): the paged pool follows kv_format; delete paged FP8 - #362

Merged
Brooooooklyn merged 3 commits into
mainfrom
feat/kv-int8-s7-pool-follows-format
Nov 12, 2026
Merged

Brooooooklyn merged 3 commits into
mainfrom
feat/kv-int8-s7-pool-follows-format

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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

@Brooooooklyn
Brooooooklyn added this pull request to stack #344 November 11, 2026 00:40
@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: f3a00447-b09c-42b3-b2e7-dbf82418c8ec

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

@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:53:26.132369Z 4c801c5 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s6-int8-reads branch from 4addf95 to a45a2e7 Compare November 12, 2026 13:41
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s7-pool-follows-format branch from 59a0cb3 to 024c989 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-s6-int8-reads branch from a45a2e7 to 244ed11 Compare November 12, 2026 15:51
Base automatically changed from feat/kv-int8-s6-int8-reads to main November 12, 2026 15:51
Brooooooklyn and others added 3 commits November 12, 2026 23:51
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]>
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s7-pool-follows-format branch from 024c989 to 4c801c5 Compare November 12, 2026 15:51
@Brooooooklyn
Brooooooklyn merged commit c9d3f95 into main Nov 12, 2026
1 check failed
@Brooooooklyn
Brooooooklyn deleted the feat/kv-int8-s7-pool-follows-format branch November 12, 2026 15:51
Brooooooklyn added a commit that referenced this pull request Nov 12, 2026
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]>
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