Repository navigation
feat(qwen3_5): one Splash 1.6 take order for KV, states and idle owners (S18b1) - #346
Conversation
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. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e425884b9d
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 257114e7c8
ℹ️ 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".
bff5ad6 to
fecd770
Compare
f7d0dc8 to
3374b50
Compare
fecd770 to
be2afca
Compare
Every refused KV reservation on qwen3_5 dense and MoE now goes through one loop, `engine::reclaim::free_for_kv`, after Splash `MemoryLedger::free` and `Engine::allocate`: clear the MLX pool, sync marks, a need met in place takes nothing, a count that cannot cover the need takes nothing, else units go oldest first (a state on a tie, as `Cache::nextUnit`) until the need is met. A unit that frees nothing is passed over (`MemoryLedger::take`). `MetBefore` is Splash's `met` list: the same need after a take or a Met stops the retry. What changes: - One clock (`CacheRecency`) for the block allocator, the DFlash2 store, the GDN ladder and history entries and idle owners. A parked live state keeps its turn-end stamp (`insert_at`). - Ladder entries mark their chain in production, so `allocate` never takes a chain a state restores through. Marks sync at prune, at `clear_reuse_state`, at `drop_gdn_state` and before every count. - InUse: the replay point a running turn restored from (text and VLM prepares, dense and MoE) is no unit until its use ends (Splash `StateCache::useState` / `unuse`); the use end stamps it after the KV tail and the history write (`Engine::release`). - Refusal record per sequence in the adapter (Splash `MemoryLedger::refused`), kept across a failed prepare's own release with the hit blocks it hands back. `kv_need_met` is the met check; the grow probe's room is read live. - Path A: a blocked scheduled step takes states and idle owners by their own stamps (`SchedReclaim`, Splash `Engine::judge`). Its count is what releasing every idle owner frees together (`BlockAllocator::released_blocks`): a cached block two idle tables share counts once, as Splash's bound counts the whole take. An idle owner the scheduler never finished goes by its table's turn-end stamp. `capacity_exhausted` says what the take order tried. - Path A-serial: `reclaiming` wraps the serial paged steps, the six prefix prepares, the two VLM prepares, the two cold restarts and the two MTP gates. - Path A-admit: admission grow (at the cap too, `cap_shortfall_blocks`), prompt grow and admission charges leave the prompt's own marked hit out (`VictimQuery::kept`). `try_grow_pool_by`: a `Short` take, or a need `MetBefore` saw, is not grown. - Path B: the flat DFlash2 lane takes free extents, a store compaction, dead leaves, then one unit by stamp (store step, ladder or history entry, idle table offered only while an extent cut is in reach, Splash `leadsToReach`), behind a count (`flat_kv_in_reach`, `Cache::takeReclaim`) that gates on the KV alone. A take it lets through goes on toward the KV plus its transients until nothing is left, so the prefill keeps its transient headroom: the transients have no fixed reservation here, unlike Splash's scratch. - The scheduler snapshot counts only takeable blocks (marked chains out); the draft fit adds them back. - Deleted: `release_one_for_pool_grow`, `evict_one_parked_dflash2_for_pool_grow`, `POOL_GROW_EVICTIONS`, the per-owner `releasable_blocks_for`. mlx-node choices (labelled): - At the block cap only tip rungs are ladder units and store and history entries are none: they sit on no block, so taking them there only loses cache (Splash takes the oldest state either way). - At the cap the met check can return Met for a page need. - Store compaction runs first among byte units: it loses nothing. - Idle owners' kept tables (path A) and idle tables (path B) are units by turn-end stamp; Splash has no table unit. Gaps (v6 §11): no `Growth` claim, priority tiers or `Pending`; the count is coarse (blocks plus bytes rounded up plus live room, not one ledger); the refusal record is per step, not per request claim; `metBefore` is per retry loop; the kept chain is prefix-matched ladder/history entries, not `RestoredChains`; admission's marked hit matches tokens, not keys; the serial MTP per-cycle lookahead and the flat transient loop keep no take order; vision entries and the draft need are not units yet; a serial turn that fails before its history write keeps its InUse record until the next prepare. Per family: qwen3_5 dense and MoE take in one stamp order at and below the cap (`reclaims_in_order`). gemma4, qwen3, lfm2, nemotron_h, muse_glimmer, k2_horizon and qwen4_exp keep their owner loop and one `try_grow_pool`; they see only the refusal record, the snapshot fed from evictable blocks (equal to reusable with no marks) and inert trait defaults. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…store - A prompt with block keys keeps a ladder rung only when the rung's block hashes start the prompt's own salted, keyed chain (Splash RestoredChains, Walk::keepsState by hash). Before, the take side kept any rung whose tokens prefixed the prompt, while the reach count read the hit by hash, so a rung on another cache_salt or image-key chain was counted as takeable but never taken and the prepare failed context_length_exceeded at the cap. Keep::hit_chain computes the chain once for marked_hit_blocks and the new KeptPoints; Keep now flows through gdn_unit_excluded, oldest_gdn_state_unit, gdn_state_bytes, state_reach_bytes and oldest_state_unit (dense and MoE). Without keys the token test stays; the history entry stays by tokens. - At the cap a mark in no other mark's chain is a unit when its chain holds any cache-only block, not only when the mark itself is cache-only. A rung whose tip is a held verified-duplicate tail under a released ancestor was filtered out, so the cap reclaim had no unit and failed with recoverable blocks (Splash Cache::takeOldest takes the oldest state either way). - paged_kv_cache_adapter imports HashSet unconditionally: the reclaim code uses it outside the macOS cfg, so the aarch64 Linux build broke. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… its replay-point use A VLM prepare that skips the lookup (reuse_cache=false) and the cold restart after a GDN miss now keep no replay point, as Splash keeps the restored chain only when the request does not skip the cache and retries a failed admission with skipCache. ensure_paged_pool_for_prompt is split into ensure_paged_pool_keeping(target, prompt, keep); the dense and MoE VLM prepares pass Keep::default() when !reuse_cache, and the cold-restart reclaim always does. The paged finalize reads the turn's sequence before it releases the request, and save_paged_history ends that sequence's replay-point use on the reuse_cache=false return and after the history write, so a released serial turn (reuse off, or a reuse turn whose reconcile failed) no longer leaves its rung InUse (Splash Engine::release). Error and abort paths already clear gdn_in_use through clear_reuse_state. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…in-use replay points - kv_need_met recounts takeable blocks after a passing grow: a grow clamped at the pool max can add less than the shortfall (Splash KvPool::takeFreePages). free_for_kv re-reads the cap after each met miss, so units that free no block at the cap are passed over. - A lone blocked turn's need reaches the replay points other turns use, suspended or not, after every ordinary unit (Splash Engine::growthClass, ReclaimClass::InUse); its count includes their bytes (Splash StateCache::reclaims). A yielding lane, admission, serial and DFlash2 keep them. The use survives preemption and a take. - Tests that finalize a paged turn hold the sidecar counter lock. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ished shrink bytes Keep::points tests ladder and history entries against the prompt without its last token, as the lookup does (Splash Cache::extendMatch): a rung at the prompt's own block-aligned end is no replay point of it, so an admission at the max pool may take it instead of rejecting. A resumed turn charges and keeps by its replay tokens (prompt plus committed output, Splash exactTokens), the tokens its lookup uses. release_reach_bytes adds the layer bytes above the pool's block count that a cut or grow which failed part way left behind (Splash MemoryLedger::takeUnsized), so a flat DFlash2 growth at the runway sees them in reach and its first take finishes the cut instead of failing with context_length_exceeded. Scheduled turns never skip the cache (reuse_cache=false is rejected before a scheduled turn is prepared), so admission keeps are unchanged for skipCache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A grow capped by the pool max or by headroom can end inside an extent; the cut takes that partial extent down to the runway, so release_reach_bytes rounds the extent count up. Co-Authored-By: Claude Opus 5.5 <[email protected]>
3374b50 to
8099193
Compare
…e order (S18b2) (#347) ## What Stage S18b2 of the Splash int8 KV alignment. It stacks on #346 (S18b1). The reference is Splash `9124ff2c` (1.6.0). It adds the two units that S18b1 left out of the take order: ``` free_for_kv (KV need) free_for_draft (draft need, new) met in place? → count covers? → take: met in place (live shortfall)? → count covers? → take: states / idle owners by stamp idle owners by stamp (tables + parked rows) then ONE unheld image entry (Rebuild stage, below the block cap only) ``` ## What changes - **Rebuild stage.** A vision cache entry that nothing outside the cache holds (`Arc::strong_count == 1`) is a unit. The oldest goes first, and only after the state and owner walk is empty (Splash `Order::Stage` Rebuild, `TakeRights::rebuiltPools`). It never meets a pure page need (`Lacking::meets`). - **Image hold.** A VLM turn holds its image features until the prefill that reads them is evaluated, then drops them before decode (Splash `Runtime::prefillAsync`). This applies to dense and MoE, in both paged VLM turns. - **Draft need as its own claim.** A short draft fit records a `DraftRefusal`, next to the KV refusal (`MemoryLedger::refused`). `free_for_draft` reads the shortfall live and takes idle owners by stamp. - **One met list.** A single `MetBefore<(SeqId, StepNeed)>` serves both kinds of need. A blocked qwen3_5 step with no record takes nothing, so the old lowest-SeqId owner loop is gone. ## mlx-node choices and gaps (labelled) - **Re-encode cost.** A dropped image entry is re-encoded on later turns that send the image, even when the restored KV covers it. Splash releases covered images and never needs them again. - **Locked cache.** A locked vision cache counts as unknown (`u64::MAX`), so the count can over-count but never under-count. - **Draft need.** Images, states and store entries are not draft units, because the draft fit counts only pool bytes. Splash's rebuild pools do serve a byte need. ## Families - **qwen3_5 dense and MoE:** these get the change. - **Other families:** they see inert defaults, and the draft map is cleared every step. ## Tests - 27 new or changed tests. Each has a named mutation that went red, then green after the revert (31 mutation runs). - An adversarial verify step found 4 items. All 4 are fixed or labelled. - Gates: - `cargo fmt --check` and `cargo clippy --all-targets -D warnings` pass. - `cargo test -p mlx-paged-attn --lib` passes: 213 tests. - `cargo test -p mlx-core --lib`, run over every touched family and module, passes: 2635 tests. - Not run: a live two-turn image chat. CI does not run on this PR until its base is `main`. ## Review round 1 (2026-11-09) `837e50b54`: `Scheduler::preempt_running_at` clears both reservation flags before `settle_step` reclaims for the parked turn, while its caches stay resident. The parked turn now gets both flags back before the reclaim, as `reinstate_running` does, so its draft state and bookings count. Tests run through the real `preempt_running` (victim refused, peer refused); 4 named mutations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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 SplashMemoryLedger::freeandEngine::allocate:What changes
CacheRecency) is shared by the block allocator, the DFlash2 store, the GDN ladder and history entries, and the idle owners.allocatenever takes a chain that a state restores through.StateCache::useState/unuse).release_one_for_pool_grow,evict_one_parked_dflash2_for_pool_growandPOOL_GROW_EVICTIONS.mlx-node choices (labelled in code)
settle_stepfrees tables between the refusal and the reclaim.Gaps (left to S11 and S18b2)
Pendingor holds.Families
Tests
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: 2598 tests.CI does not run on this PR until its base is
main.Review rounds 3-6 (2026-11-09)
63c7af826KvPool::takeFreePages,MemoryLedger::take63c7af826Engine::growthClass,takeRights1b6f5d0beCache::extendMatch,restoredChain1b6f5d0beMemoryLedger::takeUnsized257114e7cEngine::allocate->governor.freef7d0dc845KvPoolkeeps whole extents onlyEach 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