Skip to content

glm cuda: prompt rows' MLA absorb and expand sum without lane trees, same bits - #3579

Closed
laudney wants to merge 4 commits into
ashhart:mainfrom
laudney:pr-glm-absorb-lanes
Closed

laudney wants to merge 4 commits into
ashhart:mainfrom
laudney:pr-glm-absorb-lanes

Conversation

@laudney

@laudney laudney commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor
FP4-Local, TP=2 on two GB10, base e86a0bed1d against this, alternated base, head, head, base main this
Cold prompt of 8,192 / 32,768 tokens (s) 5.659 / 22.242 5.510 / 21.798 (−2.65 / −2.0%)
absorb_q + expand_v of one 2,048-row prompt block, isolated (ms) 9.97 5.72 (1.74×)
Decode-window blocks (1 to 32 rows), L2 flushed first main's loops main's loops, same time
Kernel outputs, 78 row counts from 1 to 4,096 — byte-identical to main
Replies after each cold prompt; golden drafted = plain; concurrent = alone; resumed = cold — one sha256 a size across all launches; PASS, golden ids ba28cfb7, dae7e2a5, db45a54e on both

Every head launch beat every base launch in every row of the speed table. Plain decode also measured +2.7% (24.53 against 23.88 tok/s), but decode windows run main's loops on both sides, so that gain is not claimed.

What this changes

GLM's MLA tf_glm_absorb_q (q · wk into the 512-wide latent) and tf_glm_expand_v (latent · wv into the 256-wide v heads) sum each output as 8-fma chains spread over lanes, then reduce them through shuffle trees. In a prompt chunk that kept the LSU pipe at 83% while the FMA pipe sat at 21% (Nsight Compute, one GB10). For prompt blocks (64 rows a block, cuda_latent.zig's prompt_rb) one thread now forms the partials main spreads over lanes, each the same fma chain in the same order, adds them in main's tree shape (((0+4)+(2+6))+((1+5)+(3+7)), so every add keeps its pair; IEEE addition is commutative), then takes main's last shuffles; the q and o rows come through shared memory four rows a pass with 16-byte loads. Decode windows (blocks under 64 rows) run main's loops unchanged, as their cold kv_b read wants main's 16-byte weight loads. Nothing else changes: not the launcher, the decode path's arithmetic, or any other kernel.

Both kernels had no contract entry; this registers them (zig/tests/cuda/contract_glm_latent.zig, joined to the mla group because contract_tests.zig is at its 600-line limit), with nvcc 13.0 and 13.3 records for the five served SMs.

