Repository navigation
feat(kv-int8): one memory plan sizes the pool, the window and the DFlash2 budget (Splash int8 align S4) - #356
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: 8549389c74
ℹ️ 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: 7ee7dbf73e
ℹ️ 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".
0b664fb to
eb36d46
Compare
7ee7dbf to
254506b
Compare
eb36d46 to
0f3c603
Compare
…ash2 budget Qwen3.5 dense and MoE loads now build one memory plan in the shape of Splash EngineMemoryPlan (evaluateEngineMemoryPlan): a hard budget below the Metal working set, the fixed bytes the load measured (weights, other pools, restore staging, Splash's 256 MiB pipeline and 512 MiB runtime reserves), and per lane the longest window whose state, transients and KV in whole Splash extents fit the dynamic rest. - Margin: 15% of the working set plus 1 GiB (hard = WS - margin), until the memory governor moves it to Splash max(1 GiB, 2%). - --max-memory (mlx serve, mlx agent; napi maxMemoryBytes) only lowers the hard budget, as Splash hardBudgetBytes; Splash memoryBound names it in the errors. - The pool starts at the runway on every load and grows by extents to the plan's ceiling; an explicit paged_cache_memory_mb above the plan fails the load. A load whose lane and runway do not fit fails with Splash's wording; a startup audit (Splash auditActualMemory) refuses a footprint over the hard budget. - DFlash2 growth, the paged prefill headroom and pool growth probe the plan's ceiling; the 2 GiB reserve and the 9/10 rule are gone. - /v1/models shows a load-free estimate from the same plan (estimateQwen35ContextWindow) until the model loads. Deleted: - MLX_PAGED_CACHE_INITIAL_MB and paged_cache_initial_memory_mb - MLX_KV_MEMORY_UTILIZATION and MLX_KV_SAFETY_MARGIN_BYTES - MLX_PAGED_PER_SEQ_CTX for qwen3_5 / qwen3_5_moe (other families keep it) - the TS overlay's 16,384 MiB MLX_PAGED_CACHE_MEMORY_MB floor and 2,048 MiB initial size Co-Authored-By: Claude Opus 5.5 <[email protected]>
…; estimate the loaded config Co-Authored-By: Claude Opus 5.5 <[email protected]>
PagedAttentionConfig::validate refuses gpu_memory_mb under 256, but the Qwen3.5 pool allocates by blocks. The plan can approve a pool under that floor (231 MiB for the 27B at the lane minimum), and the load then failed to construct the KV pool. Splash has no pool floor (evaluateEngineMemoryPlan refuses only KvPoolDoesNotFit). - mlx-paged-attn exports the floor as MIN_GPU_MEMORY_MB, used by validate. - PoolPlan::config_mib() = max_mib().max(MIN_GPU_MEMORY_MB); dense and MoE initialize_paged_adapter pass it. Allocation stays bounded by num_blocks and max_num_blocks from the plan; validate is unchanged for other families. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The DFlash2 lane transient counts the verify cycle plus the free pool MLX keeps of it (decode_cache_limit, twice the cycle), the base S28 term: MLX collects that pool only at min(0.95*WS, its memory limit) and no load lowers that limit to the plan. The plan, turn eviction and the Decode growth delta read the one function. M3 Pro DFlash2 window 61,433 -> 32,761; --max-memory 20G 27,241 -> 12,936; the pool lane is unchanged. A Qwen3.5 dense or MoE load with neither pool nor draft is planned on a flat lane (one GDN cell, flat K/V in the load's format, a per-layer grow copy, its last prefill chunk or one decode step), as Splash plans every start. maxMemoryBytes now bounds and can refuse such a load, the load is audited, and effectiveWindowTokens is the flat window with an omitted budget meaning the rest of it. 27B sym8 estimate on a 27 GiB working set with 16,000 MiB of weights: 262,144 -> 126,976. Co-Authored-By: Claude Opus 5.5 <[email protected]>
254506b to
19da873
Compare
… memory plan (#357) Stage FN1 of the Splash int8 KV alignment (stack #344). Base: S4 (#356). The Flash Next (`qwen4_exp`) context window and expert store now come from the one memory plan, the same as Splash `planStreamedMemory` + `evaluateEngineMemoryPlan` for a target that cannot spill. ``` load: descriptors → price fixed weights + experts + row-cache share → KV allowance first (every lane: min(trained, 64K)) → experts whole if they leave allowance + row share, else stream with the rest as cap → floors over the hard budget refuse before any payload read after load: re-plan from what is resident → pool grows from a 96-block runway to the plan max ``` ## Changes - The KV allowance comes first; the store cap is what is left. The host only gates allocations (a refusal gives partial slots; the plan keeps its cap). - The pool starts at a 96-block runway and grows by extents under the plan ceiling. Rows, MTP draft state and the transient share the dynamic budget. - The page prices the indexer block keys. The cell is the real storage (115,651,584 B; Splash `cellBytes` 115,802,112). - `--max-memory` reaches `qwen4_exp` loads. `/v1/models` shows a load-free estimate (`estimateQwen4ExpContextWindow`, descriptors only). - Deleted: `effective_context_limit` (the `.min(32_768)` cap and its 2 GiB f32 estimate), the fixed 1 GiB pool, the host-sized weight budget, the 2 GiB prefill scratch cap, and the 4 GiB `WORKING_BYTES` share. ## Plan numbers | Input | Store cap | Window | |---|---|---| | 36 GB (WS 30,150,672,384) | 14,459,363,158 | AR 65,536 (was 32,768) | | 36 GB + MTP weights | 13,180,462,934 | AR 95,225 / MTP 65,655 | | 128 GiB working set | experts whole | 262,144 | ## Tests - Rust (one build): `memory_plan load_plan qwen4_exp hybrid_scheduler engine paged_kv_cache_adapter` — 974 passed, 0 failed, 12 ignored (real-checkpoint tests). - Each new test has a named mutation that went red (`MUTATIONS.md`, 30 mutations). - `cargo clippy --all-targets -D warnings`, `cargo fmt --check`, `yarn typecheck` (`tsc -b --force`), `vp lint --type-aware --type-check`, `vp fmt --check`: clean. - `vp test`: 12 files, 252 passed. ## Not in this PR - The live load gate on a real Flash Next checkpoint is not run. - On a 36 GB Mac the host check can halve the 1,024-token prefill chunk at load (known gap 17). - The MTP lane's draft state is booked for the whole turn at admission, not grown per step as in Splash. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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).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:
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::prefillTokenBudgetdoes, so the plan prices the chunk the engine runs.MLX_PAGED_PREFILL_CHUNK_SIZEabove 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 ofMLX_PAGED_PER_SEQ_CTX, the TS overlay's 16,384 / 2,048 MiB defaults andMLX_PAGED_CACHE_MEMORY_MB.MLX_PAGED_PER_SEQ_CTXstays for the families outside this work.New
--max-memory SIZE(lower only) onmlx serveandmlx agent, through the host toQwen35LoadOptions.max_memory_bytes. A value above the automatic budget is ignored with Splash's log line./v1/modelsbefore load:estimateQwen35ContextWindowplans from file sizes without loading.Splash gaps (labelled)
--max-memoryreaches 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.--libscoped: 784 + 379 passed; mlx-paged-attn profile 5 + 6 passed.yarn typecheck,vp lint(21 files),vp teston 75 touched and importing files: 1,426 passed.bge-nativefails at 2.7e-5 vs 5e-6: that is the NAX TF32 reranker drift fixed by fix: test precision (reranker f32, MoE autograd stop_gradient, deterministic draft parity) #348 (not in this stack's base).🤖 Generated with Claude Code