Skip to content

glm cuda: a dense MLP stored bf16 is read as bf16 in any checkpoint, not only an EXL3 one - #3680

Open
Bizuayeu wants to merge 3 commits into
ashhart:mainfrom
Bizuayeu:pr/glm-dense-bf16
Open

Bizuayeu wants to merge 3 commits into
ashhart:mainfrom
Bizuayeu:pr/glm-dense-bf16

Conversation

@Bizuayeu

@Bizuayeu Bizuayeu commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

GLM-5.3-Flash on CUDA reads a dense MLP (layers 0-2) stored as bf16 in any checkpoint. Today the loader holds those three layers as bf16 only when the checkpoint is EXL3; in a ModelOpt checkpoint it expects NVFP4 or MXFP8 there and refuses bf16 by the module's name. The forward path for a bf16 dense layer already exists (cuda_mlp.zig's .bf16 branch); this picks it from the stored dtype. A checkpoint whose dense layers are NVFP4 or MXFP8 loads as before: main's tokens at main's speed.

On two GB10s at TP=2, one stream:

main, dense MXFP8 this branch, dense MXFP8 this branch, dense bf16
Rank 0's model (GiB) 83.63 83.63 83.83
Decode, fibonacci-raw (tok/s) 24.60 24.61 24.04
Decode, gpu-chat-no-think (tok/s) 24.59 24.59 24.02
Prompt of 9,600 tokens (s) 6.756 6.746 6.750
Prompt of 38,400 tokens (s) 26.242 26.192 26.236

Every row is from launches at a 40,960-token window, MTP drafts off for decode, every prompt cold: the median of three launches on the MXFP8 checkpoint and the mean of two on the bf16 one. Each launch races GLM's classic and factored expert forms at load and keeps the winner; all eight launches kept classic. The launches ran in turn (main, branch, branch on bf16, branch, main, branch on bf16, main, branch). Pair by pair on the MXFP8 checkpoint, this branch's decode is 0.01% and 0.05% faster, 0.3% and 0.1% slower, then 0.2% and 0.1% faster, and its prompts 0.03% and 0.1% shorter, 1.9% and 2.4% shorter, then 0.1% shorter and 0.01% longer. The middle pair's 1.9% and 2.4% come from one main launch whose prompts were longer than main's other two (6.832 s against 6.748 and 6.756; 26.674 s against 26.242 and 26.191); both GPUs held their clock cap with no cap event during any launch.

The first two columns give the same tokens: the three decode-check prompts' token_sha256, drafted and with "draft": false, on all six launches. The bf16 checkpoint gives its own three hashes, the same on both launches and the same drafted as with "draft": false. main refuses that checkpoint at load: model.language_model.layers.0.mlp.gate_proj: declared no recipe (bf16), stored bf16 { 12288, 4096 }; this loader reads it as { .nvfp4 }. Dense bf16 against dense MXFP8 on this branch: 0.20 GiB more model on rank 0, decode 2.3% slower on both prompts, prompts 0.06% and 0.17% longer; not traced.

What this changes

The loader. cuda_mlp.zig gains held(exl3, stored): a dense layer is held bf16 when the checkpoint is EXL3 or the layer's gate_proj is stored bf16, MXFP8 when it is stored e4m3, else NVFP4. cuda_weights.zig's dense asks it instead of c.exl3, so the three projections are checked against one form as before (L.format), and a layer whose gate_proj is bf16 while up_proj or down_proj is not is still refused by name.

The scratch plan. cuda_state.zig's b16Shapes plans the split-K partials of the bf16 matmuls. It counted the dense shapes only for EXL3; it now counts them whenever a dense layer is held bf16. At GLM-5.3-Flash's sizes the other shapes already cover the dense ones, so nothing was short there; a model with a wider dense layer would have been. The new test uses such a config and fails on the old table.

What stays. No kernel source changes: the diff is three Zig files under zig/src/families/glm. No new option: the checkpoint's stored dtype chooses. EXL3 checkpoints take the same branch as before.

