Repository navigation
feat(qwen3_5_moe): default to int8 KV where the int8 kernels serve the geometry (S3) - #343
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. |
1e6662a to
addf0f0
Compare
493942d to
9189763
Compare
…e geometry
Splash defaults every target's KV to int8 (RuntimeResourcesConfig
kvFormat = kv::Format::Int8, runtime/engine/RuntimeResources.hpp:103)
and applies that format to the target layout without a per-family
override (RuntimeResources.mm:727-728). Drop the MoE-only bf16 override
in Qwen3_5MoeConfig::to_dense_config, so MoE takes the same geometry
default as dense qwen3_5.
KvFormat::default_for_geometry now also needs a GQA factor of 1..=8:
the int8 two-pass verify runs 32 x gqa x rows threads (<= 1024), so an
8-row block (DFlash2, MTP depth >= 4) needs 4-row chunks. Splash serves
the 122B (32Q/2KV/D256, gqa 16) with its own compiled kernel
(PagedAttention.cpp:61-67: {24,4,256}, {16,2,256,_kv2_g8},
{32,2,256,_kv2_g16}, ...). mlx-node has no gqa-16 int8 verify kernel,
so at gqa 16 every flat int8 verify block of 5 to 8 rows would error.
The 122B therefore stays bf16 by default; closing that gap needs a
gqa-16 int8 verify kernel like Splash's _kv2_g16.
The DFlash2 window prices the format the cache will use, the MoE paged
parity tests pin their flat side to bf16, and the napi docs and CLI help
state the new default.
Tests:
- kv_format_default_needs_an_int8_verify_kernel (27B/35B int8, 122B,
non-divisible, D128 bf16)
- int8_verify_chunks_bound_the_default_gqa
- moe_flat_cache_precision_follows_the_geometry_default_and_explicit_format
- moe_dflash2_window_prices_the_default_format
- eager_forward_over_an_int8_cache_tracks_the_bf16_cache over every
served gqa
Co-Authored-By: Claude Opus 5.5 <[email protected]>
docs/models.md, docs/cli.md and docs/research/splash-qwen35-moe.md state that dense and MoE Qwen default to int8 KV on Metal at head 256 and GQA up to 8, following Splash (RuntimeResources.hpp:103, RuntimeResources.mm:727-728), and record the Qwen3.6-122B gap: Splash serves 32Q/2KV/D256 with its _kv2_g16 kernel (PagedAttention.cpp:61-67); mlx-node has no gqa-16 int8 verify kernel, so the 122B stays bf16. The 27B / 35B tail KL and top-1 slots and the gate table's commit and device cells are placeholders until the teacher-forced quality run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Teacher-forced vs a bf16-KV teacher (view dir with kv_format bf16), 8 x 8,192 tokens, top-k 1024, M5 Max 128 GB, 1 trial per case. 35B-A3B bf16 control: kvFormat bf16, KL 0, top-1 1 (exact). 35B-A3B default (no flag): kvFormat int8, KL 0.00467 / top-1 0.97746 raw; tail past the first 2,048-token chunk KL 0.00623 / top-1 0.96994 (1,477 of 49,144; 0.97 allows 1,474, 0.07 SE under). Raw top-1 and both KL figures pass; the default stays int8. 27B: teacher captured, the default score run failed with a GPU timeout while materializing weights; the bf16 control was not run (budget). Co-Authored-By: Claude Opus 5.5 <[email protected]>
An f16-compute load (mlx convert --dtype float16) got int8 flat K/V at head 256 / GQA <= 8: the int8 segmented SDPA verify takes BF16 queries only, so the MoE compiled DFlash2 verify failed the turn and dense fell back to the eager int8 read (whole-prefix dequantize, f32 SDPA). Splash is BF16-only (bfloat queries in its int8 kernels; f16 weights narrowed at image write). KvFormat::default_for_geometry now takes the compute dtype, and both loaders pin the format after the weights give it (the embedding's output dtype, after the MoE affine-sidecar alignment). An explicit kvFormat still wins. This also closes the dense hole open since #183. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The int8 segmented SDPA takes BF16 queries only. A MoE load with f32 layer norms (the MoE loader installs norms as stored) or an explicit int8 format on an f16 load gave f32/f16 queries, the compiled DFlash2 verify threw at the validator, and MoE turns that error into a failed turn. The Int8 arm of forward_verify_impl now casts the queries to BF16, as Splash's int8 kernels take bfloat queries; a no-op on every BF16 load. Co-Authored-By: Claude Opus 5.5 <[email protected]>
addf0f0 to
6be43ea
Compare
… (S18a) (#345) ## What Stage S18a of the Splash int8 KV alignment. It stacks on #343 (S3). The reference is Splash `9124ff2c` (1.6.0). Every block allocator now orders and reuses its cached blocks the way Splash `KvCache` does: ``` before after (Splash KvCache / MemoryLedger) LinkedHashSet LRU of hashes one u64 clock (CacheRecency) victim = oldest hash = chain HEAD victim = oldest cached LEAF nothing holds (a 4-block chain loses block 0, (A→B→C→D loses D; A→B→C still hits) so the prefix hit drops to 0) reserve: take one, retry, roll back reserve(n): take nothing unless free + evictable (evicts cached blocks, then fails) cover n, at every pool size; the caller grows first prefix cache entry cap removed (it never fired in production) ``` The stamp rules: - A block is stamped on commit, on the tip of a hit, and on release. - A parent that becomes a leaf takes `max(own, child)` (`KvCache::inherit`). - A refresh stamps nothing. ## mlx-node choices, not in Splash (labelled in code) - **Pinned-interior fallback.** When no dead leaf is left, `allocate` takes the deepest cached block whose cached children are all held. Splash moves a request onto the block it finds. mlx-node's verified-duplicate skip links the new tail under the found block, so without the fallback that block could never be reused. - **Wave gate.** At the max pool, a batched decode wave reserves all of its rows or none. Splash admits one claim at a time; mlx-node records a wave row by row. - **Turn-end stamp for kept tables.** A table kept past its turn is freed at its turn-end stamp. ## Families - **Shared allocator change:** all families that use the allocator, which are lfm2, nemotron_h, qwen3, qwen3_5 dense/MoE, qwen3_asr, k2_horizon, gemma4, muse_glimmer and qwen4_exp. - **No state marks are set yet** (S18b does that). So reusable equals evictable, and no admission decision and no qwen3_5 reclaim order changes. - **Which requests fail does not change.** The only difference is that a refused reserve no longer evicts cached blocks before it rolls back. ## Tests - 19 new tests, each with a named mutation that went red, then green after the revert. Examples: - `allocate_takes_the_chain_tail_and_keeps_the_prefix_hit` - `parent_takes_its_child_stamp` - `a_hit_touches_its_tip_only` - `reserve_evicts_nothing_it_cannot_cover` - `below_max_refused_reserve_takes_nothing_after_the_grow` - `max_pool_wave_records_nothing_it_cannot_cover` (adapter and muse_glimmer) - Gates: - `cargo fmt --check` and `cargo clippy --all-targets -D warnings` pass. - `cargo test -p mlx-paged-attn --lib` passes: 212 tests. - `cargo test -p mlx-core --lib`, run over every touched family and module, passes: 2113 tests. 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]>
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_moenow takes the same geometry default as denseqwen3_5. The old MoE-only BF16 override inQwen3_5MoeConfig::to_dense_configis removed.Splash (
031a25a6) uses int8 for every model (RuntimeResources.hpp:103,RuntimeResources.mm:727-728). It has one kernel per geometry, including_kv2_g16for 32/2/256 (PagedAttention.cpp:59-65).Gap: 122B stays BF16
mlx-node has no gqa-16 int8 verify kernel for wide blocks:
So the default adds the bound
gqa in 1..=8.kvFormat: 'bf16'(load option,--kv-format bf16, orkv_formatinconfig.json) opts out on any model. Lift: a gqa-16 int8 verify kernel, like Splash_kv2_g16.DFlash2 window (35B-A3B, M3 Pro inputs)
Quality (teacher-forced, int8 vs BF16 K/V, 8 x 8192 tokens, M5 Max)
BF16 compute only (review fixes)
1bc057823: an FP16 MoE load (mlx convert --dtype float16) got int8 K/V. Its compiled DFlash2 verify then failed the turn, becausesegmented_sdpa_int8takes only BF16 queries. Now an f16 or f32 load keeps BF16 K/V. Dense had the same hole since perf(qwen3.5, kquant): Splash-parity work — tiled K-quant layout, all ggml types, int8 KV, fused verify kernels #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 takebfloatqueries). No real checkpoint makes that mix, but no turn can abort now.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_kernelandint8_verify_chunks_bound_the_default_gqapin the gqa bound.eager_forward_over_an_int8_cache_tracks_the_bf16_cachenow covers 24x4 and 16x2, and it counts int8 kernel reads.moe_flat_cache_precision_follows_the_geometry_default_and_explicit_formatandmoe_dflash2_window_prices_the_default_formatcover the MoE flip and the window.cargo clippy --all-targets -D warnings,cargo test -p mlx-core --libon 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