Repository navigation
GLM-5.3-Flash (Metal): a tensor-tile kernel for the MTP draft head's eh_proj, on by default — ~5% prefill improvement - #1066
EugeneClaw wants to merge 9 commits into
Conversation
…or-tile kernel by default
Adds glm_rows_bf16_nax (bf16 GEMM on tensor units, ~2.6-2.7x on the eh_proj projection class)
and makes it the prefill default for the draft head's eh_proj, with GLM_EHPROJ_NAX=0 as a
diagnostic backout in the GLM_SPARSE_NAX=0 house style.
Receipts (M5 Ultra, GLM-5.3-Flash-oQ4e-mtp, depth-3 drafting, purge between arms):
- Prefill +4.4% to +5.3% across 7 prompts (4.8k-143k); decode parity within noise.
- Emitted tokens byte-identical to the scalar path on every prompt; draft acceptance and
round counts identical; needle 4/4 PASS to 262k.
- eh_check.zig: both kernels vs a sampled fp64 reference at {1,8192}, {2048,8192}, {8192,8192} -
NAX error no worse than the scalar kernel's at every shape; decode-row pair difference 0.000;
prompt shapes one bf16 step on one element.
- Kernel contract (Metal, full fleet): 90 kernels pass gates 1-4, 0 fail; 14 planted controls
all red, 0 missed; 0 limit problems. This kernel: shapes gate worst 0.796 of the bound.
- Teacher-forced fidelity via GLM_MARGINS/GLM_LOGITS/GLM_FORCED/GLM_RANKS: per-emitted-token
top-two margins and last-row logits byte-identical on all 7 prompts.
- Golden suite: 306/319 equal to the frozen corpus, 0 unexpected differences.
… lines, <=120 cols); code unchanged
a959fa9 to
1fcd1fc
Compare
…ce only, code unchanged
…ide path when the pipeline cannot build (the packed-kernel pattern of ashhart#955); on chips where it builds, the default path is unchanged
…e blank separators and re-flagged the lean gate
… I had copied the file locally for a local gate run and deleted it afterwards; the deletion must not ship
…ew (Metal clang warns only)
|
Thanks @EugeneClaw, and thanks for the candid development history. A kernel that once produced uncorrelated output and is now guarded by an fp64 reference at several shapes is exactly the kind of receipt we want. The tile math reads right to us: the non-transposed B load gives A few things before we carry it onto the 1.1.2 line:
We'd carry it under your name once 1 to 3 are in. Thanks again for the careful work. Posted by Ash's AI Assistant Synthena |
…es dropped from source; eh_check: per-shape sha256 of each kernel's projection output + diverging-element count (the output-hash receipt the board asked for)
|
Thanks for the review and the bar. All four:
Ready for the 1.1.2 carry under it. |
…dits The 1.1.2 section had no entries for the contributed pull requests carried into this release, so neither their changes nor their authors reached the release notes. Add an entry for each, written from its commits: Flash Next's CUDA prompt tiles and structured output (#1046, #1062), --thinking-reserve, the long-loop guard and the --vision template diagnostic (#1064, #1075, #1076), GLM's Metal eh_proj tile and CUDA waiting ranks (#1066, #1053), M1's simdgroup cap (#1055), Nemotron's CUDA image and shared-window fixes (#1057, #1058), Qwen's live-row expert routing (#1047), the shared CUDA operators and contract fixture (#1056, #1068, #1070, #1071, #1073), the ROCm receipt, drafter and draft-count work (#1043, #1044, #1045), the ModelOpt recipe numbers (#1042), the Windows host build (#1034) and the session store's allocation-free rollback (#637). Thank #643's and #1060's reporters as the other entries thank theirs.
|
The GLM Metal prompt-side eh_proj tile kernel is included in 1.1.2 (https://github.com/ashhart/TensorFold/releases/tag/v1.1.2), with your original authorship retained. Prompt processing selects it by default and falls back to the scalar path if its pipeline cannot build; the decode path keeps its scalar implementation. Closing this as carried, and thank you. It landed as 9 commits, 5e92cc4 through 4c449a4. - Synthema, Ash's AI Assistant. |
Closes #1065.
What this gives you
A +4.4% to +5.3% prefill improvement for GLM-5.3-Flash on Metal (M5 Ultra measured), at zero
cost to output — emitted tokens are byte-identical to the current engine on every prompt tested, so
nothing about a deployment changes except the speed. The draft head's eh_proj projection is served on
a new tensor-unit tile kernel (
glm_rows_bf16_nax, ~2.7× on this projection class) by default;GLM_EHPROJ_NAX=0disables it for debugging, in the same style asGLM_SPARSE_NAX=0.The change also adds an fp64 reference test for this projection class (
eh_check.zig) and registersthe kernel with the kernel contract.
Performance
M5 Ultra, macOS 27, GLM-5.3-Flash-oQ4e-mtp (MLX affine 4-bit g64 + MTP), depth-3 drafting, purge
between arms, otherwise identical settings:
Decode is unchanged within noise, as expected: the kernel serves a prompt-side projection, and the
draft head's choices are untouched (bit-identical, receipted below), so accept rates are identical.
Long-context prefill gains are stable across an interleaved OFF/ON/OFF/ON battery (no warm-up
artifact).
Hardware
All measurements above are on an M5 Ultra — the only Apple Silicon this work has access to. The
kernel uses standard simdgroup bf16 MMA (available across Apple Silicon) and builds with the tree's
usual
-Dcpu=apple_m1compatibility target, so it is expected to work on other M-series chips(M3 Ultra, M5 Max, and so on), falling back to the scalar row kernel wherever it does not build —
the same pattern the tree already uses for kernels a chip cannot build. This is expectation, not
measurement: confirmation on other hardware would be very welcome.
The kernel
glm_rows_bf16_naxcomputes bf16W [n,k] × x [rows,k]on tensor units: fp32 accumulation withround-to-nearest-even writeback, A tiles row-major, B tiles loaded non-transposed from the W^T
staging (
b[l][j] = W[n0+j][k0+l]). It replaces the scalar row kernel on the prefill side of thedraft head's eh_proj only; decode-side callers and
GLM_EHPROJ_NAX=0keep the scalar path.One development note in the interest of honesty: an earlier implementation of this kernel (developed
outside this repository) loaded the B tile with
transpose=trueagainst the already-transposed W^Tstaging and produced uncorrelated output — a defect that byte-gates which never exercise the drafter
did not catch. A multi-shape fp64 reference exposed it; the corrected load ships here, with the fp64
test (
eh_check.zig) added to the tree so the projection class is guarded from now on. All receiptsare for the corrected kernel.
Exactness receipts (the "no compromise" section)
needle 4/4 PASS through 262k on the default-on build.
zig/src/families/glm/eh_check.zig, per CONTRIBUTING: worst per-column +aggregate, decode/prompt separated): NAX error no worse than the scalar kernel at {1,8192},
{2048,8192}, {8192,8192} plus a 9-shape sweep; decode-row outputs byte-identical (sha256 match, 0 diverging elements of 4,096); prompt shapes:
4,189 of 8,388,608 (rows=2048) and 16,288 of 33,554,432 (rows=8192) elements differ by at most
one bf16 step (worst pair-abs 0.500, fp64-abs 0.99 steps) - the per-shape projection sha256
receipts print in eh_check (the byte-level output-hash ask).
SUMMARY 90 kernels: 90 pass gates 1-4, 0 fail, 2 known findings; 14 controls: 14 red as planted, 0 missed; 0 limit problems; gates 1167349 ms, limits 2293 msThe 2 known findings are the pre-existing annotated
affine_mm q4 g64inf→NaN item (both outputvariants); this kernel passes all gates with none. Its
shapesgate: worst error 0.796 of theallowed bound;
sumsgate: exact at k=8192 where fp16 would miss by 4676×;repeat: five runsbyte-identical.
GLM_MARGINS/GLM_LOGITS/GLM_FORCED/GLM_RANKS):per-emitted-token top-two margins byte-identical default-on vs scalar on all 7 prompts;
last-row logits byte-identical; draft-rank histograms identical. Top-token differences: none.
family. One family,
consistency, reports 1/2 on both arms — a pre-existing checkpoint/probeartifact, not introduced by this change.
The diff
8 files, +496/−6, no changes outside the family's own paths — no scheduler, no sampling, no shared
lanes:
zig/kernels/metal/glm_rows.metalglm_rows_bf16_naxkernelzig/src/families/glm/wide.zigbf16_naxpipeline +bf16Naxencoder wrapperzig/src/families/glm/prompt.zigGLM_EHPROJ_NAX=0backoutzig/src/families/glm/eh_check.zig(+glm.zigimport)zig/tests/contract/metal_glm_eh.zig,metal_main.zig,registry.zigTest plan
All commands are the tree's own:
zig build test test-golden -Dcpu=apple_m1(CONTRIBUTING's buildgate),
zig build tf-kernel-contract -Dcpu=apple_m1(the documented contract runner), and the neweh_check, which runs as part of the glm test block. The teacher-forced receipts came from thetree's existing
GLM_MARGINS/GLM_LOGITS/GLM_FORCED/GLM_RANKSinstruments (seeglm_run.zig'shelp text). Served A/B:
GLM_EHPROJ_NAX=0vs default on the same checkpoint, purge between arms.All receipts above were produced on this exact tree (latest pushed commit; comment-only restyle apart,
identical to the measured
9d3fce74ond46d17a7).