Skip to content

feat(kv-int8): DFlash2 verifies on the int8 pool - #364

Merged
Brooooooklyn merged 2 commits into
mainfrom
feat/kv-int8-s8-dflash2-pool
Nov 12, 2026
Merged

Brooooooklyn merged 2 commits into
mainfrom
feat/kv-int8-s8-dflash2-pool

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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 feat(output-store): add training output persistence with libsql #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)

🤖 Generated with Claude Code

@Brooooooklyn
Brooooooklyn added this pull request to stack #344 November 11, 2026 10:43
@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: 62532dd9-73e9-40cf-addb-9f57df255830

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:12.179944Z 1fb67c0 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-fn2-flash-next-int8 branch from 56a979f to d0d71b7 Compare November 12, 2026 13:41
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s8-dflash2-pool branch from ef025f7 to b93e8d6 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-fn2-flash-next-int8 branch from d0d71b7 to 7834c3f Compare November 12, 2026 15:52
Base automatically changed from feat/kv-int8-fn2-flash-next-int8 to main November 12, 2026 15:52
Brooooooklyn and others added 2 commits November 12, 2026 23:52
Qwen3.5 dense and MoE DFlash2 turns now run on the paged pool, like
Splash. Each cycle runs one fixed 8-row verify (anchor + 7 drafted rows;
the driver's cap lowers only the keep), books committed + 8 rows, and
rolls back past the keep. A full accept adopts the spare GDN cell. The
paged verify refuses a chunk that is not 8 rows. The DFlash2 prefill
taps the paged prefill and books each chunk's end, not the whole prompt.

The flat DFlash2 lane is deleted: flat KV growth, flat turn, parking,
the flat compiled verify, MoE deferred GDN and their env knobs. Every
turn takes the one pool window; the pool lane prices the draft state
(second GDN cell + draft ring). A load with a draft and no pool fails.
contextLimits() and the context estimate drop the speculative window.

Parked DFlash2 states have no store until the paged store lands.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… fails

A cold DFlash2 prime books nothing past its hit, so each prefill chunk
books its own rows. Those bookings ran outside the take order, and the
prime kept the whole prompt's chain: after an AR turn the released live
table stayed marked and a chunk that fits after a reclaim failed the turn.

Each DFlash2 prefill chunk now books through `reclaiming` (Splash
`Engine::growLane` -> `Engine::allocate`) on the dense and MoE models, and
the DFlash2 prime keeps nothing, since it reuses only the live table. The
AR paths are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s8-dflash2-pool branch from b93e8d6 to 1fb67c0 Compare November 12, 2026 15:52
@Brooooooklyn
Brooooooklyn merged commit 96ef513 into main Nov 12, 2026
1 check failed
@Brooooooklyn
Brooooooklyn deleted the feat/kv-int8-s8-dflash2-pool branch November 12, 2026 15:52
Brooooooklyn added a commit that referenced this pull request Nov 12, 2026
#365)

Stage S31 of the Splash int8 KV alignment (stack #344). Base: S8 (#364).

A thinking-budget cut now ends thinking with the chat template's own
close, not with `</think>` alone. The re-rendered history then has the
same tokens as the reply, so the next turn's paged prefix hit goes
through the forced close.

```
before:  ...thinking (budget reached) ──► </think>             re-render: "\n</think>" ──► prefix hit stops at the cut
after:   ...thinking (budget reached) ──► "\n" </think>        re-render: "\n</think>" ──► prefix hit covers the close
```

## Changes
- **Probe at load** (Splash `thinking_end_tokens` / `_thinking_end`):
every tokenizer renders a 4-message conversation, slices from the end of
the reasoning through the first `</think>`, and encodes it. The close
must end with `</think>`, have no other added token, and be at most 64
tokens, or the load fails. A template with no close falls back to
`</think>` alone, as Splash does. `from_tokenizer` now returns `Result`.
- **One tracker rule for every decode loop** (Splash
`NativeBackend._thinking_budget`, `commitSelected`): the end advances
when a token is observed. A forced token is handed out only when no
forced token is in flight. While thinking ends, the unforced budget is
0, with no drafts and no pipelining. A token past the budget is a
`debug_assert`, because Splash throws there.
- **Paths:** AR, `decode_loop!`, MTP, DSpark/DFlash2, the qwen3
scheduler, hybrid scheduler AR rows and scheduled speculation, the
qwen3_5 and MoE whole-turn cores, and every family with a thinking
budget. Speculative paths commit each forced token through its own
one-row cycle, so their tokens and KV are the same as AR.
- **Deleted:** `forced_token_id`, `should_force_think_end`,
`force_think_end_pending`, `end_scheduled`, `from_setup_multi`.

## Probe survey (local templates, tokenizer only)
| close | families |
|---|---|
| `"\n</think>"` | Qwen3, 3.5, 3.6, 3.8, clef, ornith, agents, ternary,
and their GGUFs |
| `"</think>"` | nemotron, lfm2.5, qianfan, qwen3-asr, deepseek |
| none (nothing forced) | gemma4, muse, k2, privacy-filter |

No local template fails the load. Qwen3 also moves to `"\n</think>"`.
This is deliberate.

## Gaps
- Splash forces the close inside one verify. Here MTP and DSpark spend
one 1-row cycle for each close token, which is 2 on Qwen.
- No `also_ends` rule: a `<tool_call>` opened inside a cut still gets
the close after it. This was true before S31 too. There is no
`--thinking-end-text` flag.
- A cut right after a space or a line break still misses the cache at
the cut, because the template trims the reasoning. Splash has the same
gap.
- A cut turn reports one more reasoning token (budget + 1), which is
Splash's count.
- The MoE whole-turn and vision cores have no test of their own. The
tracker test covers their risk.
- `docs/vllm_reasoning_control_flow_spec_for_mlx_node.md` still
describes the old single-token design (historical spec).

## Tests
- 14 named mutations, each red when on and green when off (M1–M13, M5 =
force `</think>` alone and the re-rendered history splits at the cut).
- New tests include `tracker_ends_thinking_with_the_whole_close`,
`probe_finds_the_template_close` (Qwen3.8 + a new Qwen3.6 template
fixture), `probe_falls_back_and_refuses_a_bad_close`,
`budget_cut_rerender_hits_through_the_close`,
`scheduled_rows_end_thinking_with_the_whole_close`,
`legacy_dense_cores_end_thinking_with_the_whole_close` and
`decode_loop_ends_thinking_with_the_whole_close`.
- `cargo fmt --check`, `cargo clippy --all-targets -D warnings`, `yarn
build:native`, `yarn typecheck`, `vp lint` / `vp fmt` on the touched
files: clean. mlx-core `--lib` (`RUST_TEST_THREADS=1`): 4,762 passed, 0
failed.
- After the rebase onto S8 ef025f7: fmt, clippy, `yarn build:native`,
`yarn typecheck` clean; mlx-core `--lib` 4,764 passed, 0 failed

## Not in this PR (live, not run)
- L1 AR, L2 DFlash2, L3 MTP on qwen3.8-27b with a thinking budget of 64.
Each runs a second turn on a re-rendered history and records the
prefix-hit tokens, which must cover the forced close.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
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