Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

### Performance

- CUDA one-row MoE gathers that ran `qmm_naive` run the per-pair `gather_qmv` instead (#2784). An affine `gather_qmm` whose pairs each have one row (batched MoE decode and short prefill: `[T, 1, 1, K]` against `[T, top_k]` experts, or the same pairs sorted) took `qmm_naive` from 8 pairs on wherever `qmm_sm80` did not apply (expert N not a multiple of 128, 3/5/6-bit stacks, devices below sm_80), spending a GEMM tile on every one-row pair; it now takes the kernel the same gather already took below 8 pairs, so each pair gets the bits it gets when gathered alone. On GB10, Gemma 4 26B A4B 4-bit aggregate decode rises from 90.20 to 110.98 tok/s (+23.0%) at 4 clients and from 155.12 to 167.04 tok/s (+7.7%) at 8 with 1-client decode unchanged, the measured prompts of 8 to 127 tokens prefill 5% to 10% faster, and Qwen3-30B-A3B 3-bit, whose every expert projection took `qmm_naive`, decodes 31.7% / 27.7% / 17.8% faster at 1 / 4 / 8 clients (n = 3 each). `qmm_sm80` and the sorted grouped-GEMM prefill keep their gathers. `MLXCEL_GATHER_QMM_ONE_ROW_QMV=0` restores `qmm_naive`. A kernel that grouped the pairs by expert to read each selected expert once was tried first and was slower than this per-pair launch. Method and rows are in `docs/benchmark_results/moe-gather-one-row-qmv-gb10-2026-12-03.md`.

## [v0.9.0] - 2026-11-30

### Added
Expand Down
1 change: 1 addition & 0 deletions docs/benchmark_results/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ These remain standalone because their reports leave a substantive measurement ga
- [Scheduler-owned sequence state, decode rate on GB10](scheduler-owned-state-decode-gb10-2026-11-23.md): main against the #3254 branch for Gemma 3 and Qwen 3.5 with a null arm; no cell shows a decode regression. Gemma 3 at `B = 4` was 2% to 4% below main on a loaded host and is at or above main (+3% to +6%) on a quiet one.
- [Turbo3Asym KV host readbacks and the on-device codec on GB10](turbo3-readback-share-gb10-2026-11-27.md): the readback share before #3274 (76% / 78% / 82% of a decode step) and decode after it (4.1x / 3.8x / 4.4x); no Apple Silicon run, and no batched (B>1) decode step was timed.
- [CUDA graph commits per decode step on GB10](cuda-graph-commit-audit-gb10-2026-11-27.md): which launches pay the graph byte budget for a buffer they read part of (#3387), and the decode rate after the fused decode-MoE kernels stop paying it. MiniMax-M3 and `gemma4` were not measured on a checkpoint, the sparse path only at batch 1 on synthetic tensors, and Metal and ROCm not at all; the builtin gathers it found are left to a follow-up.
- [One-row MoE gathers on gather_qmv, GB10](moe-gather-one-row-qmv-gb10-2026-12-03.md): #2784 sends the one-row MoE gathers that ran `qmm_naive` to the per-pair `gather_qmv`: Gemma 4 26B A4B decode +23.0% at 4 clients and +7.7% at 8 (1 client unchanged), 8- to 127-token prefill 5% to 10% faster, Qwen3-30B-A3B 3-bit +17.8% to +31.7%, n = 3 with a null arm; kernel timings from 8 to 16384 pairs, and why a grouped read-each-expert-once kernel was not shipped (slower than the per-pair launch). Two checkpoints on one host; devices below sm_80 and the N1X host of #2796 were not run.
- [Qwen3.8 snapshot capacity](qwen38-snapshot-capacity-default-2026-08-30.md): sizing unit tests are not a rerun of the Apple Silicon multi-turn benchmark.
- [GB10 fused decode-MoE Dff crossover](fused-moe-dff-crossover-gb10-2026-11-11.md): the 8192 bound is confirmed by the decision rule, but no fused-path model has been measured between Dff 6400 and 14336, and the fast models' run-to-run spread is unexplained.
- [ROCm flash prefill](sdpa-flash-prefill-gfx1151-2026-10-13.md): kernel timings exist, but model-level before/after was not measured.
Expand Down
263 changes: 263 additions & 0 deletions docs/benchmark_results/moe-gather-one-row-qmv-gb10-2026-12-03.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
# One-row MoE gathers on gather_qmv instead of qmm_naive, GB10 (#2784)

Batched decode of Gemma 4 26B A4B and Qwen3-30B-A3B (3-bit), Gemma 4
short-prompt prefill, and kernel timings on one NVIDIA GB10 (sm_121, 121 GiB
unified memory), driver 580.178.04, CUDA 13.0.88, Ubuntu 24.04.5, before and
after the change. The baseline is mlxcel `9402cf893` (decode steps replayed as
CUDA graphs since #3714), MLX pinned to
`5a48f9cc2631804ea985c4289e34f0b1e4f66c60`. The main checkpoint is
`mlx-community/gemma-4-26b-a4b-it-4bit`, revision
`0d77464eeb233a2da68ebf9d7dc4edaac7db956d` (30 layers, 128 experts, top 8,
gate/up N = 704 K = 2816, down N = 2816 K = 704, affine 4-bit, group 64).

## What runs where

An expert projection hands `gather_qmm` one-row pairs: `[T, 1, 1, K]` against
`[T, top_k]` expert indices, or, from 64 pairs on, the same pairs flattened and
sorted by expert (SwitchGeGLU's sort). On the baseline `GatherQMM::eval_gpu`
ran such a gather on the per-pair `gather_qmv` below 8 pairs, and from 8 pairs
on on `qmm_sm80` where it applies (N a multiple of 128, 4 or 8 bits, sm_80 or
newer) and on `qmm_naive` everywhere else. Sorted gathers of at least
`8 * E` pairs take the dequantize + grouped GEMM path of #629 first.
`qmm_naive` spends a whole GEMM tile on each one-row pair. The change sends
those `qmm_naive` gathers to the per-pair `gather_qmv` instead, the kernel the
same gather already took below 8 pairs; `qmm_sm80` and #629 keep theirs.

For Gemma 4 26B that is gate and up (N = 704) from 8 pairs to 1023:

- batched decode from 2 clients on (16 pairs and up; 4 clients = 32 pairs,
8 clients = 64, sorted);
- prefill of prompts, or final prefill chunks, of up to 127 tokens (up to
1016 pairs). From 128 tokens (1024 pairs) #629 takes the gather, as before.

One-token decode runs the fused GeGLU MoE kernel and reaches neither kernel.

## Serving A/B

`bench_moe.py` (in this directory) starts one `mlxcel-server` per arm
(`--parallel 8 --no-prompt-cache`, default flags otherwise, decode graphs on)
and sends 1, 4 or 8 concurrent streaming chat completions, each with a
different prompt (eight topics), greedy with `ignore_eos`, 512 tokens. The rate
is the aggregate over the window in which every row is streaming. Arms rotate
per round (main, new, main again), three rounds. Before each cell the driver
waited for a 1-minute load average of at most 4 and then for the GPU to cool
to 60 C (one Qwen3 cell started at load 4.7, which rose during the
temperature wait). No other GPU process was running when a run started.

```sh
python3 bench_moe.py --main server-main --fix new=server-new \
--model gemma-4-26b-a4b-it-4bit --rounds 3 --batches 1,4,8 --out result.json
```

Gemma 4 26B A4B:

| Clients | main (6 runs), tok/s | new (3 runs), tok/s | Change |
|---:|---|---|---:|
| 1 | 73.12 (73.06 to 73.27) | 73.06 (72.97 to 73.09) | -0.1% |
| 4 | 90.20 (89.80 to 90.39) | 110.98 (110.56 to 111.12) | +23.0% |
| 8 | 155.12 (154.66 to 156.98) | 167.04 (166.89 to 167.21) | +7.7% |

Medians, with ranges. The two main arms differ by 0.12 to 0.32% in median.
At 4 and 8 clients the new arm's range clears main's. The median SM clock was
2086 or 2093 MHz in every cell. The one-client decode rate is unchanged, but
the one-client text differs from main's in every round (`176c7e8499c4` against
`6f1cbc7620f7`): the prompt is prefilled through the changed gathers (see the
next section), and a one-token decode never reaches them.

`mlx-community/Qwen3-30B-A3B-3bit`, revision
`6add5f3b9ef4219603698b4b996e20a6da6d8793` (48 layers, 128 experts, top 8,
hidden 2048, expert intermediate 768, every projection affine 3-bit, group
64), same driver and protocol. `qmm_sm80` takes only 4 and 8 bits, so on main
all three expert projections ran `qmm_naive` from 8 pairs on, and the fused
decode-MoE kernel declines 3-bit gate/up, so a one-client decode step gathers
8 pairs and is affected too:

| Clients | main (6 runs), tok/s | new (3 runs), tok/s | Change |
|---:|---|---|---:|
| 1 | 69.88 (65.35 to 72.73) | 92.01 (90.82 to 92.42) | +31.7% |
| 4 | 111.72 (110.86 to 112.34) | 142.62 (142.28 to 143.17) | +27.7% |
| 8 | 124.02 (121.69 to 124.86) | 146.13 (144.56 to 146.20) | +17.8% |

The two main arms differ by 0.26 to 0.73% in median; every new range clears
main's. The median SM clock was 2080 to 2093 MHz. The one-client text differs
from main's (`ca028e6b9d45` against `7e1bbb77b3f6`) and is the same in every
round within each arm.

## Short-prompt prefill

`ttft.py` (in this directory) starts one server per arm (default slots,
`--no-prompt-cache`) and times a non-streaming `/v1/completions` request with
`max_tokens` 1 (prefill plus one sampled token) for raw prompts of exactly L
tokens (`usage.prompt_tokens`), seven requests after one discarded, median per
server; arms rotate main, new, main over three rounds.

```sh
python3 ttft.py --main server-main --new server-new \
--model gemma-4-26b-a4b-it-4bit --lengths 8,16,32,64,96,127,128,256 --out result.json
```

| Prompt tokens | main (6 runs), ms | new (3 runs), ms | Change |
|---:|---|---|---:|
| 8 | 66.04 (65.61 to 66.63) | 60.05 (58.97 to 60.77) | -9.1% |
| 16 | 84.62 (83.94 to 85.60) | 76.26 (75.98 to 77.03) | -9.9% |
| 32 | 118.95 (118.30 to 119.71) | 109.98 (109.66 to 110.42) | -7.5% |
| 64 | 185.74 (184.89 to 186.52) | 174.39 (174.33 to 174.56) | -6.1% |
| 96 | 253.03 (251.94 to 254.57) | 238.97 (238.43 to 239.50) | -5.6% |
| 127 | 319.96 (319.26 to 321.89) | 302.56 (302.51 to 303.10) | -5.4% |
| 128 | 697.08 (692.15 to 699.42) | 697.19 (694.96 to 698.30) | 0.0% |
| 256 | 758.35 (756.08 to 760.07) | 758.35 (757.83 to 758.72) | 0.0% |

Medians of the per-server medians, with ranges. The two main arms differ by
0.03 to 0.57%. Every length gave the same first token in both arms. 128 and
256 tokens take #629 in both arms and are controls. On both binaries a
128-token prompt takes 2.2 times as long as a 127-token one: from `8 * E`
sorted pairs #629 dequantizes the whole expert stack; that is unchanged here.

## Kernel timings across pair counts

To find where the per-pair `gather_qmv` might lose to `qmm_naive`, a temporary
probe (not committed) timed one `gather_qmm` on a synthetic expert stack per
pair count, unsorted (`[T, 1, 1, K]` against `[T, top_k]` distinct experts)
and sorted (below `8 * E` pairs), as the median of seven batches of
synchronous calls, in one binary with `MLXCEL_GATHER_QMM_ONE_ROW_QMV=0`
(`qmm_naive`) and unset, alternated twice. Single calls are 0.05 to 170 ms and
include a host synchronization each, so small gathers are noisy (the two runs
of one arm differ by up to 1.5x below about 0.3 ms). Ratio of means,
`gather_qmv` / `qmm_naive`:

| Stack (E, top_k) | N | K | bits | 8 | 32 | 64 sorted | 256 sorted | 1016 sorted | 1016 | 4096 | 16384 |
|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
| Gemma 4 gate/up (128, 8) | 704 | 2816 | 4 | 0.78 | 0.69 | 0.66 | 0.89 | 0.90 | 0.59 | 0.57 | 0.56 |
| Gemma 4 gate/up (128, 8) | 704 | 2816 | 8 | 0.46 | 0.80 | 0.89 | 0.88 | 0.75 | 0.83 | 0.83 | 0.83 |
| Qwen3-30B-A3B-like gate/up (128, 8) | 768 | 2048 | 3 | 0.73 | 0.81 | 0.74 | 0.85 | 0.89 | 0.70 | 0.65 | 0.64 |
| Qwen3-30B-A3B-like down (128, 8) | 2048 | 768 | 3 | 1.43 | 1.17 | 0.93 | 0.95 | 1.07 | 0.89 | 0.87 | 0.88 |
| Qwen3-30B-A3B-like gate/up (128, 8) | 768 | 2048 | 6 | 0.62 | 0.73 | 0.75 | 0.74 | 0.57 | 0.71 | 0.69 | 0.68 |
| Qwen3-30B-A3B-like down (128, 8) | 2048 | 768 | 6 | 0.85 | 0.73 | 0.78 | 0.90 | 0.77 | 0.69 | 0.67 | 0.66 |
| synthetic (128, 8) | 704 | 704 | 4 | 0.89 | 1.15 | 0.83 | 0.98 | 1.23 | 1.06 | 1.01 | 1.05 |

Columns are pair counts, unsorted unless marked. Sorted gathers of 1024 pairs
or more take #629 on both arms and are left out. One-expert stacks with one
row per pair, as Qwen4-Exp's row-invariant projections run (K = 4096, 4-bit),
at 8 / 128 / 2048 / 8192 pairs:

| N | 8 | 128 | 2048 | 8192 |
|---:|---:|---:|---:|---:|
| 1 | 0.13 | 0.06 | 0.08 | 0.12 |
| 32 | 0.12 | 0.24 | 0.48 | 0.41 |
| 64 | 0.16 | 0.65 | 0.57 | 0.53 |

`gather_qmv` was faster almost everywhere, by up to about 2x on the 3-, 6-
and 8-bit stacks and up to 16x on the one-expert projections. Two places were
not. The synthetic 4-bit N = 704, K = 704 stack scatters around 1.0 in both
directions (0.83 to 1.23 below 1024 pairs, 1.01 to 1.06 above); no supported
model is known to run that shape off `qmm_sm80` (Gemma 4's K = 704 projection
is down, N = 2816, which keeps `qmm_sm80`). The 3-bit down at 8 and 32
unsorted pairs is slower in both runs (0.17 against 0.12 ms at 8 pairs), while
the 3-bit gate and up at the same pair counts are faster by more than that;
Qwen3-30B-A3B-3bit, where those three gathers make up a decode step's MoE
layer, is measured end to end above. So the dispatch has no upper bound on the
pair count.

## A grouped kernel that reads each expert once (not shipped)

The issue proposed grouping the pairs of a gather by expert so a selected
expert is read once rather than once per pair. That was built first (a
`gather_qmv` variant whose blocks found the other pairs of their expert with
warp ballots and applied each dequantized tile to up to eight of them, used
for one-row gathers of 8 to 256 pairs that took `qmm_naive`) and measured on
the same host, base and protocol as above, with a third arm that sent exactly
the same gathers to the per-pair `gather_qmv`, n = 3:

| Clients | main (6 runs) | grouped | per-pair `gather_qmv` |
|---:|---:|---:|---:|
| 1 | 74.62 | 74.49 (-0.2%) | 74.73 (+0.1%) |
| 4 | 87.85 | 100.89 (+14.9%) | 110.69 (+26.0%) |
| 8 | 155.75 | 159.55 (+2.4%) | 163.47 (+5.0%) |

The two arms gave the same text in every round (every pair of the grouped
kernel had the per-pair bits), and the per-pair arm was faster by 8.9% at 4
clients and 2.4% at 8: all of the gain came from leaving `qmm_naive`, and the
saved reads cost more than they saved. A bound in #2796's terms agrees that
they were never worth much: with this bench's prompts, a decode step's MoE
layer selects 27 distinct experts of 32 pairs at 4 clients and 45 of 64 at 8
(median over 2850 layer-steps; #2796 found 28 and 45 on the N1X), so at most
15.6% of the gate/up reads at 4 clients could go, which with gathers about
54% of a layer and gate/up two thirds of the gathered bytes caps the gain at
about 5 to 6%. The grouped launch had a quarter of `gather_qmv`'s blocks per
pair; that was not profiled further. Grouping the `qmm_sm80` gathers (down)
too, and leaving 64-pair decode unsorted, were both slower in one-round
screens.

## Numerics

`examples/logit_trace` over `tests/fixtures/wikitext2_excerpt.txt`, top 8,
64-token chunks (4) and 16-token chunks (16), each arm traced with the change
on and off (`MLXCEL_GATHER_QMM_ONE_ROW_QMV=0`, main's `qmm_naive`) in one
binary, compared with `scripts/compare_logit_traces.py`. "Prefill" traces each
chunk from a forward at the chunk's width (64 tokens = 512 sorted pairs, 16
tokens = 128 pairs: both take the changed gathers); "N rows" runs every
position as a width-one batched decode over N rows
(`MLXCEL_TRACE_BATCH_ROWS`). Top-1 disagreement, all positions and positions
the reference had decided (top-two gap at least 2):

Qwen3-30B-A3B 3-bit:

| Comparison | 64-token chunks | 16-token chunks |
|---|---|---|
| on vs off, prefill | 20/256 (7.8%), decided 0/91 | 21/256 (8.2%), decided 0/67 |
| on vs off, 1 row | 21/256 (8.2%), decided 0/92 | 22/256 (8.6%), decided 0/66 |
| on vs off, 4 rows | 17/256 (6.6%), decided 0/91 | 20/256 (7.8%), decided 0/67 |
| main: prefill vs 1 row | 17/256 (6.6%), decided 0/91 | 20/256 (7.8%), decided 0/67 |
| main: 1 row vs 4 rows | 12/256 (4.7%), decided 0/92 | 5/256 (2.0%), decided 0/66 |

On Qwen3-30B-A3B 3-bit (perplexity on the excerpt 74 to 75 with 64-token
chunks and 232 to 240 with 16-token chunks, every arm within 3.5% of the
others, in both directions) the change disagrees with `qmm_naive` about as
often as main's own prefill and decode kernels disagree with each other, and
never where the reference had decided. Its one-token MoE step is a gather, so
its one-row traces differ on and off.

On Gemma 4 26B A4B the one-row traces are byte-identical on and off: one-token
decode runs the fused GeGLU kernel and never reaches the changed gathers. That
makes the one-row trace (off) a reference the change does not touch, and each
arm is measured against it:

| Against the 1-row trace | 64-token chunks | 16-token chunks |
|---|---|---|
| prefill, off (main's path) | 60/256 (23.4%), decided 6/115 (5.2%) | 69/256 (27.0%), decided 8/96 (8.3%) |
| prefill, on (this change) | 62/256 (24.2%), decided 5/115 (4.3%) | 70/256 (27.3%), decided 7/96 (7.3%) |
| 4 rows, off | 53/256 (20.7%), decided 4/115 (3.5%) | 73/256 (28.5%), decided 7/96 (7.3%) |
| 4 rows, on | 54/256 (21.1%), decided 6/115 (5.2%) | 65/256 (25.4%), decided 4/96 (4.2%) |
| 8 rows, off | 55/256 (21.5%), decided 6/115 (5.2%) | 61/256 (23.8%), decided 5/96 (5.2%) |
| 8 rows, on | 60/256 (23.4%), decided 5/115 (4.3%) | 62/256 (24.2%), decided 5/96 (5.2%) |

Summed over the six cells, the change disagrees with the common reference on
32 of 633 decided positions (5.1%) and main's path on 36 of 633 (5.7%); the
change is closer in four cells, equal in one and farther in one (4 rows,
64-token chunks: 6 against 4). On all positions the two are 373 and 371 of
1536 (24.3% and 24.2%), and the largest logit move on the reference's choice
is 8.0 to 13.0 against 6.4 to 13.4. Compared directly, on against off, the
arms disagree more (decided positions, 64- and 16-token chunks: prefill
11/119 (9.2%) and 13/107 (12.2%), 4 rows 10/123 (8.1%) and 11/98 (11.2%),
8 rows 4/112 (3.6%) and 12/111 (10.8%)), because both arms of that comparison
changed the rounding, each in its own way, and two independent perturbations
tend to sit farther from each other than either sits from the reference.
Gemma 4 26B A4B is an instruct checkpoint run on raw text: its perplexity here
is 3600 to 4800 (64-token chunks) and 67000 to 110000 (16-token chunks) in
every arm, and main against itself disagrees on 21 to 29% of all positions
between batch sizes, so these traces cannot bound the change tightly; they
show it sits at main's own distance from the reference (closer in total). The
grouped kernel's direct on-against-off comparison at 4 and 8 rows (64-token
chunks) gave the same 10/123 and 4/112, as expected from identical bits.

## Limits

- Two checkpoints on one host for the end-to-end numbers. The kernel timings
cover other shapes and bit widths, but not on a checkpoint; no 6-bit or
mixed-precision MoE checkpoint and no Qwen4-Exp checkpoint was run.
- Expert gathers that take `qmm_sm80` (4- and 8-bit stacks with N a multiple
of 128: Qwen3-30B-A3B, Mixtral, Llama 4, ...) are unchanged and were not
re-measured.
- Devices below sm_80, where every one-row gather of 8 or more pairs ran
`qmm_naive`, were not measured.
- RTX Spark N1X, where #2796 measured, was not re-measured.
Loading