Skip to content

fix(qwen3_5_moe): cap a verify stall at twice the fit, with no floor (Splash int8 align S28) - #355

Merged
Brooooooklyn merged 1 commit into
mainfrom
feat/kv-int8-s28-verify-stall-cap
Nov 12, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
feat/kv-int8-s28-verify-stall-cap

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Contributor

What

Stage S28 of the Splash int8 KV alignment. It stacks on #354 (S27). The reference is Splash 9124ff2c (1.6.0).

One stalled cycle could push the MoE DFlash2 lane into anchor-only verify cycles. The verify budget now counts a cycle as Splash VerifyBudget::observe does:

before: counted = clamp(ms, 0.5*fit, 2*fit)
after:  counted = min(ms, 2*max(fit, mean))     (no floor)

mean is cost.time / cost.weight for that width. A fast cycle counts at its own time. A cycle cut to under half its time prints one tracing::warn! line at most once a minute (Splash cuts_ / nextNotice_).

Only qwen3_5_moe/verify_budget.rs changes. Dense qwen3_5 has no time cap.

Tests

  • stalled_cycle_counts_twice_the_larger_of_fit_and_mean (both fit < mean and fit > mean)
  • fast_cycle_counts_at_its_own_time
  • one_doubled_cycle_does_not_lock_verification_to_the_anchor: from the second cycle after a 2x stall, the width stays at its pre-stall value. Under Splash's own rule the first cycle after the stall drops to 2 rows; this was checked against Splash VerifyBudget.cpp built with clang++.
  • The Splash-source golden test still gives the same bits.

Mutations: the 0.5x floor back, a cap at the line alone, and the old clamp: each turns its gate red. cargo test -p mlx-core --lib qwen3_5_moe::verify_budget 11 passed; qwen3_5_moe::dflash2 31 and qwen3_5::dflash2 171 passed. fmt and clippy are clean.

🤖 Generated with Claude Code