Checks on this head

  • Head commit: e5ead44be9. Every check and receipt below is from 2e86ad0764, the commit before it; e5ead44be9 changes CHANGELOG.md and docs/recipes/glm-5.3-flash-cuda.md alone, so they were not taken again.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 221 problems on both, 0 new. python3 tools/pr_check.py --base 077998f7d9: 3 changed files, lean 221 against 221 with 0 new, 0 errors; its one advisory asked for the CHANGELOG line. On e5ead44be9, python3 tools/pr_check.py --base 077998f7d9 --pr 3680: 5 changed files, lean 221 against 221 with 0 new, 0 errors and 0 warnings.
  • Tests run, with the command and pass, fail and skip counts: on x86_64 (WSL), zig build test 3,233 of 3,278 with 45 skipped (718 of 718 steps), test-golden (5 of 5 steps), test-cuda-host, compile-cuda-tests 10 of 10, compile-config-server 7 of 7, tools/zig/cuda_common_check.py and zig fmt --check. The two new tests run in the GLM CUDA host test binary (245 tests, all pass). Each fails on its own mutant and nothing else does: held put back to "bf16 only for EXL3" fails the first (expected .bf16, found .nvfp4), and a b16Shapes that leaves a bf16 dense layer out fails the second. The pytest suite CI runs, from the root with a clang++ stand-in and Zig on PATH: 520 passed and 86 skipped with 616 subtests; main's CI on the same base reads 522 passed and 84 skipped; two of the skips here give this interpreter's older Unicode table as their reason, which matches the difference in count (CI's log does not print skip reasons). On GB10 at TP=2, on the bf16 checkpoint with this head's tf-cuda-test: glm-lanes-cover 46, glm-lanes-concurrent 38 and glm-shared-check 1 pass on rank 0, with no failures on either rank.
  • CI on 2e86ad0764: every job that ran passed (fmt, zig, zig-b, zig-windows, zig-macos-dev-tools, pytest, release-paths and both benchmark-clients); host-nightly-linux and host-nightly-macos were skipped. Its pytest job reads 522 passed and 84 skipped with 616 subtests, main's numbers. On e5ead44be9 the same jobs passed again, with the same two skipped and the same pytest counts.
  • Not run, and why: Metal and HIP, which this does not reach. TP=3 or wider serving was not run for this.

Receipt

  • Main against branch: the table above.
  • Boxes it reaches: GLM-5.3-Flash on CUDA. Ran on GB10 (sm_121) at TP=2.
  • New switch? None; the checkpoint's stored dtype chooses.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: main 077998f7d9 and this branch's 2e86ad0764 on it, each built from an empty Zig global cache. Zig 0.17.0, nvcc 13.3 for sm_121. Driver 580.178.04. Two GB10s at TP=2 over a direct link. The MXFP8 checkpoint is Bizuayeu/GLM-5.3-Flash-Jammed-XSFP4-NZ5@451ca955, whose dense MLPs are MXFP8, read from a local copy: its 132 .safetensors files, tokenizer and config files have that revision's hashes. The bf16 checkpoint is the same files with the nine dense matrices of layers 0 to 2 replaced by zai-org/GLM-5.3-Flash-BF16@a5b45eb4's bf16 tensors and their quantized_layers entries removed (18 tensors dropped, 9 added, 2 shards rewritten); it is a receipt's checkpoint and is not published.
  • Paths and platforms the change reaches, which I ran and which I could not: GLM's CUDA load (Loader.dense, b16Shapes) and, for a bf16 dense layer, cuda_mlp.zig's bf16 branch. Ran on GB10 (sm_121). Could not run any other CUDA chip.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: on each checkpoint, the three decode-check prompts, 512 tokens each and greedy, give the same token_sha256 drafted and with "draft": false; on the MXFP8 checkpoint this branch gives main's on all three launches. The bf16 checkpoint's three hashes differ from the MXFP8 checkpoint's, as its dense weights do. glm-lanes-cover 46, glm-lanes-concurrent 38 and glm-shared-check 1 pass on rank 0 on the bf16 checkpoint at TP=2, with no failures on either rank.
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): the table above.
  • Decode speed before and after, from tools/bench_openai.py: its two prompts with "draft": false in each request, 256 tokens five times each, one stream at a 40,960-token window, the median of three launches: the table. On the MXFP8 checkpoint this branch is within 0.04% of main.
  • Prompt speed before and after: the cold first request's ttft_s from tools/bench_cache.py --require-cold, on the decode-check prompts' tokens repeated to 9,600 and 38,400, the median of three launches: the table. On the MXFP8 checkpoint this branch takes 0.15% and 0.19% less than main, from pairs that put it 0.03% and 0.1% shorter, 1.9% and 2.4% shorter, and 0.1% shorter and 0.01% longer.
  • Licence of any new weights or drafter, or "n/a": n/a, no weights in this change.

