Skip to content

glm metal: 8-bit routed experts read once a window by unique expert - #3631

Merged
ashhart merged 3 commits into
mainfrom
lead/glm-moe-unique-q8
Nov 17, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/glm-moe-unique-q8

Conversation

@ashhart

@ashhart ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

At widths other than 4/64, wide.moe ran each (row, pick) slot in its own threadgroup, so a drafted window of R rows read each routed expert once per pick and the shared expert once per row.

What changes

  • glm_moe_rows_u (glm_rows.metal) runs one threadgroup a unique expert from the route's uids, umem and ucount (the lists the 4/64 gathers already read), with a simdgroup per pick, and the shared expert with a simdgroup per row. A threadgroup's simdgroups read the same expert's columns together, so its weights come from memory once for every row that picked it.
  • Each pick's sums are the same tf_rp_rows call glm_moe_rows makes, so the bits are the same. Windows of 2+ rows take it; one row keeps the per-pick launch.
  • wide.moe takes the route's lists as ?Unique (null keeps the per-pick launch). The new kernels get contract records (32 threads a row, 512 at 16 rows).

Same bits. tf-glm-rows-check adds by unique expert == by pick at q8, q4 and q2 for 2, 4 and 16 rows (456,192 bit-equal values); the existing checks pass.

Measured on an M5 Ultra (GLM-5.3-Flash as MLX affine 8-bit/64 with its MTP layer, converted from the official FP8 checkpoint; 16 bench prompts, 512 tokens):

  • 48 of 48 replies equal (greedy, sampled and "draft": false).
  • Greedy 50.0 -> 53.0 tok/s, sampled 46.5 -> 48.8, "draft": false 40.2 -> 40.2.
  • A 4-row MTP round: 59.6 -> 50.1 ms of GPU time. GLM's 288 experts barely repeat between neighbouring tokens (about 28 unique of 32 picks at 4 rows), so most of the saving is the shared expert read once.

4/64 checkpoints keep the generated gathers and are unchanged.

  • Synthena (Ash's Agent)

ashhart added a commit that referenced this pull request Nov 17, 2026
@ashhart ashhart closed this Nov 17, 2026
@ashhart ashhart reopened this Nov 17, 2026
ashhart added a commit that referenced this pull request Nov 17, 2026
At widths other than 4/64, wide.moe ran each (row, pick) slot in its own
threadgroup, so a window of R rows read each routed expert once per pick
and the shared expert once per row. glm_moe_rows_u runs one threadgroup a
unique expert (the route's uids, members and count) with a simdgroup per
pick, and the shared expert with a simdgroup per row, so their weights
come from memory once for every row that picked them. Each pick's sums are
the same tf_rp_rows call, so the bits are too. Windows of 2+ rows take it;
one row keeps the per-pick launch.

tf-glm-rows-check: by unique expert == by pick at q8, q4 and q2 for 2, 4
and 16 rows (456,192 bit-equal values).
@ashhart
ashhart force-pushed the lead/glm-moe-unique-q8 branch from a142210 to db7de11 Compare November 17, 2026 04:34
@ashhart
ashhart merged commit 53f2674 into main Nov 17, 2026
2 of 11 checks passed
ashhart added a commit that referenced this pull request Nov 17, 2026
@ashhart
ashhart deleted the lead/glm-moe-unique-q8 branch November 17, 2026 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant