Repository navigation
feat(kv-int8): DFlash2 verifies on the int8 pool - #364
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. |
56a979f to
d0d71b7
Compare
ef025f7 to
b93e8d6
Compare
d0d71b7 to
7834c3f
Compare
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]>
b93e8d6 to
1fb67c0
Compare
#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]>
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 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.
Changes
supports_paged_attention: true.run_paged_turnsends DFlash2 torun_paged_dspark_turn. The shared driver usesargs.params(so the window clamp holds) and gets two hooks whose defaults keep gemma4 unchanged.QwenTargetverify,PagedAttention::addVerify): the draft always proposes the full block (7). Every cycle verifies anchor + 7 = 8 rows.run_paged_dflash2_verify_steprefuses a chunk that is not 8 rows, or a page table shorter than committed + 8, with the Splash error text.open_core_write_cycle/commit_cycle. The cursor moves back 8 − keep, and no page is freed. The DFlash2 prefill books each chunk end (SplashEngine::workEndOf;exactTokensleaves out the pending anchor). GDN blob adopt/commit stays, withreplay_mtp_snapshot_to(paged = true)as the fallback. Each DFlash2 prefill chunk books throughreclaiming(SplashEngine::growLane→Engine::allocatefrees, then retries). A cold DFlash2 prime keeps no prefix chain, so marked checkpoint pages can be reclaimed.row_budget, clamped to min(budget, 1 + L).forward_dflash2_compiled,COMPILED_VERIFY_*) and its Rust helpers, MoE deferred GDN, theMLX_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)
6,391 blocks (3,245 MiB). The S4 live capacity gate (LIVE L4) checks this number on the real load.
Gaps
dflash2_state/tests.rsare deleted (each one drove a flat DFlash2 turn); S9 brings them back.mlx_segmented_sdpa_forward(bf16 segmented verify, C++/Metal) has no library caller now. Its deletion needs a metallib rebuild (follow-up).Tests
cold_dflash2_prefill_reclaims_a_marked_live_chain, dense and MoE).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_refusedandsecond_dflash2_turn_resumes_the_live_window.cargo fmt --check,cargo clippy --all-targets -D warnings,yarn build:native,yarn typecheck: clean.--lib(RUST_TEST_THREADS=1): 4,753 passed, 0 failed.vp teston the 7 touched TS test files: 605 passed.yarn build:native,yarn typecheckclean; qwen4_exp 238, qwen3_5 445, qwen3_5_moe 139, engine 543, transformer::paged 192 passedNot in this PR (live, not run)
🤖 Generated with Claude Code