Skip to content

feat(qwen3_5): image entries and the draft need in the Splash 1.6 take order (S18b2) - #347

Merged
Brooooooklyn merged 2 commits into
mainfrom
feat/kv-int8-s18b2-vision-draft
Nov 12, 2026
Merged

Brooooooklyn merged 2 commits into
mainfrom
feat/kv-int8-s18b2-vision-draft

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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

@coderabbitai

coderabbitai Bot commented Nov 9, 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: 58a88cc1-29d4-43be-b85e-0d07d03157b8

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
  • 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 9, 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:49:16.349378Z 3c1029d 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 added this pull request to stack #344 November 9, 2026 00:29
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s18b2-vision-draft branch 3 times, most recently from 9533d3f to 837e50b Compare November 9, 2026 10:24
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s18b2-vision-draft branch 2 times, most recently from e85d349 to 61602e8 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-s18b1-reclaim branch from 3374b50 to 8099193 Compare November 12, 2026 15:46
Base automatically changed from feat/kv-int8-s18b1-reclaim to main November 12, 2026 15:46
Brooooooklyn and others added 2 commits November 12, 2026 23:46
…e order

Image feature entries become the Rebuild stage of `free_for_kv`, and a
refused draft fit becomes its own claim with its own entry,
`free_for_draft`, over the same skeleton as Splash `MemoryLedger::free`:
a need met in place takes nothing, a count that cannot cover it takes
nothing, else units go oldest first until it is met; a unit that frees
nothing is passed over.

What changes:
- Rebuild stage (Splash `Order::Stage` Rebuild, the `embeddings` pool):
  a vision cache entry nothing outside the cache holds
  (`Arc::strong_count == 1`, Splash's `use_count() > 1` floor) is a
  unit, least recently used first (`release_one_unheld`). `free_for_kv`
  takes one only when the state/owner walk is empty, and adds the
  unheld bytes to the count, both only below the block cap: a pool unit
  gives bytes and never meets a need of pages alone (Splash
  `Lacking::meets`).
- `KvNeed.rebuilt` is Splash `TakeRights::rebuiltPools`; `in_place`
  sets it, as every caller is an `InService` or `Start` claim.
- A VLM turn holds its image features (`vlm_prepare_vision_features`
  returns them) until the prefill that reads the merged embeddings is
  evaluated, then drops them before decode (Splash
  `Runtime::prefillAsync` gives an image's rows to the cache once they
  are in). Dense and MoE, both paged VLM turns each.
- Path A (scheduler): `SchedReclaim` and the dense and MoE backends
  expose `rebuilt_bytes` / `release_one_rebuilt`; `capacity_exhausted`
  names the image features as KV units below the pool's max only, and
  the idle owners as the only draft units.
- Path B (flat DFlash2 lane): `flat_kv_in_reach` counts the unheld
  image bytes; `flat_reclaim_one` takes one image entry only after its
  whole state/table walk is empty; `KvGrowth.released_vision_entries`
  is logged.
- Draft need: a short draft fit records `DraftRefusal` (bytes, rows) in
  the adapter beside the KV refusal (Splash `MemoryLedger::refused`);
  `reserve_speculative_step` clears its own record first and
  `clear_refusals` clears both maps each step. `free_for_draft` reads
  the shortfall live at the recorded rows over the running turns and
  the preempted one (`DraftUnits`), counts what the idle owners give
  (released blocks times bytes per block, plus parked rows) and takes
  idle owners by their own stamps.
- One `MetBefore<(SeqId, StepNeed)>` (Splash `Engine::allocate`'s
  `met` list) serves the KV and the draft need of one blocked step;
  both are served in one reclaim. A blocked qwen3_5 step with no record
  of either kind takes nothing: the lowest-SeqId owner loop is gone
  there.

mlx-node choices (labelled):
- Image entries are the only Rebuild unit. Taking one costs a re-encode
  Splash never pays: `vlm_prepare_vision_features` encodes every image of
  the prompt before the prefix plan, with no cached-prefix length, so a
  dropped entry is re-encoded on every later turn that sends the image,
  even when the restored KV prefix covers it. Splash's restore releases
  the images `ModelRequest::restoredTokens` covers and never needs them
  again. This is an mlx-node gap; it bites only below the cap, once no
  state or owner is left.
- A locked vision cache reads as `u64::MAX` unheld bytes (unknown): the
  count may over-count, never under-count. Only the model thread locks
  it today.
- A turn holds its features through the returned clones, not a
  protected key set.
- The rebuild right is a field no production caller sets false.
- The draft need has its own entry: the KV count measures blocks, the
  draft fit measures pool-budget bytes.
- Draft units are idle owners only (tables and rows). Store, ladder,
  history and image entries are left out: the draft fit charges only
  pool bytes, so dropping them moves no number it reads (Splash's
  Rebuild pools do serve a state need with refused bytes).
- The draft shortfall is re-read live; Splash's need is the recorded
  refused bytes.
- The flat transient loop and the flat-vision pre-evict take no image
  entry: they run without a count.

Gaps: "unheld" is the Arc count, so an MLX graph that still reads a
feature buffer after its turn dropped it is not seen; `kv_staging`,
`vision_arena` and the hot block cache have no unit; no `Growth` claim
or priority tiers, so `rebuilt` is always true; the draft need has no
state unit, extent cut or grow, and the fit counts marked chains no
draft unit frees; RAM states hold no straddled image rows
(`holdStraddledRows`); no test runs a whole qwen3_5 VLM turn, so the
four held bindings are pinned at the `vlm_prepare_vision_features`
level only.

Per family: qwen3_5 dense and MoE take image entries last below the cap
and serve the draft need by idle-owner stamps. gemma4, qwen3, lfm2,
nemotron_h, muse_glimmer, k2_horizon and qwen4_exp keep their owner loop
(`reclaims_in_order` is false) and the inert trait defaults
(`rebuilt_bytes` 0, `release_one_rebuilt` false); a draft record their
scheduled speculation writes is cleared every step and never read.

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

settle_step restores the preempted turn's block and recurrent-state
reservation flags before its reclaim: preempt_running_at clears them,
but the turn's caches stay resident until handle_preempted releases
them, so the draft need read with the parked turn left its state and
bookings out and the idle owner stayed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s18b2-vision-draft branch from 61602e8 to 3c1029d Compare November 12, 2026 15:46
@Brooooooklyn
Brooooooklyn merged commit 4f1648a into main Nov 12, 2026
@Brooooooklyn
Brooooooklyn deleted the feat/kv-int8-s18b2-vision-draft branch November 12, 2026 15:47
Brooooooklyn added a commit that referenced this pull request Nov 12, 2026
…353)

