Skip to content

feat(kv-int8): gqa-16 models default to int8 KV - #366

Merged
Brooooooklyn merged 2 commits into
mainfrom
feat/kv-int8-s32-gqa16-tile-parts
Nov 12, 2026
Merged

Brooooooklyn merged 2 commits into
mainfrom
feat/kv-int8-s32-gqa16-tile-parts

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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_geometry allowed int8 only up to gqa 8.

before:  gqa <= 8 and whole groups ──► int8      gqa 16 ──► bf16
after:   whole groups               ──► int8      (122B window at 96 GiB: 118,393 ──► 262,137 tokens)

Why no tile parts

Splash SPLASH_ATTENTION_TILE_PARTS splits 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.
  • The flat int8 cache (loads with no pool, MoE generate_sync, calibration prefills, training generation): forward_int8_cached takes the segmented kernels only for a block they can split (rows <= 2 × max_q(gqa), new segmented_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.
  • A 5..8-row verify that the segmented kernels cannot split (flat MTP at gqa 16, depth 4 or 5) dequantizes the cache's own rows [0, P+T), so its new rows are read int8, as a 1-row decode reads them (Splash PagedAttention::addVerify: store, then attend). Prefill chunks keep the bf16 own-rows read; S10 owns that.
  • Doc text, generated TS types, CLI help and docs no longer say "GQA up to 8".
  • No Metal, C++ or metallib source changed. gqa ≤ 8 results stay bit-identical.

Tests

test clean mutation (red)
paged_int8_attention_gqa16 (32/2 at 300 / 600 / 17,000 / 33,000 tokens; 1, 2, 8, 64 rows) vs f64 reference max ≤ 1.03, mean ≤ 0.13 bf16 ulps G16 (heads 8+ read the next KV head): all 11 rows, 151–374 ulps; gqa ≤ 8 tests stay green
int8_adapter_reads_serve_gqa_16 (D256, 32/2) max diff 0.125 G16: diff 16.0
eager_forward_over_an_int8_cache_tracks_the_bf16_cache (adds 32x2) worst 8.6e-3 covers-check removed: the C++ throw
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]) ≤ 2 bf16 ulps F1 (own rows read as bf16): verify 0.25 vs decode 0
122B default, unset-format 32/2 rows, 122B estimate green D1 (keep gqa <= 8): red
  • cargo 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

  • At gqa 16 the pool reads run 16 threadgroups per KV head per decode row (128 per 8-row verify). Splash runs _kv2_g16 as 2 parts. Its speed gain for parts is not captured here; it belongs to the S10 prefill split kernel and the compiled paged verify.
  • The grouped int8 route is enabled for 24/4 and 16/2, not 32/2.
  • Splash uses 32-token pages; mlx-node uses 16.
  • No gqa-16 checkpoint is on disk. The 122B window numbers come from a config-only fixture with Splash's Qwen3.5-122B-A10B geometry.
  • Out of scope, reported only: the MoE loader pins sym8 after the KV format. It matters only for a page size other than 16 or 32.

Not in this PR (live, not run)

  • L0 download a 4-bit Qwen3.6-122B; L1 teacher-forced KL / top-1, int8 vs bf16 pages; L2 decode and verify speed, int8 vs bf16.

🤖 Generated with Claude Code

@Brooooooklyn
Brooooooklyn added this pull request to stack #344 November 11, 2026 16:09
@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: 12c7ac44-6631-4a0c-9053-8b42f6bf95c7

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:55:09.358213Z ac26334 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.

@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s31-thinking-close branch from 736aa42 to 48f3c52 Compare November 12, 2026 13:41
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s32-gqa16-tile-parts branch from f39eac4 to 5c6f1f7 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-s31-thinking-close branch from 48f3c52 to 42c28ea Compare November 12, 2026 15:53
Base automatically changed from feat/kv-int8-s31-thinking-close to main November 12, 2026 15:53
Brooooooklyn and others added 2 commits November 12, 2026 23:53
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]>
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s32-gqa16-tile-parts branch from 5c6f1f7 to ac26334 Compare November 12, 2026 15:53
@Brooooooklyn
Brooooooklyn merged commit b3fd60c into main Nov 12, 2026
1 check failed
@Brooooooklyn
Brooooooklyn deleted the feat/kv-int8-s32-gqa16-tile-parts branch November 12, 2026 15:53
Brooooooklyn added a commit that referenced this pull request Nov 12, 2026
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]>
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