Repository navigation
perf(models): fold the remaining hand-masked MLA prefills into SDPA - #3114
Merged
Merged
Conversation
GLM4MoeLite (and its pipeline stage), KimiLinear's MLA layers, KimiK3 and LongcatFlashNgram built an f32 [L, L + offset] causal mask per forward and added it to a dense [B, H, L, S] rope-score tensor passed to SDPA as an additive mask, or to hand-built score and softmax tensors. Their multi-token steps now call mla::rope_folded_attention with MLX's causal mode in both the absorbed and materializing branches; a caller mask is still applied as given, and single-token decode is unchanged. The GLM4MoeLite stage executor passes no mask, matching the single-process model, and the now-unused execute_with_computed_mask_last_row helper is removed. On GLM-4.7-Flash at 22.7K tokens (M5 Max) 2048-chunk prefill drops from 35-50 s to 12.3 s and peak from 28.8 to 20.5 GB with identical greedy output; the single pass, which hit a Metal GPU timeout at 82.8 GB on main, completes at 24.1 GB. Teacher-forced trace: 0.06-0.09% disagreement on decided positions. New unit tests compare the folded prefill against the unchanged single-token path (or KimiK3's unabsorbed reference) on tiny random weights for every family, and a two-stage GLM4MoeLite split against the single-process model. The create_causal_mask roster drops from 21 to 17 files. Closes #3099
inureyes
marked this pull request as ready for review
November 16, 2026 05:49
This was referenced Nov 16, 2026
inureyes
added a commit
that referenced
this pull request
Nov 18, 2026
…ts (#3152) * update(mla): absorb DeepSeek V2 by default on ROCm, add gfx1151 results Issue #3133 measured the 2026-11 MLA and prefill-memory changes on CUDA (#3149) and left ROCm unmeasured for lack of a host. On a gfx1151 host the composed absorbed path decodes 3.4% behind the decompressed layout at 512 tokens (median of five runs per arm), 17% ahead behind 2K and 65% ahead behind 16K, where the phase peak drops from 16.06 to 12.39 GB, with 0 decided disagreements in the teacher-forced trace, so #3102's switch rule holds there too. `mla::default_absorbs_on` now makes the unset `MLXCEL_MLA_ABSORBED` absorb on ROCm as well; the CPU backend and Metal with the fused kernel off keep the decompressed default. `kv_arch` already reads `mla::absorbed_enabled()`, so V2-Lite at 32K now estimates 972.0 MiB of KV instead of 8.44 GiB. Adds the gfx1151 decode, trace and prefill-peak results: GLM-4.7-Flash fits a 28K single pass in 21.13 GB where the pre-#3114 tree asks for 62.72 GB, prefills 3.0x faster with 2048-token chunks, and gpt-oss-20b stays unchanged as designed. Llama 4 Scout did not fit on the host and is not recorded. * docs(mla): record ROCm results provenance and qualify the sizing claim The gfx1151 record is the evidence behind the new ROCm default, so its provenance and its weakest cell have to stand on their own. The CSVs now carry the measured commit (`c27b86f4`) like the CUDA rows, section 7 says which binary produced the `inspect` rows, and the record lists the MLX pin and ROCm overlay commit. Section 4 notes the 26.43 GB gpt-oss branch run instead of presenting both arms as 26.21 GB, the GLM failure is recorded as an allocation rather than an inferred mask array, and the Gate section replaces `PENDING` with what actually ran: the two narrow suites pass and the full local `make verify-rocm-held` was stopped by the memory guard, so hosted CI carries the rest. The docs no longer say the composed path is level with or ahead at 512 tokens on ROCm; the measured median is 3.4% behind there, and the claim is now within a few percent at 512 and ahead from 2K. The top-level layout summary and the family table now name ROCm. Refs #3133 * docs(mla): record the completed ROCm gate for the gfx1151 run The full local gate did run: a second attempt with the job cap lowered to three passed every prerequisite and the workspace tests (192 binaries, 15,954 passed). The first attempt was the one the memory guard stopped, so the record now says both. Refs #3133 * docs: add technical report for PR #3152
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GLM4MoeLite (and its pipeline stage), KimiLinear's MLA layers, KimiK3 and LongcatFlashNgram run every multi-token step through
mla::rope_folded_attention(#3083) with MLX's causal mode, in both the absorbed and materializing branches. They no longer build the f32[L, L + offset]mask or the dense[B, H, L, S]rope-score tensor, and the Kimi models no longer build hand-made score and softmax tensors. A caller mask is still applied as given (the GLM4MoeLite MTP drafter keeps its own). Single-token decode is unchanged. The GLM4MoeLite stage executor passes no mask, like the single-process model. Its now-unusedexecute_with_computed_mask_last_rowhelper is removed.Measurements (M5 Max, main
00cd2d69vs branch, two reps, order reversed)The GLM-4.7-Flash teacher-forced logit trace (rope folding reorders the score sum) shows 2 / 3335 (0.060%) disagreement on decided positions at width 2048 cold, and 3 / 3360 (0.089%) at width 4096 behind 2048 context. 81 to 83% of disagreements land at the reference's rank 2, and perplexity moves +0.23% / +0.05%. The overall 6% top-1 rate is near-ties on bf16 logits where one ulp is 0.5. Details are in
docs/benchmark_results/mla-prefill-rope-fold-remaining-m5max-2026-11-15.md.Covered only by unit tests (no local checkpoint): KimiLinear and LongcatFlashNgram (
longcat_flash,longcat_flash_ngram). The GLM4MoeLite pipeline stage is also covered only by unit tests.kimi-k3-2l-mla-synthis a two-layer truncation with degenerate text. It exercises KimiK3's MLA layer but not real-quality output.Test plan
models::glm4_moe_lite*(37),models::kimi_linear(13),models::kimi_k3(30),models::longcat_flash_ngram(14),stage_executor::glm4(2),mlxcel-coremla::(53) andcreate_causal_mask_roster_count_matches_repo(roster 21 to 17) all pass.cargo fmt --check, narrow clippy formlxcelandmlxcel-core,check_env_var_docs.py,check_benchmark_raw_logs.py,make verify-kernel-dtype-keysCloses #3099