Skip to content

perf(mla): absorb DeepSeek V2 decode by default where the fused kernel runs - #3136

Merged
inureyes merged 3 commits into
mainfrom
update/issue-3131-mla-absorbed-default
Nov 16, 2026
Merged

inureyes merged 3 commits into
mainfrom
update/issue-3131-mla-absorbed-default

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

  • MLXCEL_MLA_ABSORBED is a tri-state (mla::AbsorbedMode). On spellings force absorbed decode on every backend and off spellings force decompressed. Unset or unrecognized resolves to absorbed only where mla::fused_decode_enabled() holds (Metal port, MLXCEL_MLA_FUSED_DECODE not off), because the evidence for the switch is Metal plus fused kernel only. CUDA and ROCm keep decompressed by default until test(bench): measure the 2026-11 memory and MLA changes on CUDA and ROCm #3133 measures them. A unit test covers the resolution table.
  • Under the default, DeepSeek V2's fold report is a tracing info line. Explicit =1 and any decline still print to stderr. The per-cache declines (non-FP16 KV modes, paged caches) are unchanged.
  • tests/deepseek_v2_greedy_parity.rs is now teacher-forced and tolerates a different argmax only within 0.0625 logits of the top (at most 2 of 20 steps). The fused kernel scores . and , both at 29.094 at step 1, where the decompressed reference has 29.109 / 29.094 (one f16 ULP). Free-running, that one tie changed every later token. A bidirectional prefill (fix(models): deepseek_v2 generates degenerate output on a real checkpoint while mlx-lm is correct on the same weights #991) still misses by whole logits.
  • Kimi-VL validated on the fused kernel. No defect was found.
  • Docs: docs/mla-absorbed-decode.md, docs/environment-variables.md, CHANGELOG, and new results in docs/benchmark_results/mla-absorbed-default-m5max-2026-11-16.md (CSV + md).

Measurements (M5 Max, release build of this branch)

The host was shared with another unit's builds, so absolute rates run 10 to 18% below #3121's quiet sweep. Every GPU run held the lock and the arms were interleaved. Throughput is mlxcel-bench-decode tg128, median tok/s.

prompt V2 default V2 =0 Kimi-VL fused Kimi-VL fused off
512 (6 runs) 168.5 171.3 -1.7% 159.5 149.4 +6.7%
2048 (4 runs) 153.5 150.9 +1.8% 149.8 139.2 +7.5%
16384 (1 run) 105.8 71.4 +48%

Teacher-forced trace (examples/logit_trace, compare_logit_traces.py --decided 2, width-one decode, MLXCEL_TRACE_MLA_STATS=1):

model context decided disagree top-1 disagree candidate path
V2-Lite, default vs =0 1024 0 / 209 4 / 512 absorbed_fused=13824
V2-Lite, default vs =0 4096 0 / 106 0 / 256 absorbed_fused=6912
Kimi-VL, fused vs off 1024 0 / 192 2 / 512 absorbed_fused=13824
Kimi-VL, fused vs off 4096 0 / 50 2 / 256 absorbed_fused=6912

Every disagreement falls where the reference's top two were within 0.11 logits.

Test plan

  • cargo test -p mlxcel-core --lib mla::, -p mlxcel --lib deepseek (164 tests)
  • tests/deepseek_v2_greedy_parity.rs and tests/deepseek_vl_v2_parity.rs under the default, MLXCEL_MLA_ABSORBED=0, =1 and MLXCEL_MLA_FUSED_DECODE=0
  • deepseek-vl2-small-4bit generates the same greedy text (text and image prompts) under both layouts
  • Scoped clippy on mlxcel-core and mlxcel (--lib --tests), cargo fmt --check, make verify-env-var-docs
  • Workspace-wide gate is left to CI. This unit runs scoped tests only on the shared host.

Closes #3131

…l runs

#3121 brought absorbed MLA decode to within 2% of the decompressed layout at pp512 and ahead from 2K tokens on, with no decided-position disagreement, so both of #3102's switch conditions hold on Metal.

MLXCEL_MLA_ABSORBED becomes a tri-state (mla::AbsorbedMode). An on spelling forces absorbed on every backend and keeps the stderr fold report, and an off spelling forces the decompressed layout. Unset or unrecognized resolves to absorbed only where mla::fused_decode_enabled() holds (Metal port, MLXCEL_MLA_FUSED_DECODE not off). Other backends keep decompressed until #3133 measures them. Under the default the fold report is a tracing info line, and a decline still goes to stderr. The existing per-cache declines (non-FP16 KV modes, paged caches) are unchanged.

The mlx-lm greedy parity test is now teacher-forced and tolerates a different argmax only within 0.0625 logits of the top. The fused kernel ties `.` and `,` at step 1, where the decompressed reference has them one f16 ULP apart, and in free-running mode that one tie changed every later token.

Kimi-VL (deepseek_v3, always absorbed) was validated on the fused kernel: absorbed_fused covers every decode step, 0 decided disagreements, and decode is 7% faster. Results are in docs/benchmark_results/mla-absorbed-default-m5max-2026-11-16.md.

Closes #3131
@inureyes inureyes added status:review Under review type:performance Performance improvements priority:medium Medium priority area:models Model architectures, weights, loading, metadata area:inference Generation, sampling, decoding (incl. speculative, DRY) platform:macos macOS (Apple Silicon) specific labels Nov 16, 2026
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 16, 2026
@inureyes
inureyes marked this pull request as ready for review November 16, 2026 12:54
@inureyes
inureyes merged commit 453c085 into main Nov 16, 2026
14 checks passed
@inureyes
inureyes deleted the update/issue-3131-mla-absorbed-default branch November 16, 2026 12:54
inureyes added a commit that referenced this pull request Nov 16, 2026
…t out (#3137)

## Summary

Since #3131 and #3136, DeepSeek V2 caches the MLA latent by default wherever the fused Metal kernel runs, but `kv_arch` still sized every `deepseek_v2` config as the decompressed per-head cache: 10240 bytes per token per layer on DeepSeek-V2-Lite against the 1152 actually cached (8.9x). The figure feeds the prompt-cache snapshot budget, `mlxcel inspect` / `--estimate-memory` and the KV cache advisor. This is the sizing item of #3133, done before the release so the new default and its estimates ship together.

- `kv_arch` resolves the `deepseek_v2` layout with the loader's own decision: latent when `mla::absorbed_enabled()` holds and the KV cache is FP16 (`deepseek_v2_latent_layout`), decompressed under `MLXCEL_MLA_ABSORBED=0`, on a backend without the fused kernel, or with an int8 cache (`latent_layout_supports_mode` refuses it at runtime). The paged-cache decline cannot reach `deepseek_v2`, which does not opt into the paged decode backend.
- The always-latent families in `MLA_LATENT_CACHE_FAMILIES` (GLM-4.7-Flash, Kimi Linear, Kimi K2, ...) were also sized per head; they now size the latent.
- The advisor no longer recommends int8 KV for an absorbing DeepSeek V2: int8 turns absorption off and returns to the decompressed cache, about 4x the fp16 latent. Without absorption the int8 advice is unchanged.
- CHANGELOG: the Known Issues entry that still said V2 keeps the decompressed cache by default now describes CUDA and ROCm only, and a Fixed entry covers the sizing.

## Validation

- `execution::` and `server::prompt_cache::` lib tests pass on Metal (406), including new tests for the latent and decompressed sizes, the int8 decline, the layout rule, the process-level decision, the latent-pair families and the advisor rule. The old `mla_v2_uses_decompressed_per_head` becomes `mla_v2_uses_decompressed_per_head_without_absorption`. clippy `--lib --tests -D warnings` and fmt pass.
- `mlxcel inspect` on the published DeepSeek-V2-Lite-Chat-4bit-mlx `config.json` at 32768 tokens: KV cache 8.44 GiB before, 972.0 MiB after (M3 Ultra, absorbed by default; 31104 instead of 276480 bytes per token), 8.44 GiB with `MLXCEL_MLA_ABSORBED=0`, 4.22 GiB (decompressed) with an int8 cache.

Not done here: the CUDA/ROCm measurements in #3133, which decide whether the default (and with it the sizing) changes on those backends.

Refs #3133
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) area:models Model architectures, weights, loading, metadata platform:macos macOS (Apple Silicon) specific priority:medium Medium priority status:done Completed type:performance Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(mla): make absorbed decode the DeepSeek V2 default and validate Kimi-VL on the fused kernel

1 participant