Repository navigation
Description
Requires a CUDA host (and a ROCm host if one is available). It cannot be done on the macOS development machine.
Problem
These 2026-11 changes were measured only on Apple Silicon (M5 Max):
- perf(models): fold the remaining hand-masked MLA prefills into SDPA #3114: MLA prefill through SDPA causal mode
- fix(models): keep Llama 4 chunked decode inside the query's chunk #3117: Llama 4 chunked decode
- perf(models): run attention-sink prefill in MLX causal and window mode #3119: attention-sink prefill in causal/window mode
- fix(models): apply Llama 4's traditional llama3-scaled RoPE #3126: Llama 4 traditional llama3-scaled RoPE
- perf(mla): quantized folds and a fused kernel for absorbed decode #3129: quantized MLA folds plus the fused absorbed-decode kernel, which is Metal-only (
src/lib/mlxcelverse/kernels/mla_absorbed_decode.cpp);mla::fused_decode_enabled()(src/lib/mlxcel-core/src/mla/mod.rs:144) routes non-Metal backends to the composed path
The quantized folds and the causal-mode dispatch run on every backend, so a CUDA or ROCm regression would currently go unnoticed.
Acceptance Criteria
- The gate (
cargo test --workspace --profile test-fast --features cuda) passes on the CUDA host, failures triaged (GB10: 15910 passed, 0 failed with one OOM test skipped; blockers filed as fix(tests): two test-only defects keepmake verify-test-cudafrom completing on GB10 #3147) - glm-4.7-flash prefill: peak memory and prefill throughput, before vs after perf(models): fold the remaining hand-masked MLA prefills into SDPA #3114
- gpt-oss-20b single-pass prefill: peak memory and throughput, before vs after perf(models): run attention-sink prefill in MLX causal and window mode #3119 (unchanged on CUDA by design)
- Llama 4 Scout decode past 8192 tokens: throughput and a teacher-forced trace (fix(models): keep Llama 4 chunked decode inside the query's chunk #3117, fix(models): apply Llama 4's traditional llama3-scaled RoPE #3126); the CUDA decode defect found here was fixed in fix(cuda): reject mid-buffer KV slices in the cuDNN decode test #3138
- DeepSeek V2-Lite absorbed (
MLXCEL_MLA_ABSORBED=1) vs decompressed decode at pp512/tg128 and a 16K prompt, withMLXCEL_TRACE_MLA_STATS=1showingabsorbed_composed(notabsorbed_fused) and a trace (examples/logit_trace,scripts/compare_logit_traces.py --decided 2) confirming the composed fallback is correct - Results recorded under
docs/benchmark_results/(one file per host, named likefused-gelu-tanh-f32-cuda-gb10-2026-11-11.md), with the binary built from the measured commit - Any defect found is filed or fixed separately (fix(cuda): reject mid-buffer KV slices in the cuDNN decode test #3138 fixed, fix: paged_detach trim tests trip debug_assert on stub handle offsets #3140, fix(tests): two test-only defects keep
make verify-test-cudafrom completing on GB10 #3147 filed)
On GB10 hosts run GPU work under gpu-lock run --tag <purpose> -- <command>.
Added: DeepSeek V2 KV sizing follows the runtime layout
Since #3136, DeepSeek V2 caches the MLA latent by default wherever the fused Metal kernel runs: mla::absorbed_enabled(), which is AbsorbedMode::resolve(fused_decode_enabled()). src/execution/kv_arch.rs still classifies every deepseek_v2 config as KvArchKind::MlaDecompressed (around line 370) and sizes it per head. On V2-Lite that is 10240 bytes/token/layer against the 1152 actually cached (8.9x). The estimate feeds prompt-cache snapshot sizing (src/server/prompt_cache/snapshot_sizing.rs) and the KV cache advisor (src/execution/kv_cache_advisor.rs). Overcounting is safe for budgeting, but it shrinks the prompt-cache budget and skews the advisor's recommendation on Metal. This item belongs here because the CUDA/ROCm measurement above decides whether the default, and with it the sizing, changes on those backends too.
-
kv_archresolves thedeepseek_v2layout through the same decision the loader uses (theMLXCEL_MLA_ABSORBEDtri-state plus fused-kernel availability), and keeps decompressed where the runtime declines absorption (non-FP16 KV modes, paged caches) - Unit tests cover latent sizing under the Metal default, decompressed under
MLXCEL_MLA_ABSORBED=0and on a backend without the fused kernel, and the decline cases. The existingmla_v2_uses_decompressed_per_headtest is updated accordingly - Prompt-cache snapshot sizing and the advisor output checked on the real V2-Lite checkpoint, before and after
- If the CUDA/ROCm measurement switches the default on those backends, the sizing follows it in the same change (CUDA switched in update(mla): absorb DeepSeek V2 by default on CUDA, add GB10 results #3149; ROCm not measured, no host)
Resolution
CUDA (GB10) measured and recorded in #3149 (docs/benchmark_results/mla-and-prefill-memory-cuda-gb10-2026-11-18.md), which also made absorbed MLA the DeepSeek V2 default on CUDA. The kv_arch items were done in #3137. ROCm was not measured because no host was available.
Activity
perf(mla): absorb DeepSeek V2 decode by default where the fused kerne…
inureyes commentedon Nov 16, 2026
Runbook for the CUDA / ROCm measurement
Everything needed to complete this issue on a Linux CUDA host (and a ROCm host if one is available). The Metal baselines it compares against are linked in each section. Report results under
docs/benchmark_results/(md plus CSV, no raw logs) in a PR that closes this issue.0. Ground rules
453c085eor a latermain, and record the exact commit in every results file.bench_decode.shstamps the commit from git, so rebuild after every checkout; the harness refuses a binary older thansrc/.gpu-lock run --tag mlxcel-3133 -- <command>. Never run two GPU jobs at once, and keep builds out of throughput runs (they cost 10 to 18% on a shared host).nvcc --version(thebackendcolumn, e.g.cuda-13.0), total memory, and whether memory is unified (GB10) or discrete.scripts/compare_logit_traces.py REF.tsv CAND.tsv --decided 2, reporting decided-position disagreement. Seedocs/benchmarks.md#judging-a-change-that-moves-the-numbers.1. Checkpoints
Download into
models/(not~/.cache/mlxcel/models) with./target/release/mlxcel download <id>:deepseek-v2-lite-chat-4bit-mlxmlx-community/DeepSeek-V2-Lite-Chat-4bit-mlxkimi-vl-a3b-thinking-4bitmlx-community/Kimi-VL-A3B-Thinking-4bitglm-4.7-flash-4bitmlx-community/GLM-4.7-Flash-4bitgpt-oss-20b-mxfp4-q4mlx-community/gpt-oss-20b-MXFP4-Q4llama-4-scout-17b-16e-instruct-4bitmlx-community/Llama-4-Scout-17B-16E-Instruct-4bit2. Build and gate
make verify-test-cudais the CUDA gate (cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1). Report the pass/fail counts and triage every failure: say whether it reproduces onmainbefore these PRs, and file anything new separately. For ROCm use--features rocmandmake verify-rocm.For the before/after cells in section 5 you also need builds of the parents of the PRs under test. Build each in its own worktree so the arms never share a
target/:3. Absorbed MLA correctness on the composed path (the main question)
On CUDA and ROCm the fused absorbed-decode kernel does not exist.
mla::fused_decode_enabled()is false, so absorbed decode takes the composed path, and since #3136 the DeepSeek V2 default there is still decompressed. Verify both facts first.Use the same corpus as the Metal run:
docs/architecture.md,docs/benchmarks.mdanddocs/turbo-kv-cache.mdconcatenated intocorpus.txt.logit_tracearguments areMODEL TEXT CHUNK_TOKENS MAX_CHUNKS TOPK PREFILL.PREFILLis consumed untraced as context, and each remaining row is traced as a width-one decode step underMLXCEL_TRACE_BATCH_ROWS=1.Expected:
v2-defshould be byte-identical tov2-dec(same path; a difference means the default did not resolve to decompressed or the CUDA path is nondeterministic, and either is worth reporting), and the stats line shows noabsorbed_*steps.MLXCEL_MLA_ABSORBED=1showsabsorbed_composed, neverabsorbed_fused.=1against=0is 0. Metal measured 0/209 at 1K and 0/106 at 4K; any decided disagreement on CUDA is a defect to investigate.Kimi-VL (a
deepseek_v3decoder, absorbed unconditionally) runs the composed path on CUDA by construction. Trace it once with"64 8 8 1024"and check that the stats showabsorbed_composedand the run finishes with finite perplexity (Metal composed reference: ppl 18.04 at 1K).4. Should CUDA switch the V2 default too?
Decode throughput,
mlxcel-bench-decode, 128 tokens, 16 warmup, median tok/s:Decision rule (the one #3102 set for Metal): switch the CUDA default to absorbed only if
=1is within a few percent of=0at 512 tokens and section 3 shows no decided disagreement. Metal had absorbed composed at about -10% at 512 before the fused kernel (#3102), so expect the CUDA composed path to fail the rule. State the measured numbers and the verdict explicitly either way. If the rule passes, changeAbsorbedMode::resolve(src/lib/mlxcel-core/src/mla/mod.rs) so the default absorbs on that backend, with a unit test and doc updates, in the same PR.Metal reference (
docs/benchmark_results/mla-absorbed-default-m5max-2026-11-16.md): 512: -1.7%, 2048: +1.8%, 16K: +48% (fused kernel).5. Prefill peak memory regressions (#3114, #3119)
Prompt:
python3 scripts/bench/metal_sdpa_chunk/make_prompt.py 28000 > prompt_28000.txt(the generator is backend-neutral despite the directory name). Measure each model with each pair of binaries (../mlxcel-pre3114vs current for GLM,../mlxcel-pre3119vs current for gpt-oss), atMLXCEL_PREFILL_CHUNK=2048andMLXCEL_PREFILL_CHUNK=0(single pass):MLXCEL_PREFILL_CHUNK=0 /usr/bin/time -v ./target/release/mlxcel generate \ -m models/glm-4.7-flash-4bit -p "$(cat prompt_28000.txt)" -n 48 --temp 0 --profile --show-reasoning/usr/bin/time -l(the macOS footprint used in the Metal tables) does not exist on Linux, and RSS does not count device memory on a discrete GPU. Record two figures:mlxcel-bench-decode -m <model> --prompt-tokens 28000 ..., line[Memory] after warmup (prefill + warmup tokens): ... phase peak X GB. This is backend-neutral and the primary number.Maximum resident set sizefrom/usr/bin/time -v. It is meaningful on unified-memory GB10 only.Also record prefill time from
--profileand whether the greedy text is identical between the arms. The old single-pass GLM path is expected to fail (on Metal it timed out building a[20, L, S]f32 score per layer). Record the error text as the result. Metal reference: GLM 2048 chunks 28.82 to 20.51 GB, single pass failed to 24.11 GB; gpt-oss-20b single pass 22.54 to 17.86 GB.6. Llama 4 Scout past the 8192 chunk (#3117, #3126, #3135)
Skip if the checkpoint does not fit; say so in the results.
./target/release/examples/logit_trace models/llama-4-scout-17b-16e-instruct-4bit corpus2.txt 9216 1 8 0 > one.tsvagainst... 4608 2 8 4608 > two.tsv, wherecorpus2.txtisdocs/architecture.mdfollowed bydocs/installation.md. Report decided disagreement (Metal: 0/3651) and the MLX peak.mlxcel generate --temp 0 -n 64on a prompt of about 8,600 tokens, withMLXCEL_PREFILL_CHUNK=0and with the default, must produce the same tokens.Metal references:
docs/benchmark_results/llama4-long-prefill-memory-m5max-2026-11-16.md,llama4-rope-m5max-2026-11-16.md.7. KV sizing follows the runtime layout (the item added to this issue)
Implement the "DeepSeek V2 KV sizing follows the runtime layout" checklist in the issue body after section 4 decides the CUDA default, so
src/execution/kv_arch.rsmatches whatever the default is on each backend. This part is pure code plus unit tests and can be developed on any host. Check the before and after numbers on the real V2-Lite checkpoint, from the KV cache advisor and prompt-cache snapshot sizing output, on CUDA (decompressed) and, if available, a Metal host (latent, 1152 vs 10240 bytes/token/layer).8. What to deliver
docs/benchmark_results/mla-and-prefill-memory-cuda-<host>-<date>.mdwith CSVs beside it (trace.csv,decode.csv,prefill-peak.csv), one file per hostkv_archchange with testsinureyes commentedon Nov 16, 2026
CUDA results (GB10, sm_121, main
5e9caf8a)Release builds on a quiet box, under
gpu-lock, ABBA order with 60 s idle between runs.Section 3, V2-Lite composed MLA. The default arm is byte-identical to
MLXCEL_MLA_ABSORBED=0at 1K and 4K. With=1, stats showabsorbed_composedonly (absorbed_fused=0), and the KV cache drops from 10240 to 1152 bytes/token/layer. Decided disagreement against=0is 0/208 at 1K (ppl 14.6543 vs 14.6582) and 0/106 at 4K (12.9485 vs 12.9960), matching Metal's 0/209 and 0/106. Kimi-VL also takes the composed path, with ppl 18.01 (Metal 18.04).Section 4, V2-Lite decode (tok/s,
-n 128, two runs per arm).=0=1At 512, absorbed is 3 to 11% slower, which misses #3102's "within a few percent" bar. Keep
=0as the CUDA default. Absorbed wins from 2048 up (2.4x at 16K), so a length-based switch is worth considering.Section 5, prefill peak memory, 28K-token prompt (MLX phase peak from
mlxcel-bench-decode).The old GLM single pass did not fail on CUDA. It peaked at 74.56 GB. After the change, its greedy output matches the chunked runs, while the old single pass differed in wording (still coherent). gpt-oss is unchanged on CUDA by design:
maskless_route_is_fusedis Metal only, so the sink prefill keeps the band, and the output is identical across trees.Section 6, Llama 4 Scout past 8192. A 9216-token single pass vs two 4608 chunks gives decided disagreement 0/3642 (Metal 0/3651), ppl 11.8001 vs 11.7992. Generation from an 8720-token prompt was garbage on CUDA (also on the pre-#3114 and pre-#3119 builds). The cause is the CUDA SDPA overlay.
is_kv_cache_slicelacked thekv.offset() != 0check, so the chunked cache's decode window, a slice that starts mid-buffer, was rebased to the buffer start, and cuDNN read the wrong keys once the window reached 256. With the check, Scout answers correctly, and a teacher-forced decode after the 8720 prefill gives 0/149 decided disagreements (NLL 1.853 vs 1.854). A regression test fails without the fix (relative rms 1.12) and passes with it. That fix goes in a separate PR.Gate.
make verify-test-cudadid not finish. The run was killed under host memory pressure inmaskless_padded_prefill_parity(olmo3 case) after 72 test binaries: 12688 passed, 0 failed, 279 ignored. The rest still needs a run.Not done here: the results doc under
docs/benchmark_results/and the section 7 kv_arch sizing change.fix(memory): size the DeepSeek V2 KV cache the way the runtime lays i…
inureyes commentedon Nov 16, 2026
The "DeepSeek V2 KV sizing follows the runtime layout" item is done in #3137 (be70b63):
kv_archsizes the latent when absorbed decode is selected and the KV cache is FP16, decompressed otherwise, and the advisor no longer advises int8 for an absorbing V2. On the V2-Lite config at 32K tokens,mlxcel inspectreports 972.0 MiB of KV instead of 8.44 GiB. The last checkbox of that item (sizing follows a CUDA/ROCm default change) stays open with the measurements above; the sizing already reads the samemla::absorbed_enabled()decision, so a default change there carries over without further code.fix(cuda): reject mid-buffer KV slices in the cuDNN decode test (#3138)
inureyes commentedon Nov 17, 2026
Section 4 follow-up: is the 512-token slowdown real?
The 3 to 11% gap at 512 decides the CUDA default, so it needs more than two runs per arm before we act on it.
Prefill does not leak into the decode figure.
DirectEngine::generatestarts the decode clock aftercomplete_prefillhas sampled and evaluated the first token (src/lib/mlxcel-core/src/engine/direct.rs,decode_start), and the rate countsgenerated - 1tokens inside that window. The absorbed cold prefill reads the latent back throughview.update_and_fetchbefore the dense SDPA (src/models/deepseek_v2.rs,forward_absorbed), so the cache write sits on the logits path and is evaluated with the first token, not deferred into the first decode step.Three explanations remain:
=1runs at 512 are 90.6 and 98.0 (8% apart) while=0is 101.8 and 101.1. Taking 98.0 alone, the gap is 3.4%, close to perf(models): decide DeepSeek V2's default MLA cache layout by measurement #3102's bar.-n 128pass reaches 640, so cuBLASLt plan selection for each new shape may land in the decode window, and more of it on the=1arm.Requested on GB10, V2-Lite, 512-token prompt, same build, quiet box,
gpu-lock, ABBA order:-n 128, default warmup, 5 runs per arm. Report median and spread. Separates 1 from the rest.-n 128 --warmup-tokens 160, 5 runs per arm. If the gap closes here, 3 is the cause.-n 512, default warmup, 3 runs per arm. A fixed first-shape cost shrinks relative to the window; a per-step cost (2) keeps the gap at the same ratio.Please include
prefill_time_msanddecode_time_msfrom the CSV and the MLA path counts the harness prints for each run, so every=1run is confirmed to have takenabsorbed_composed. If 2 holds, the length-based switch mentioned in the results comment becomes the candidate for the CUDA default; if 1 or 3 holds, the absorbed default may be fine on CUDA as is.inureyes commentedon Nov 17, 2026
Section 4 follow-up results (GB10)
Same build (main
5e9caf8a), V2-Lite 4-bit, 512-token prompt,--ignore-eos, quiet box,gpu-lock, ABBA order, 60 s idle before each run.mlxcel-bench-decodeprints no MLA counters, so the measurement build adds one line afterDecode path:printingmla::stats::snapshot().summary(). The counters are always recorded, so the measured code is unchanged. The line is not committed.Decode tok/s, median (min to max):
=0=1=1vs=0-n 128, default warmup (20), 5 runs-n 128 --warmup-tokens 160, 5 runs-n 512, default warmup, 3 runsThe 64.01 run (
=0,-n 512, rep 6) is a single outlier; the other two=0runs are 96.03 and 93.47. Prefill is 1942 to 1999 ms in every run, with no arm difference.Every
=1run took the composed path:absorbed_composed= 3942 / 7722 / 14310 per cell, andabsorbed_fused=0. Each=0run shows onlydecompressed. The 54decompressedcalls in each=1run are the two cold prefills (27 layers each), which matchesabsorbed_prefill=0. The counts are cumulative over the warmup and measured passes.Reading. This is explanation 1, noise. With five runs, each arm spans 4 to 8% from run to run, and the medians are within 3% in every cell, with
=1never behind. The first round's 90.6 was a low run of the same kind (the second=1run there was 98.0). The longer warmup does not change the ratio (3), and-n 512keeps the arms level rather than at a fixed per-step gap (2). Together with the 0/208 and 0/106 decided disagreements above,=1meets #3102's bar on CUDA. Switching the CUDA default to absorbed needs no length-based switch. This replaces the "keep=0" recommendation in my results comment above.Per-run data
=1=0=0=1=1=0=0=1=1=0=1=0=0=1=1=0=0=1=1=0=1=0=0=1=1=0inureyes commentedon Nov 17, 2026
CUDA gate (GB10, main
fab141b1)cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1 --skip glm4v_moe_maskless_padded_prefill_matches_unpadded: all 184 test binaries ran, 15910 passed, 0 failed, 498 ignored.The one skip is needed because the plain
make verify-test-cudacannot finish on this 121 GB host. The kernel OOM killer stopped it twice insidetests/maskless_padded_prefill_parity.rs: glm4v_moe alone takes MemAvailable from 101 GB to 13 GB, and memory from earlier tests in the binary is not returned. That run also hit one failure indistributed::stage_assignment::coordinator_names_peers_that_did_not_commit, which then passed 5 of 5 times alone and in the full run above; it is a port reservation race in the test helper. Both are filed as #3147.Defects found while working on this issue: #3138 (CUDA SDPA mid-buffer KV, fixed and merged), #3140, #3147.
inureyes commentedon Nov 18, 2026
ROCm row (gfx1151) and the default it implies
The CUDA row (#3149) is above; this fills the ROCm row #3133 was closed without. Host: Ryzen AI MAX+ 395 with Radeon 8060S (
gfx1151, 20 WGP), 30 GiB unified memory, HIP 7.15, release build fromc27b86f4with--features rocm, every GPU run under the ROCm guard lock, ABBA order with 60 s idle before each run.Section 3 (absorbed MLA on the composed path).
MLXCEL_MLA_ABSORBED=1tracesabsorbed_composedon every step andabsorbed_fused=0, as expected without a fused kernel. Decided-position disagreements against=0: 0 of 208 behind 1024 tokens and 0 of 105 behind 4096 (top-1 disagrees 6 of 512 and 3 of 256, all where the reference's own top two sat within 0.25 logits). Kimi-VL runs the composed path too (absorbed_composed=13824), ppl 17.97 against the Metal composed reference of 18.04. The unset default on the measured commit still resolved to decompressed and traced byte-identical to=0.Section 4 (should ROCm switch the default). decode tok/s, deepseek-v2-lite, tg128:
=0=1composedThe 512 cell was measured twice (the first pair read +5.6% with a 14% spread in the decompressed arm); the five-run repeat puts the composed path 3.4% behind, inside the band the Metal switch was made under, with a 3.7 GB smaller phase peak behind 16K. Both of #3102's conditions therefore hold, so the V2 default now absorbs on ROCm as it does on CUDA.
Section 5 (prefill peak). GLM-4.7-Flash 2048-token chunks: 25.26 to 20.53 GB; a 28K single pass that asked for 62.72 GB on the pre-#3114 tree now fits in 21.13 GB;
generateprefill 919.2 to 306.9 s (3.0x). gpt-oss-20b is unchanged at 26.21 GB and its single pass fails on both trees as designed.Not covered. Llama 4 Scout (about 61 GB) does not fit this host.
make verify-rocm-heldwas stopped by the harness memory guard on this 30 GiB machine, so the gate half is hosted CI plus the narrow runs listed in the PR.Results:
docs/benchmark_results/mla-and-prefill-memory-rocm-gfx1151-2026-11-18.mdwith per-run CSVs. Code and docs land in #3152.docs(mla): record ROCm results provenance and qualify the sizing claim
docs(mla): record the completed ROCm gate for the gfx1151 run
inureyes commentedon Nov 18, 2026
The ROCm row is measured now, on a gfx1151 host (Ryzen AI MAX+ 395, Radeon 8060S, 30 GiB unified memory, HIP 7.15.26333, MLX pin
fc344c98, overlay75915908). Results record:docs/benchmark_results/mla-and-prefill-memory-rocm-gfx1151-2026-11-18.md, carried by #3152.Measured
MLXCEL_MLA_ABSORBED=1(composed path) against=0with teacher-forced traces. Kimi-VL countsabsorbed_composedonly, ppl 17.9719.generateprefill from 919.2 s to 306.9 s. A 28K single pass that fails to allocate 62.72 GB on the pre-perf(models): fold the remaining hand-masked MLA prefills into SDPA #3114 tree now fits in 21.13 GB.mlxcel inspecton a build of the change reports 972.0 MiB of KV (12.12 GiB total) with the default and 8.44 GiB (21.10 GiB total) under=0.The switch lands in #3152:
mla::default_absorbs_onnow absorbs on ROCm, the same rule Metal and CUDA follow. The 512-token cell is 3.4% behind, inside the "within a few percent" band the Metal default was switched under (-1.7%), and the longer prompts gain 17% and 65%.Omitted, with reasons
maskless_route_is_fusedreports fusion, which is Metal-only, so CUDA and ROCm keep the band. The chunked peak (26.21 to 26.43 GB on both trees) is recorded instead, and greedy text is identical across trees.update(mla): absorb DeepSeek V2 by default on ROCm, add gfx1151 resul…
update(mla): absorb DeepSeek V2 by default on CUDA, add GB10 results (l…