Checklist

  • The title and description match the head commit, including the receipt and the stack. (e5ead44be9, two commits on main at 077998f7d9; every receipt is from 2e86ad0764's binary, and the commit after it changes the CHANGELOG and the recipe alone.)
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (Each of the two new host tests fails on its own mutant and nothing else does, under Checks; before this branch main refuses a bf16 dense layer by name, as the receipt's launch shows. The tests need only std.)
  • Comments and docstrings are one line. No measurements or history in the source. (lean: 0 new problems.)
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines. (The diff, the commit's message and this description, searched; none.)
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (A bf16 dense layer runs under the same rounds: glm-lanes-cover, concurrent and shared pass on the bf16 checkpoint at TP=2.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Drafted equals plain on both checkpoints; resumed and concurrent by the lanes tests on the bf16 checkpoint.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (No sum changes on a checkpoint that loads today: the MXFP8 checkpoint returns main's tokens. A bf16 dense layer runs the branch EXL3 checkpoints already run, on the stored bf16 values.)
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. (One stream, greedy, MTP drafts off, on the MXFP8 checkpoint: decode within 0.04% and prompts 0.15% and 0.19% shorter than main, medians of three launches run in turn with main's, under Receipt. The widest admitted, sampled and --drafter were not measured: for a checkpoint that loads today this changes no lane, launch or kernel.)

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu. LAND with routine changelog integration. The stored dtype now selects the existing BF16 branch, and the scratch plan follows the loaded dense layers. The two regressions cover format selection and the wider-dense allocation case. Existing quantized checkpoints retain their path; the BF16 variant is correctly compared against its own replies.

  • Synthena

@Bizuayeu

Copy link
Copy Markdown
Contributor Author

LAND with routine changelog integration.

(#3680 (comment))

Since that verdict main (6db2561b18) has moved under this branch in one more place than the changelog. #3869 (fb069a3856) rewrote the Jammed XSFP4 NZ5 sentence of docs/recipes/glm-5.3-flash-cuda.md ("on main after 1.2.7" became "in 1.2.10"), and that is the line directly above the sentence this PR adds, so GitHub now reports the PR as conflicting. git merge-tree against 6db2561b18 names that file as the only conflict; CHANGELOG.md merges by itself.

The resolution is to keep both lines: main's NZ5 sentence as it stands, then this PR's sentence ("A ModelOpt checkpoint may also leave the dense MLPs of layers 0 to 2 as bf16 ..."). No code is involved.

I have left the branch at e5ead44be9, as you asked on #3807 for the changelog line. If you would rather have the branch carry the resolution, I can merge main into it as one docs-only commit on top of the receipted head.

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @Bizuayeu. The change is ready to land and the earlier LAND verdict stands; nothing is needed from you. The only new item is a docs-only conflict from main's recipe sentence changing from "on main after 1.2.7" to "in 1.2.10". We will resolve that when we land it by keeping main's sentence and your "A ModelOpt checkpoint may also leave the dense MLPs of layers 0 to 2 as bf16" line together. The CHANGELOG entry applies by its context and the three Zig files apply cleanly. Please leave the branch as it is.

  • Synthena

ashhart pushed a commit to Bizuayeu/TensorFold that referenced this pull request Nov 19, 2026
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu. As promised, we rebased this onto current main ourselves, keeping your commits as they were; nothing else changed. It is in the landing queue now, and nothing is needed from you.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I checked the queued 28c8553c head against 124052c97. It trial-merges cleanly, including the updated recipe. On M5 Max with Zig 0.17.0, zig build test-glm-thin-weights-host test-gradient-serving compile-glm-native-open -Dcpu=apple_m1 plus a local filter for the two new dense-BF16 cases passed 16 tests on the head and 18 on the trial merge. The two cases cover the storage tag and the [gate | up] scratch plan for a checkpoint outside EXL3. The Linux GLM open path also compiled. This is the host and build receipt, with the earlier GB10 run covering the checkpoint.

Igor Lessio - AIFLOW LABS

Bizuayeu and others added 3 commits November 22, 2026 00:13
…not only an EXL3 one

The loader picks a dense layer's form from its stored dtype (mlp.held), and the B16 scratch plan counts the dense shapes whenever a dense layer is held bf16.
@AIFlowML

Copy link
Copy Markdown
Contributor

The queued 45224c2d head trial-merges cleanly into d21617008. On M5 Max with Zig 0.17.0, the thin-weight and serving-pin checks, the two dense-BF16 checks, and the native GLM open compile passed. The full run reported 20/20 tests and 16/16 steps.

zig build test-glm-thin-weights-host test-gradient-serving compile-glm-native-open \
  -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j2 --summary all

For the two feature-specific fixtures I also registered a scratch target on the existing GLM test root filtered for a dense layer stored bf16 and a dense layer held bf16. They check the storage classification and the gate/up scratch plan on a non-EXL3 checkpoint fixture. The published implementation was unchanged. Real checkpoint behavior remains in the GB10 receipt.

Igor Lessio - AIFLOW LABS

This branch has not been deployed

No deployments
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.

3 participants