@Brooooooklyn
Brooooooklyn added this pull request to stack #344 November 9, 2026 11:58
@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: 0cae0e94-c000-43f2-b97a-5977627c4c52

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:24.344038Z 0f3c603 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-s28-verify-stall-cap branch 2 times, most recently from 556f86c to 0b664fb Compare November 9, 2026 12:42
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s28-verify-stall-cap branch from 0b664fb to eb36d46 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-s27-server-rules branch from 3717455 to fb9a592 Compare November 12, 2026 15:47
Base automatically changed from feat/kv-int8-s27-server-rules to main November 12, 2026 15:47
VerifyBudget::observe now counts a cycle as min(ms, 2*max(fit, mean)),
with no lower bound, as Splash 9124ff2c does: a cap at the fitted price
alone let one stall tilt the line so later cycles verified only their
anchors. Cycles counted at under half their time raise one warning a
minute, like Splash's cut notice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn
Brooooooklyn force-pushed the feat/kv-int8-s28-verify-stall-cap branch from eb36d46 to 0f3c603 Compare November 12, 2026 15:48
@Brooooooklyn
Brooooooklyn merged commit 3904ad5 into main Nov 12, 2026
0 of 5 checks passed
@Brooooooklyn
Brooooooklyn deleted the feat/kv-int8-s28-verify-stall-cap branch November 12, 2026 15:48
Brooooooklyn added a commit that referenced this pull request Nov 12, 2026
…ash2 budget (Splash int8 align S4) (#356)

## What

Stage S4 of the Splash int8 KV alignment. It stacks on #355 (S28). The
reference is Splash `9124ff2c` (1.6.0), `evaluateEngineMemoryPlan`.

One memory plan now sizes the paged pool, both lane windows and the
DFlash2 KV budget for qwen3_5 dense and MoE. It replaces three separate
budgets (the 0.85 pool probe, DFlash2's 0.95 − 2 GiB then ×0.9, and
`live_prefill_headroom`).

```
hard    = WS − (15% + 1 GiB), lowered by --max-memory        (S11: Splash max(1 GiB, 2%))
fixed   = MLX active after load + other pools + 64 MiB staging + 256 MiB pipeline + 512 MiB runtime
dynamic = hard − fixed
lane    = lane state + transient(W) + growth copy + KV(W + scratch), in whole extents ≤ dynamic
window  = min(trained, largest W that fits)
```

## ⚠️ Window change on a 36 GB M3 Pro (needs your review)

The plan now charges what the old budgets left to the margin: Splash's
768 MiB reserves, the pool-growth copy, and the turn transients (verify
partials and paged prefill attention). The margin stays 15% + 1 GiB
until the governor (S11), as decided. Together this lowers the windows
until S11:

| M3 Pro inputs (27 GiB WS, 17,357 MiB active) | before S4 | S4 | with
S11's 2% margin |
|---|---|---|---|
| AR / pool window | 78,464 | 48,601 | ~120K |
| DFlash2 window | 139,257 | 61,433 | ~176K |
| pool ceiling (1 MiB blocks) | 5,051 | 3,186 | ~7.7K |

## Prefill chunk ceiling

Every qwen3_5 / MoE paged prefill (text, scheduler, serial, VLM) now
runs in chunks of at most 2,048 rows, as Splash
`ExecutionLimits::prefillTokenBudget` does, so the plan prices the chunk
the engine runs. `MLX_PAGED_PREFILL_CHUNK_SIZE` above 2,048 is capped,
and 0 (one shot) is gone for these families. CLI launchers already set
2,048.

The pool budget subtracts the lane state first (Splash
`availableForOneRequestKv = dynamic − laneStateBytes`). The scheduler
still charges the GDN cell inside the pool too, so the AR window pays it
twice versus Splash (50,585 if paid once); that is shared scheduler code
and stays a labelled gap.

## Deleted (no compatibility path)

`MLX_KV_MEMORY_UTILIZATION`, `MLX_KV_SAFETY_MARGIN_BYTES`,
`DFLASH2_KV_HEADROOM_RESERVE_BYTES`, `MLX_PAGED_CACHE_INITIAL_MB` /
`paged_cache_initial_memory_mb`, the qwen3_5 one-sequence pool cap,
qwen3_5/MoE reads of `MLX_PAGED_PER_SEQ_CTX`, the TS overlay's 16,384 /
2,048 MiB defaults and `MLX_PAGED_CACHE_MEMORY_MB`.
`MLX_PAGED_PER_SEQ_CTX` stays for the families outside this work.

## New

- `--max-memory SIZE` (lower only) on `mlx serve` and `mlx agent`,
through the host to `Qwen35LoadOptions.max_memory_bytes`. A value above
the automatic budget is ignored with Splash's log line.
- Load errors that name the limit: the plan cannot hold one lane and the
runway; an explicit pool above the plan (16,384 MiB on the M3 Pro inputs
→ "at most 3,186 MiB"); the startup audit finds memory over the plan.
- `/v1/models` before load: `estimateQwen35ContextWindow` plans from
file sizes without loading.

## Splash gaps (labelled)

- 27B lane: 355,217,408 B vs Splash 356,122,624 B (−905,216): no 4-bit
draft window, a 2,311-row ring, no 16 KiB conv alignment.
- Flash Next is FN1 (index plane, E1 64K allowance, E9 PLE share).
- `--max-memory` reaches qwen3_5/MoE loads only.

## Tests

Plan module: 18 tests, 25 named mutations. Wiring: 17 mutations. TS: new
flag and overlay tests with mutations. Golden: WS 25,769,803,776 → hard
20,830,591,385 with mlx-node's margin (Splash's 24,696,061,952 recorded
for S11; mutation "Splash margin" → red).
- `cargo fmt --check`, `cargo clippy --all-targets -D warnings`: clean.
- mlx-core `--lib` scoped: 784 + 379 passed; mlx-paged-attn profile 5 +
6 passed.
- `yarn typecheck`, `vp lint` (21 files), `vp test` on 75 touched and
importing files: 1,426 passed. `bge-native` fails at 2.7e-5 vs 5e-6:
that is the NAX TF32 reranker drift fixed by #348 (not in this stack's
base).
- No live model run yet.

🤖 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