Repository navigation
feat(paged-attn): one recency clock, leaf-only reuse, covered reserve (S18a) - #345
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. |
bff5ad6 to
fecd770
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fecd770225
ℹ️ 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".
addf0f0 to
6be43ea
Compare
Every block allocator now orders and reuses its cached blocks the way Splash KvCache does. Recency - One saturating u64 clock per allocator (`CacheRecency`, as Splash `CacheRecency::next`). A block is stamped when it is committed (new or a verified duplicate), when a hit ends on it, and when its last request lets go of it (as Splash `KvCache::releaseActive` stamps a released block with no children). A refresh stamps nothing. - A hit stamps its tip only: Splash `Cache::lookup` touches the tip and the attach after it calls `KvCache::retainActive` on the chain's last block alone. - A parent that becomes a leaf takes max(own, child) when nothing holds it (Splash `KvCache::inherit`). Reuse - `allocate` takes a free id, else the oldest cached leaf nothing holds and no state mark protects (Splash `KvCache::orders`: a block enters a leaf order only with no resident children and no users). - `reserve(n)` takes nothing unless free plus evictable blocks cover n, at every pool size (Splash `MemoryLedger::free` counts with `bound` and calls `take` only when the count covers the need). Blocks the pool has not grown yet do not count: the caller grows first, as Splash `KvPool::takeFreePages` grows an extent before the claim reaches the ledger. A refused reserve now evicts nothing; which requests fail is unchanged. - Telemetry reports reclaimable blocks (marked chains included) apart from evictable ones. - The hashlink LRU, the prefix-cache entry cap and `evict_oldest_cache_only_leaf` are removed. With no state marks set, reusable equals evictable, so no admission decision and no qwen3_5 reclaim order changes. mlx-node choices, not in Splash - Pinned-interior fallback: when no dead leaf is left, `allocate` takes the deepest cache-only block whose cached children are all held, outside every marked chain. Splash moves a request onto the block it finds when it publishes, so it never has one; mlx-node's verified-duplicate skip keeps the request on its own block and links its new tail under the found one, and without the fallback such a block could never be reused. - Wave gate: at the max pool, `check_wave_fits` checks that free plus evictable blocks cover the whole wave before any row of a batched decode records, so a wave reserves all or nothing. Splash admits one claim at a time through the ledger; mlx-node records a batched wave row by row. - Turn-end stamp for kept tables: a table kept past its turn records the stamp at its turn end, and `release_request` frees its blocks at that stamp (`free_at`), so its tip is stamped as if the request had ended then. Splash has no table that outlives its request; it stamps at `KvCache::releaseActive` when the request ends. Per family - lfm2, nemotron_h, qwen3_5 dense/MoE, qwen3_asr, k2_horizon and the qwen3 batched decode: `record_decode_wave` runs the wave gate. - qwen3 ragged step: the wave gate over each row's query length. - gemma4: the batched step runs the gate across both KV groups (`check_wave_fits_all`); `reserve_rows_all` admits with free plus evictable blocks. - Muse-Glimmer: the batched step runs the gate across its KV groups (`check_wave_fits_all`). - qwen3_5 DFlash2 prompt growth counts evictable blocks as cached. - Sliding restore and the cold-tier batch restore take their blocks with `reserve`. The prefix-cache hit-walk bench is renamed prefix_cache_hit_walk_bench. Co-Authored-By: Claude Opus 5.5 <[email protected]>
fecd770 to
be2afca
Compare
…rs (S18b1) (#346) ## What Stage S18b1 of the Splash int8 KV alignment. It stacks on #345 (S18a). The reference is Splash `9124ff2c` (1.6.0). On qwen3_5 dense and MoE, every refused KV reservation now goes through one loop, `engine::reclaim::free_for_kv`. The loop follows Splash `MemoryLedger::free` and `Engine::allocate`: ``` refused reserve(n) → clear MLX pool, sync marks → need met in place? yes → take nothing → count (bound) covers need? no → take nothing → take units oldest first, one clock, tie → state (DFlash2 store states · GDN ladder/history entries · idle owners) a unit that frees nothing is passed over → until the need is met ``` ## What changes - **One clock** (`CacheRecency`) is shared by the block allocator, the DFlash2 store, the GDN ladder and history entries, and the idle owners. - **Ladder entries mark their chain.** `allocate` never takes a chain that a state restores through. - **InUse.** The replay point that a running turn restored from is not a unit until its use ends (Splash `StateCache::useState` / `unuse`). - **Refusal record per sequence.** It survives a failed prepare's own release. - **Paths:** - blocked scheduled step (A); - serial steps, prefix, VLM, cold-restart and MTP-gate prepares (A-serial); - admission and prompt grow, where the prompt's own marked hit is left out of the need (A-admit); - the flat DFlash2 lane: extents, then compaction, then dead leaves, then one unit by stamp (B). - **Shared blocks.** The count for idle owners is what releasing all of them frees together, so a block shared by two idle tables counts once. - **Deleted:** `release_one_for_pool_grow`, `evict_one_parked_dflash2_for_pool_grow` and `POOL_GROW_EVICTIONS`. ## mlx-node choices (labelled in code) - At the block cap, only tip rungs are ladder units. Store and history entries are not units there, because they sit on no block. - At the cap, the met check can return Met for a page need. `settle_step` frees tables between the refusal and the reclaim. - Store compaction runs first among the byte units, because it loses nothing. - Idle tables are units, ordered by their turn-end stamp. Splash has no table unit. ## Gaps (left to S11 and S18b2) - There is no single byte ledger, and there are no claim tiers, `Pending` or holds. - Vision entries and the draft need are not units yet. That is S18b2. - The serial MTP per-cycle lookahead and the flat transient loop keep no take order. ## Families - **qwen3_5 dense and MoE:** they take in one stamp order, at the cap and below it. - **gemma4, qwen3, lfm2, nemotron_h, muse_glimmer, k2_horizon and qwen4_exp:** they keep their owner loop and see only inert defaults. ## Tests - 80 new tests. Each has a named mutation that went red, then green after the revert (104 mutation runs). - An adversarial verify step found 6 items, including a regression where a lone turn failed when two idle owners shared blocks. All 6 are fixed and confirmed. - Gates: - `cargo fmt --check` and `cargo clippy --all-targets -D warnings` pass. - `cargo test -p mlx-paged-attn --lib` passes: 212 tests. - `cargo test -p mlx-core --lib`, run over every touched family and module, passes: 2598 tests. CI does not run on this PR until its base is `main`. ## Review rounds 3-6 (2026-11-09) | Commit | Fix | Splash rule | |---|---|---| | `63c7af826` | "Met" means covered: after a grow clamped at the pool max, the takeable blocks are counted again. The walk re-reads the cap after each miss. | `KvPool::takeFreePages`, `MemoryLedger::take` | | `63c7af826` | A lone blocked turn can take a suspended turn's in-use replay point, last. A yielding lane and admission still cannot. Preemption keeps the use ("suspended or not"). | `Engine::growthClass`, `takeRights` | | `1b6f5d0be` | A kept prompt leaves out its last token; a resume keeps by its replay tokens. | `Cache::extendMatch`, `restoredChain` | | `1b6f5d0be` | The reach counts layer bytes left above the pool after a part-way shrink or grow. | `MemoryLedger::takeUnsized` | | `257114e7c` | A waiting admission below the cap grows and reclaims before it waits, sized for the watermark at the grown pool. | `Engine::allocate` -> `governor.free` | | `f7d0dc845` | The reach counts a partial last extent (a grow capped by the pool max or headroom can stop inside an extent). | `KvPool` keeps whole extents only | Each fix has tests with named mutations (red, then green). Round 6 also flagged token-only admission keys across cache salts: that is gap 34 (admission keys and salt), planned for S11, and not part of this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
What
Stage S18a of the Splash int8 KV alignment. It stacks on #343 (S3). The reference is Splash
9124ff2c(1.6.0).Every block allocator now orders and reuses its cached blocks the way Splash
KvCachedoes:The stamp rules:
max(own, child)(KvCache::inherit).mlx-node choices, not in Splash (labelled in code)
allocatetakes the deepest cached block whose cached children are all held. Splash moves a request onto the block it finds. mlx-node's verified-duplicate skip links the new tail under the found block, so without the fallback that block could never be reused.Families
Tests
allocate_takes_the_chain_tail_and_keeps_the_prefix_hitparent_takes_its_child_stampa_hit_touches_its_tip_onlyreserve_evicts_nothing_it_cannot_coverbelow_max_refused_reserve_takes_nothing_after_the_growmax_pool_wave_records_nothing_it_cannot_cover(adapter and muse_glimmer)cargo fmt --checkandcargo clippy --all-targets -D warningspass.cargo test -p mlx-paged-attn --libpasses: 212 tests.cargo test -p mlx-core --lib, run over every touched family and module, passes: 2113 tests.CI does not run on this PR until its base is
main.🤖 Generated with Claude Code