Repository navigation
glm metal: the FP8 checkpoint's routed experts read as stored (E4M3, 128x128 scales) - #3682
Merged
Merged
Conversation
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
ashhart
force-pushed
the
lead/glm-fp8-experts
branch
from
November 17, 2026 12:44
6d5fb85 to
3e17494
Compare
Owner
Author
|
/atc exchange 19f7758ea6cf42f6e00a693a581f3ac3419398e12f5fb191f1dc5cf94f33a610 |
# Conflicts: # CHANGELOG.md
…8x128 scales) GLM-5.3-Flash on Metal reads routed experts stored in the official FP8 checkpoint's format, E4M3 codes with f32 128 x 128 block scales, without conversion. The loader takes a shard's tensors only where the index maps them, so a combined checkpoint can point at whole FP8 shards. The FP8 row sums keep tf_rp_rows_at's lanes and order, and tf-glm-rows-check covers every FP8 launch against each other and against float64. (cherry picked from commit b3a7b87)
ashhart
force-pushed
the
lead/glm-fp8-experts
branch
from
November 17, 2026 16:09
3e17494 to
b5ec069
Compare
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.
GLM-5.3-Flash on Metal can read its routed experts in the official FP8 checkpoint's format, as stored: E4M3 codes with f32 128 x 128 block scales, no conversion. A checkpoint whose index maps the backbone's routed experts to the FP8 shards and everything else to an MLX build now loads on one Mac.
What changed
names.zig: a shard's tensors are taken only when the index maps that name to that shard. A combined checkpoint can then point at whole FP8 shards (symlinks) without their other tensors being read. Every index we ship already names each tensor once, so existing checkpoints load as before.fp8.zig(new),weights.zig,load_plan.zig: a routed expert withweight_scale_invloads as FP8, stacked[experts, n, k]codes and[experts, n / 128, k / 128]scales. It is checked by name, dtype and shape, loads whole on one Mac, and a stack that mixes FP8 and affine experts is refused by name.glm_rows.metal:glm_f8_rowsdecodes each code exactly (the seven magnitude bits as a half's, then the sign; the scale carries the factor 256). It keepstf_rp_rows_at's lanes and summation order: 16 codes a lane, four groups of four, one block scale for each 128-column piece, thensimd_sum. The by-pick, by-unique-expert, by-ids and sorted-pair kernels take anF8template flag through one helper,glm_expert_rows. Their affine instances are unchanged.wide.zig: FP8 routed experts with the 8-bit shared expert takemoe. Prompt chunks use the sorted row kernels.Exactness
tf-glm-rows-checkgainsglm_rows_fp8.zig. At 1, 2, 4 and 16 rows, FP8 experts by unique expert, by pick, by ids and as the prompt's sorted pairs give the same bits: 434,688 values. byIds is within bf16 rounding of a float64 dot of the decoded codes (worst 0.99 of the bound). The full check passes: 1,328,072 values within bound and 10,809,776 bit-equal pairs.Measurements (M5 Ultra, one stream, 131,072 context; drafts are MTP and copies)
Both builds below share the same 8-bit backbone and 4-bit MTP layer and draft head. The only difference is that the FP8 one's routed experts are the official FP8 tensors, not our MLX 8-bit conversion of them. Both builds were main plus the open decode PRs (the #3458 chain and #3402), with and without this change.
"draft": falseReplies differ between the two builds, because their weights differ. Quality was checked with the gate fixed before the run: per-token loss over a 100,000-token text through the prompt path, FP8 no worse than 1.001 x the MLX 8-bit build. FP8 experts gave 0.542561 against 0.542376, a difference of +0.034% with a standard error of 0.070% (PASS).
Not in this PR
Prompt chunks read FP8 experts with the row kernels, which on the M5 Ultra run about 2.1x slower than the 8-bit row kernels (240 against about 490 tok/s at 2K).
Tests run
On an M5 Ultra:
zig build native tf-glm-rows-check tf-glm-run -Doptimize=ReleaseFast, thentf-glm-rows-check(PASS), the serve benches above and the loss gate. The lean check reports 0 new problems.