Repository navigation
feat: serve the loaded window and K/V format to clients (int8 KV S2) - #342
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. |
25576c1 to
3ed1075
Compare
aabe08e to
cfcf4d2
Compare
f50c82f to
493942d
Compare
… /health
The registry reads contextLimits() once when a model gets its binding and
keeps a JS copy for the binding's life. servedContext(name) picks the lane
a default text turn takes (contextLane, the rule the ChatSession clamp
uses): the DFlash2 window when MTP is on by default and a speculative
window exists, else the pool window.
/v1/models carries that window as context_window, max_model_len and
context_length once the model is loaded, and the trained window before
load and after eviction. The authenticated /health body gains kv[model] =
{maximum_context_tokens, format, quantization, scale_type} (Splash /status
names); the unauthenticated minimal body is unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`mlx serve --kv-format int8|bf16` sets the flat K/V cache format of qwen3_5 / qwen3_5_moe loads; `mlx agent --kv-format` lifts the flag out of the grok argv and passes it to the spawned serve. The host hands kvFormat only to families whose family-data row sets acceptsKvFormat (the same flag the loader now checks), so a gemma4 load on the same host is unaffected. The block-paged pool ignores the option and stays bf16 (said in the help). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qwen3_5ContextLimits gains kv_format (the pool lane: bf16 on a paged load, since the block-paged pool stores BF16 whatever kv_format says; the configured flat format otherwise) and speculative_kv_format (the DFlash2 lane, from dflash2_target_kv_format, the same function its window is priced with). Dense and MoE snapshots both fill them. EvalBackend reports the K/V format its teacher-forced prefill writes, and EvalReport carries it, so `mlx eval` can name the resolved format instead of guessing from the flag. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`mlx eval score` prints `kv_format` from the native report, and `--json` takes kvFormat from it too. Before, an unset flag on dense 27B labelled an int8 run "bf16". The help names both families and the real default. Docs: draftModelPath and kvFormat cover qwen3_5_moe; the block-paged pool stays bf16 whatever kvFormat says; contextLimits() names each lane's format; `mlx serve` / `mlx agent --kv-format`; /v1/models window fields before and after load; the authenticated /health kv block; FP8 KV is dormant (every loader passes use_fp8_cache: Some(false)). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Grok reads /v1/models once at boot and caches it, so `mlx agent` now polls the spawned serve's authenticated /health until the preload is resident (or its load failed) before it starts grok; a serve exit during the wait fails the launch. No timeout: a cold load can take minutes, and Splash's launcher also starts a client only on a ready server. `mlx launch claude` loads the default model before Claude Code starts and sets CLAUDE_CODE_MAX_CONTEXT_TOKENS and CLAUDE_CODE_AUTO_COMPACT_WINDOW to the served window, as Splash install/clients.py does. A failed load is printed and Claude Code starts without them. This changes startup timing of both launchers, so it is its own commit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mlx agent waited on /health with no timeout until the preloaded model was resident or its load failed. A preload that serve rejects before the load bracket (a model its own scan no longer finds) records no lastLoad, so the agent waited forever. Serve enters the bracket in the tick that prints its banner, so nothing loading and nothing loaded after it means no load will run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The load-then-read wiring had no test: skipping the load or reading the window before it settles left every test green. loadServedWindow holds it and is tested through the real host and registry. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The named mutation (restore `kvFormat ?? 'bf16'` in the --json line) stayed green: `...report` comes after it and wins. Name the two that go red. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tartup mlx agent installed its SIGTERM/SIGHUP teardown only after the spawned serve was ready and its preload had settled. The preload wait has no timeout, so a signal during a cold load killed the launcher by the default disposition and left mlx serve running with the model resident. The handlers now go in before serve spawns and stay through readiness, preload and the agent run; a SIGINT before grok exists tears serve down and re-raises instead of forwarding. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Serve's graceful shutdown awaits in-flight model loads with no deadline, so a signal during the preload wait left serve alive (holding the model) after the launcher died. Teardown now signals serve, waits up to 10 s for it to exit, SIGKILLs it if it has not, and only then re-raises. The launcher's finally awaits the teardown so a startup failure during the grace cannot let the caller exit first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A signal during the preload wait starts the teardown while no agent exists yet. If the preload then settles inside the serve grace, the launcher went on to spawn grok, which the teardown never signals, and grok outlived the launcher. The launcher now checks the latched teardown right before spawning the agent, awaits it, and never starts grok. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The launcher's SIGINT/SIGTERM/SIGHUP handlers were process.once, and the finally removed them before awaiting the teardown. A second signal while serve used its stop grace took the default disposition and left serve running. The handlers now stay installed until the re-raise; a repeated signal SIGKILLs serve (and the agent), the teardown still waits for serve to exit, then re-raises the first signal. Co-Authored-By: Claude Opus 5.5 <[email protected]>
DELEGATE_VALUE_FLAGS lacked --kv-format, so `mlx delegate --kv-format bf16 'task'` folded bf16 into the prompt and the agent saw a bare --kv-format. The approval scan now uses the same set. Co-Authored-By: Claude Opus 5.5 <[email protected]>
493942d to
9189763
Compare
…e geometry (S3) (#343) ## What Stage 3 of the Splash int8 KV alignment. It is stacked on #342 (S2), which is stacked on #336 (S1). The flat full-attention K/V of `qwen3_5_moe` now takes the same geometry default as dense `qwen3_5`. The old MoE-only BF16 override in `Qwen3_5MoeConfig::to_dense_config` is removed. ``` KvFormat::default_for_geometry(head_dim, q_heads, kv_heads) Metal && head 256 && gqa in 1..=8 -> Int8 else -> Bf16 Qwen3.8-27B dense 24/4 gqa 6 int8 (unchanged) Qwen3.6-35B MoE 16/2 gqa 8 int8 (was BF16) <- this PR Qwen3.6-122B MoE 32/2 gqa 16 BF16 (gap) ``` Splash (`031a25a6`) uses int8 for every model (`RuntimeResources.hpp:103`, `RuntimeResources.mm:727-728`). It has one kernel per geometry, including `_kv2_g16` for 32/2/256 (`PagedAttention.cpp:59-65`). ## Gap: 122B stays BF16 mlx-node has no gqa-16 int8 verify kernel for wide blocks: ``` two-pass stage 1 = 32 x gqa x rows threads <= 1024 gqa 8 -> 4-row chunks -> 8-row verify = 4 + 4 ok gqa 16 -> 2-row chunks -> 5-8 row verify blocks error (int8 has no fallback) ``` So the default adds the bound `gqa in 1..=8`. `kvFormat: 'bf16'` (load option, `--kv-format bf16`, or `kv_format` in `config.json`) opts out on any model. Lift: a gqa-16 int8 verify kernel, like Splash `_kv2_g16`. ## DFlash2 window (35B-A3B, M3 Pro inputs) | Case | Row bytes | Window | |---|---|---| | 27B int8 (S1) | 33,280 | 139,257 | | 35B BF16 | 20,480 | 244,217 | | 35B int8 | 10,400 | **262,144** (trained cap; the pool term is 475,129) | ## Quality (teacher-forced, int8 vs BF16 K/V, 8 x 8192 tokens, M5 Max) | Model | Run | kvFormat | mean KL | top-1 | KL after 2048 | top-1 after 2048 | |---|---|---|---|---|---|---| | 35B-A3B | bf16 control | bf16 | 0 | 1 | - | - | | 35B-A3B | default (no flag) | int8 | 0.004670 | 0.977460 | 0.006226 | 0.969945 | - The stop band is top-1 < 0.97 or KL > 0.05. The whole-run numbers pass. The tail top-1 is 3 positions out of 49,144 under 0.97 (0.07 SE), so it is noise. NLL moves +0.0013 nats. - 27B was not measured in this PR. Its score run failed during the weight load with a GPU timeout. The 27B default does not change here. - DFlash2 acceptance on 35B was not run, because no local 35B draft exists. ## BF16 compute only (review fixes) ``` default_for_geometry(head, q_heads, kv_heads, compute) Int8 only if Metal && compute == BF16 && head 256 && gqa in 1..=8 load: probe the compute dtype -> pin kv_format -> build caches (dense and MoE) an explicit kvFormat still wins ``` - `1bc057823`: an FP16 MoE load (`mlx convert --dtype float16`) got int8 K/V. Its compiled DFlash2 verify then failed the turn, because `segmented_sdpa_int8` takes only BF16 queries. Now an f16 or f32 load keeps BF16 K/V. Dense had the same hole since #183 (it fell back to a slow eager path), and the same rule closes it. - `1e6662ae1`: the int8 compiled verify casts non-BF16 queries to BF16, as Splash does (its int8 kernels take `bfloat` queries). No real checkpoint makes that mix, but no turn can abort now. - Tests: `kv_format_default_needs_an_int8_verify_kernel`, `moe_load_pins_the_kv_format_for_the_compute_dtype`, `dense_load_pins_the_kv_format_for_the_compute_dtype`, `int8_compiled_verify_takes_f32_queries`. Each one went red under its named mutation. ## Tests - `kv_format_default_needs_an_int8_verify_kernel` and `int8_verify_chunks_bound_the_default_gqa` pin the gqa bound. - `eager_forward_over_an_int8_cache_tracks_the_bf16_cache` now covers 24x4 and 16x2, and it counts int8 kernel reads. - `moe_flat_cache_precision_follows_the_geometry_default_and_explicit_format` and `moe_dflash2_window_prices_the_default_format` cover the MoE flip and the window. - The two MoE paged-vs-flat parity tests pin the flat side to BF16. - Each new test went red under its named mutation and green after the revert. - Gates: `cargo clippy --all-targets -D warnings`, `cargo test -p mlx-core --lib` on the touched modules (686 passed), `yarn typecheck`, and the CLI/loader vitest files (232 passed). CI does not run on this PR until its base is `main`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Stage S2 of the Splash int8 KV alignment. This PR is stacked on #336 (S1). Merge #336 first.
What changes
Clients now see the real window and the K/V format after the model loads. Before this PR,
/v1/modelsshowed the trained window (262,144). The agent never compacted, and turns stopped with "output limit".The served window is the window of the lane that the default text turn takes. Splash does the same (
server/server.py:1830-1841,ReadyEvent.max_context_tokens).kv.format--kv-format bf16contextLimits()familyParts
/v1/modelsand/healthshowkv[model] = {maximum_context_tokens, format, quantization, scale_type}. Thecontext_windowfield stays, because grok reads it.--kv-formatonserveandagent.Qwen3_5ContextLimitshaskv_formatandspeculative_kv_format. The DFlash2 format comes from the same function that prices the window, so the two cannot disagree.mlx launch claudesetsCLAUDE_CODE_MAX_CONTEXT_TOKENSandCLAUDE_CODE_AUTO_COMPACT_WINDOWfrom the served window.Tests
yarn typecheck,vp lint,vp fmton the touched files: pass.vp test --runon 19 files: 898 passed.cargo clippy --all-targets -- -D warnings,cargo fmt --check: pass.cargo test -p mlx-core --lib(qwen3_5, qwen3_5_moe, quality, engine): 1097 passed.🤖 Generated with Claude Code