Skip to content

GLM: run the fragment check at load - #745

Merged
ashhart merged 1 commit into
ashhart:mainfrom
harrisonfriia:pr/glm-frag-check
Oct 13, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
harrisonfriia:pr/glm-frag-check

Conversation

@harrisonfriia

Copy link
Copy Markdown
Contributor

What this changes

GLM's prompt kernels and decode attention use nax.h's fragment layout: simdgroup matrices before M5, and tensor units on M5. Nemotron and Flash Next verify that layout with frags.check at every load, but GLM doesn't.

This runs the same check right after GLM's kernels compile. A GPU whose layout gives wrong sums now fails the load with error.FragLayout instead of serving wrong tokens. On a GPU that passes, the load adds one small dispatch.

Part of #743.

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision: base 0efbd44, candidate d5500d6. Zig 0.17.0, native Metal, no MLX or PyTorch, Xcode 27.0 (Metal 32023.921). M3 Ultra (80-core GPU, 256 GB, macOS 27.0.1). Checkpoint TensorFold/GLM-5.3-Flash-MLX-4bit-MTP at d2b17f5253440224422b150705c1109a9a3a0368.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: token_sha from tf-glm-run with GLM_DEPTHS=0,3 and 256 tokens on the four prompts tools/zig/glm_ref.py --long 2048 writes (story, code, facts, long2048). Every candidate reply equals base token for token at both depths, and depth 3 equals depth 0: 734d8ccb649bc216, 1fee24201b70a4b2, b68f3ad0f0a28070, 9f6599659a2baa06.
  • Decode speed before and after, from tools/bench_openai.py: --tokens 256 --reps 3 --temperatures 0 against tensorfold-native serve, median tok/s base then candidate: fibonacci-raw 74.4 and 74.4 (runs 74.4 to 74.5, and 74.4 to 76.2), gpu-chat-no-think 67.6 and 68.6 (runs 67.6 to 68.4, and 67.6 to 68.7). The difference is within the runs' spread.
  • Prompt speed before and after, from tools/prefill_cold.py: not run. The change touches no prompt code, and tf-glm-run read the 2,048-token prompt in 3.99 s on both builds. Load time, one load each: tf-glm-run 29.8 s and 29.7 s, the server 32.4 s and 32.5 s.
  • Tests run, with pass, fail and skip counts:
    • M3 Ultra, zig build test test-golden -Dcpu=apple_m1: 1,505 passed, 0 failed, 8 skipped, the same as the base. 158 of 160 steps succeed. The failing step fails on the base too: core.checkpoint_metal's split-checkpoint test passes but logs checkpoint tensor text.weight stays in its file: read it through a Stage. Goldens: 309/319 equal to the frozen answers, 10 declared differences, 0 unexpected. zig build native -Dcpu=apple_m1 -Dversion=1.0.0 builds.
    • zig fmt --check build.zig zig is clean. python3 tools/zig/lean_check.py reports 539 problems, the same as the base, all inherited.
  • Not run, and why: GLM on other Macs, because none available here has room for the checkpoint. On M5, Nemotron and Flash Next already run this check at every load. Two-Mac serving, for lack of a second Mac. CUDA, because GLM has no CUDA backend.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. Drafted and plain replies are in the receipt; resume and concurrency code is unchanged.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Prompt processing is no slower than the last release. No prompt code changes.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. No new tests: the change calls an existing check, every load in this receipt passed it, and its failure path is frags.check's own.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

GLM's prompt kernels and decode attention take nax.h's fragment layout,
as Nemotron's and Flash Next's do. Those families run frags.check at
every load and stop with error.FragLayout when the layout gives wrong
sums on the GPU. GLM didn't, so a GPU with a broken layout would serve
wrong tokens. GLM now runs the same check right after its kernels
compile.
@ashhart
ashhart merged commit 0d8fbb0 into ashhart:main Oct 13, 2026
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
@ashhart

ashhart commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Thank you, @harrisonfriia. GLM reads the same fragments as Nemotron and Flash Next, so it should stop on the same check, and now it does. Your commit landed in 1.0.9 under your name (32c54f3c3), and the PR's head is merged into the history with no change to the tree (0d8fbb0ea), so GitHub shows this PR as merged.

On an M3 Ultra, GLM-5.3-Flash 4-bit with 8 of its 45 layers (GLM_LAYERS=8), against the build before your change:

  • The check runs at load. A build whose check kernel loads the transposed operand as a plain one stopped 2 s into the load with "nax.h's fragment layout is wrong on Apple M3 Ultra" and FragLayout, before serving.
  • Same replies. The real build gave 9 of 9 replies drafted equal to "draft": false (8 greedy and 1 with thinking, 256 tokens each), with every token SHA the same as before.
  • Same speed. Decode was within 0.2% and cold prefill at 2k, 8k, 16k and 32k tokens within 0.2% (A B B A), and a warm load took 5.1 s on both builds.

On two M5 Ultras, the whole model loaded through the check on both Macs, and every reply equalled 1.0.8's, with the same prompt resumes. We didn't run GLM on a single M5 Ultra for this release; the 1.0.9 notes say so.

One thing we noticed, not for this PR: the EXLR8 GLM path (glm_dsa) inlines nax.h in its prompt kernels through exlr8_prompt.zig and doesn't run the check at load yet. That looks like a natural next piece of #743.

@ashhart ashhart mentioned this pull request Oct 14, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
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.

2 participants