## What

Stage S36a of the Splash int8 KV alignment. It stacks on #347 (S18b2).
The reference is Splash `9124ff2c` (1.6.0).

`mlx convert` read one part of a split GGUF (`NAME-0000K-of-0000N.gguf`)
and gave no error: the output held only that part's tensors. Now every
GGUF entry that reads a single file refuses a lone split part, as Splash
`GgufFile::GgufFile` does.

```
mlx convert / --mmproj / --draft ─┐
native prepare                    ├─> plan_gguf_import ─> reject_split   (new, first step)
from_asset_dir                    ─┘
family header check ──────────────────> reject_split, before the architecture check   (new)
draft preflight ──────────────────────> reject_split   (new)
native load GgufFileHandle::open ─────> reject_split   (unchanged)
```

## The rule (Splash `GgufFile::GgufFile`)

- `split.count` (absent = 1) must be 1. A larger count is refused. The
message names the parts (found with `resolve_gguf_shards`) and gives the
`llama-gguf-split --merge` command.
- `split.tensors.count` (absent = the tensors read) must equal the
tensors in the file.
- Only integer values count (u8..u64, i8..i64, bool), as Splash reads
them. A string, float or array value counts as absent.
- The file name is read by a hand-written parser.

The split-aware loaders (Flash Next `index_gguf`, DeepSeek V4.1
`shard_paths`) do not reach these checks, so they still load split
files.

## Labelled gaps

- `split.count == 0` (what `llama-gguf-split --merge` writes) is
accepted. Splash refuses it.
- A lone-part `--mmproj` is refused only after the main conversion. No
output is damaged, because convert stages its output.

## Tests

5 new tests (T1-T5), 8 named mutations, each red then green. Scoped
`cargo test -p mlx-core --lib -- utils::gguf engine::checkpoint_source
convert::`: 492 passed. `cargo fmt --check` and `cargo clippy
--all-targets -D warnings` are clean. Docs: `docs/convert-quantize.md`
(trap 13 removed, guard row added), `docs/cli.md`.

🤖 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