Skip to content

fix: take the fused MLA decode kernel only where it evaluates - #3407

Merged
inureyes merged 1 commit into
mainfrom
fix/mla-decode-thread-cap-and-test-failures
Nov 24, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/mla-decode-thread-cap-and-test-failures

Conversation

@inureyes

Copy link
Copy Markdown
Member

Why

On an M1 Ultra, mlxcel generate on DeepSeek-V2-Lite and Youtu-LLM failed at the first decode step: Thread group size (1024) is greater than the maximum allowed threads per threadgroup (768). The fused absorbed-MLA partial pass (#3121, int8 variant #3156) always launches 1024 threads, because its output exchange is a 32 x 32 transpose across simdgroups. Metal derives each pipeline's thread limit per chip from register use. At latent rank 512 this M1 caps the dense pipeline at 768 and the int8 one at 640. The kernel was measured on chips where it fits, and the default from #3131 sends DeepSeek-V2 through it on every Metal host.

What changed

  • mla_absorbed_decode_supported and ..._quantized_supported launch the real kernel once on a one-key window at the caller's template geometry, evaluate it, and cache the result per geometry. MLX throws before the dispatch is encoded, so the stream stays usable afterward, and a test checks that.
  • fused_absorbed_decode and fused_absorbed_decode_quantized decline where the probe fails, so the step takes the composed path.
  • The DeepSeek-V2 layout default probes rank 512 / rope 64. Where the kernel cannot run it keeps the decompressed layout, which perf(mla): make absorbed decode the DeepSeek V2 default and validate Kimi-VL on the fused kernel #3131 found faster without the kernel.
  • Fixes two other tests that fail on main: FAMILY_ORDER was missing the Tencent family that Hy4 reports (feat(models): add Hy4 (hy_v4) support #3281), and the xla cache_dir test compared against a macOS /var tempdir that ensure_private_dir deliberately respells as /private/var.

I did not shrink the threadgroup. That would change the reduction order and would need a fresh logit-trace and performance measurement on the chips where the kernel runs today.

Validation (M1 Ultra)

  • New fused_decode_capacity_tests at H=16, R=512, P=64 for f16/bf16/f32 and int8. With the probe gates removed they fail with the production error (768 dense, 640 int8). With the fix they pass.
  • deepseek_v2_greedy_parity (token match against mlx-lm) passes. It aborted on main.
  • DeepSeek-V2-Lite generates 64 tokens by default (119 tok/s, decompressed), with MLXCEL_MLA_ABSORBED=1 (97 tok/s, composed) and with --kv-cache-mode int8. Youtu-LLM-2B went from the error above to coherent output. GLM-4.7-Flash and MiniCPM3 output is identical to the previous binary.
  • make verify passes: 16957 tests, 0 failed. On main the same gate had 3 failures, the ones fixed here.

The fused absorbed-MLA partial pass always launches 1024 threads (its output exchange needs 32 simdgroups), and Metal fixes each pipeline's thread limit per chip from the kernel's register use. On an M1 Ultra the pipeline at latent rank 512 is capped at 768 (640 for the int8 variant), so MLX threw at eval and every DeepSeek-V2 and Youtu-LLM decode step failed with "Thread group size (1024) is greater than the maximum allowed threads per threadgroup (768)". The kernel had only been measured on chips where it fits.

Both variants now launch the real kernel once on a one-key window at the caller's geometry, evaluate it, and cache the answer per geometry. The Rust gates check it before each launch and take the composed path where it fails, and the DeepSeek-V2 layout default probes rank 512 / rope 64, so it stays decompressed where the kernel cannot run.

Also fixes two tests that failed on main: FAMILY_ORDER lacked the "Tencent" family Hy4 reports, and the xla cache_dir test compared against an uncanonicalized macOS tempdir path.
@inureyes inureyes self-assigned this Nov 24, 2026
@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions status:review Under review priority:high High priority area:models Model architectures, weights, loading, metadata arch:moe Sparse mixture-of-experts decoder labels Nov 24, 2026
@inureyes
inureyes merged commit 2cab4ae into main Nov 24, 2026
33 checks passed
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 24, 2026
@inureyes
inureyes deleted the fix/mla-decode-thread-cap-and-test-failures branch November 24, 2026 16:09
inureyes added a commit that referenced this pull request Nov 28, 2026
Bumps every version-tracking workspace crate (mlxcel, mlxcel-core, mlxcel-mlx-pin, mlxcel-surgery, mlxcel-xla) to 0.9.0-beta.3 through `make bump-version` and syncs Cargo.lock. `make verify-versions` passes.

Renames the Unreleased changelog section to v0.9.0-beta.3 and covers the 58 commits since v0.9.0-beta.2. The existing entries are kept, and the commits that had none gain entries: the OpenXLA hybrids (Falcon-H1, Jamba, PLaMo 2, Mamba1, Falcon-Mamba) and sigmoid MoE routing, the speculative exactness work, the vision resize and parser parity fixes, ERNIE-4.5 and Nemotron 3 Nano loading, and the CLI and Responses validation fixes. Dependencies, CI/CD, Docs and Known Issues sections and the compare link are added. The chrono to jiff entry that #3462 wrote into the beta.2 section moves here. Known Issues drop #2975 and #3407, which are closed, and add the open Raon-1 mini follow-ups.

Regenerates `recipes/registry/` from a release build and repoints CURRENT. It adds `raon1_mini` and the `llava_onevision2` model type on Mage-VL, and removes nothing.

Updates the release pointers: the README main-branch line and a Raon-1 mini highlight, CITATION.cff, the bug report placeholder, the cluster note in `docs/distributed.md` and `cluster_handshake.rs`, and the version example in `TECHNICAL_REPORTS/README.md`. The reports index is unchanged because 0.9 is still the line under development; `make verify-reports-index` passes.
@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

arch:moe Sparse mixture-of-experts decoder area:models Model architectures, weights, loading, metadata priority:high High priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant