Skip to content

glm metal: the FP8 checkpoint's routed experts read as stored (E4M3, 128x128 scales) - #3682

Merged
ashhart merged 3 commits into
mainfrom
lead/glm-fp8-experts
Nov 17, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/glm-fp8-experts

Conversation

@ashhart

@ashhart ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

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 with weight_scale_inv loads 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_rows decodes each code exactly (the seven magnitude bits as a half's, then the sign; the scale carries the factor 256). It keeps tf_rp_rows_at's lanes and summation order: 16 codes a lane, four groups of four, one block scale for each 128-column piece, then simd_sum. The by-pick, by-unique-expert, by-ids and sorted-pair kernels take an F8 template flag through one helper, glm_expert_rows. Their affine instances are unchanged.
  • wide.zig: FP8 routed experts with the 8-bit shared expert take moe. Prompt chunks use the sorted row kernels.

Exactness

tf-glm-rows-check gains glm_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.

MLX 8-bit experts FP8 experts
Weights in buffers 337.2 GB 318.6 GB
Prose, greedy (6 bench prompts, 512 tokens) 55.7 tok/s 60.8 tok/s
Prose, sampled (T 1.0, seed 1234) 53.6 tok/s 57.7 tok/s
Prose, "draft": false 41.7 tok/s 42.5 tok/s
Agent replies (file rewrite, config edit, quoting code), greedy 97.9 tok/s 111.3 tok/s
Agent replies, sampled 94.4 tok/s 104.0 tok/s

Replies 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

  • The tool that assembles such a checkpoint.
  • FP8 for the shared expert, the dense MLP and the MLA projections.
  • A tensor-unit prompt path for FP8 experts.

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, then tf-glm-rows-check (PASS), the serve benches above and the loss gate. The lean check reports 0 new problems.

  • Synthena (Ash's Agent)

ashhart added a commit that referenced this pull request Nov 17, 2026
@ashhart
ashhart force-pushed the lead/glm-fp8-experts branch from 6d5fb85 to 3e17494 Compare November 17, 2026 12:44
@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
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
ashhart force-pushed the lead/glm-fp8-experts branch from 3e17494 to b5ec069 Compare November 17, 2026 16:09
@ashhart
ashhart merged commit 9a46df9 into main Nov 17, 2026
10 of 11 checks passed
@ashhart
ashhart deleted the lead/glm-fp8-experts branch November 17, 2026 16:10
ashhart added a commit that referenced this pull request Nov 17, 2026
Seven duplicate entries go (a PR's own line beside its lines-file line), five outside authors are thanked, #1503 gets the line its close note promised, and eleven lines now match their PRs' code and receipts (#3129, #3194, #3258, #2696, #2921, #3365, #3345, #3384, #3679, #3682, #3699, #3393).
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