Checks on this head

  • Head commit: 9c35ffc2f9.
  • Lean checker, via tools/pr_check.py --base upstream/main: 221 on the base and 221 on this head, 0 new. Its advisory warnings: the documentation address 192.0.2.1 in the receipt's tools/env.sh, and the CHANGELOG line.
  • Tests run: zig build test-kernel-contract exit 0; git diff --check upstream/main clean; sha256sum -c SHA256SUMS passes 73 of 73 on a fresh git archive of the pushed branch.
  • CI: pending on this head. The previous head failed test-gradient-serving (the header's pin) and test-mla-twins-host (the twin check); both pass locally now.
  • Not run, and why: other GPUs than GB10 (the kernels' records are measured for all five served SMs; see the contract section).

Receipt

docs/receipts/glm-absorb-lanes-e86a0bed/ has every table, the raw results, both ranks' logs, the bit tests and the tools.

  • Main against branch: the table above; one binary a tree, the same file on both ranks; launches alternated base, head, head, base (tools/ab_compare.py prints the table from the committed results).
  • Boxes it reaches: GLM-5.3-Flash on CUDA, every prompt chunk's MLA layers (the 11 DSA layers), any checkpoint and rank count.
  • New switch? No.
  • Environment: base e86a0bed1d, head that plus the kernel commit; Zig 0.17.0, nvcc 13.5, NCCL 2.30.7, driver 580.178.04; two GB10 (128 GB) at TP=2 over a direct RoCE link; nvidia/GLM-5.3-Flash-FP4-Local at 76348ddb2be2e35e39ecfc00e75dc07703f4f3d5.
  • Paths and platforms: prompt blocks (64 rows) on the new sums, decode windows on main's loops; both tested bit for bit in isolation at 78 row counts and served.
  • Exactness: kernels byte-identical to main at 1 to 70, 100, 127 to 129, 1,000, 2,047, 2,048 and 4,096 rows (bits/latent_eq.out); one reply sha256 a prompt size across all four speed launches; tools/suite-ex.sh on both trees: golden drafted = plain (ba28cfb7, dae7e2a5, db45a54e on both), bench_concurrent.py --levels 1,2,4 --temperatures 0,1 --reps 3 --alone --serial 0 unequal, resume four ways equal to cold.
  • Decode speed: openai_aligned.py nodraft ("draft": false, 128 tokens, 3 reps): +2.65 / +2.72%, not claimed (main's loops on both sides).
  • Prompt speed: bench_cache.py --require-cold --tokens 16, the median of the three cold requests of each launch: −2.65% at 8k, −2.0% at 32k. An earlier pair of runs of the first form of this change measured −3.9% and −5.9%; run-to-run spread on one tree is about 2%.
  • Licence of any new weights or drafter: n/a.
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: glm_glue tf_glm_absorb_q and tf_glm_expand_v, changed in place (no new symbol); gates 1 to 4 against float64 at decode and prompt shapes (rows 1, 8, 32, 64, 70, 200; edges 63, 65), depth 13 and 14 (8-fma chains, then the trees).
  • A planted control for each kernel: each head launched with the next head's weights; gate 3 reports both red (311× and 710× their bounds).
  • Each backend's SUMMARY line and exit status: CUDA on GB10 with the runner built by nvcc 13.3: (filtered) SUMMARY 2 kernels: 2 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed; 0 limit problems, exit 0. Records: 2,560 and 4,224 static shared bytes, bound 128; expand_v 96 registers on all five SMs, absorb_q 111, 113, 113, 96 and 96 on sm_80/86/89/120/121 (nvcc 13.0 and 13.3, measured with cuobjdump --dump-resource-usage after the CI fix; before it, 96 on all five and kernel-contract-limits over nvcc 13.0's five-SM fatbins marked both current). Rerun on GB10 after the fix with a 13.3-built runner: the same SUMMARY line, live limits current.
  • Chips I could not run: sm_80, sm_86, sm_89 and sm_120 on a GPU (their limits are checked from the fatbins).

Checklist

  • The title and description match the head commit, including the receipt and the stack.

  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (The contract's planted controls go red; the gates pass.)

  • Comments and docstrings are one line. No measurements or history in the source.

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

  • 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.

  • No precision traded for speed. If the bits change, the description says which sums change and why. (The bits do not change.)

  • 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

GLM's MLA absorb and expand spent prompt chunks shuffling partials
through warp trees (the LSU pipe at 83%), so prompt blocks now form
the partials main spread over lanes inside one thread, each the same
FMA chain, and add them in main's tree shape before main's last
shuffles; decode windows keep main's loops, whose weight loads stay
16 bytes wide. Every output keeps its bits; prompt blocks run 1.75x
faster and cold prompts take 4 to 6% less time on two GB10.
GLM's tf_glm_absorb_q and tf_glm_expand_v changed without a contract
entry, so a rig after the mla image's checks both against float64 at
decode and prompt shapes with next-head controls that go red, and
both get nvcc 13.0 and 13.3 records for the five served SMs; the rig
joins the mla group, as contract_tests.zig is at its line limit.
The kernel change keeps every output's bits, so the receipt shows it
three ways on two GB10: the kernels against main's at 78 row counts,
four alternated served launches whose replies match and whose cold
prompts are 2 to 3% faster, and the exactness suites on both trees;
it also keeps the contract run and the tools that made each part.
@laudney

laudney commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart Opened at head f3637a500f (kernels b225c0f108, contract registration and 13.0/13.3 records 5fdd05f27a, receipt f3637a500f). Same bits at 78 row counts and served; cold prompts −2 to −3% on two GB10 (TP=2); contract SUMMARY clean with a 13.3-built runner. No new conflicts. CI pending.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney, the arithmetic is the part we checked first and it holds: each output keeps main's fma chain in the same order, the partials meet in main's tree shape, and your receipt shows the same bytes at 78 row counts and one reply hash a size across every launch. The isolated 1.74x and the 2 to 2.7 percent off cold prompts are worth having.

The CI failure is in the registration, not the kernels: the two records point at the glm_glue image, but the branch ships no rebuilt image carrying the new symbols, so the jobs that compile the contract tests cannot resolve them. Either rebuild and pin the image with the two symbols, or gate the records behind the image's presence as other pending entries do; if you would rather not rebuild the image, say so and we will do it on our side. We will rerun the contract entry on a GB10 either way. Once CI is green with that one change, this is a same bits speed change we are glad to take to the device check.

  • Synthena

CI failed two host checks: glm_glue_latent.cuh is a pinned serving
source, and mla_twins compares tf_mla's absorb_q and expand_v with
GLM's code token for token. The decode loops (absorb_main,
expand_main) are now main's kernel bodies exactly and the twins
point at them, the header is re-pinned, and absorb_q's records take
the registers sm_80/86/89 now use (111, 113, 113 under nvcc 13.0 and
13.3; sm_120/121 stay 96). Main's and these kernels stay
byte-identical at 78 row counts; the GB10 contract run is clean.
@laudney

laudney commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart thank you. The CI logs showed two other causes; the glm_glue image needs no rebuild, because both symbols already exist in it (the kernels changed in place):

Failing job Cause Fix in 9c35ffc2f9
zig (test-gradient-serving) glm_glue_latent.cuh is a pinned serving source; I did not re-pin it Re-pinned in gradient-serving.tsv
zig-b, zig-windows (test-mla-twins-host) mla_twins.zig compares tf_mla's absorb_q / expand_v with GLM's code token for token, and the kernel bodies changed The decode loops (absorb_main, expand_main) are now main's kernel bodies token for token, and the twins point at them

That change moved absorb_q's registers on sm_80/86/89 only (96 to 111, 113, 113 with nvcc 13.0 and 13.3; sm_120/121 stay 96), so both record tables carry the new values. On GB10 after the fix: main's kernels against these are byte-identical at 78 row counts (bits/latent_eq_main_loops.out in the receipt), and the filtered contract with a 13.3-built runner gives the same SUMMARY (2 pass gates 1-4, 2 controls red, 0 limit problems). Both failing steps pass locally. Head 9c35ffc2f9; no force-push, one commit on top.

@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney. You are right about the CI causes: the serving pin and twin check needed updates, rather than a new symbol. The pin now matches and the decode helpers retain main’s arithmetic. We will finish current-head CI, the GB10 checks and the changelog. The other SM register counts are build evidence; their runtime speed remains unchecked.

  • Synthena

@laudney

laudney commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing: this GLM-5.3-Flash performance work will not continue in TensorFold.

@laudney laudney closed this Nov 17, 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