Skip to content

glm cuda: decode kernels as dependent launches, +6.8% decode at TP=2, same tokens - #3673

Closed
laudney wants to merge 17 commits into
ashhart:mainfrom
laudney:glm-decode-pdl
Closed

laudney wants to merge 17 commits into
ashhart:mainfrom
laudney:glm-decode-pdl

Conversation

@laudney

@laudney laudney commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor
TP=2 on 2 × GB10, same checkpoint and expert form main this branch change
Plain decode, one stream (tok/s, two serves each, alternated) 24.60, 24.38 26.11, 26.20 +6.8%
Drafted decode, one stream (tok/s) 43.45, 42.70 45.17, 44.45 +4.0%
Four streams, summed (tok/s) 98.55, 99.85 103.40, 104.05 +4.6%
Cold 8k / 32k prompt, first token (s) 5.66 / 22.82 5.61 / 22.66 −0.9% / −0.7%
Tokens equal in every serve

What this changes

GLM's CUDA kernels and qmmf's decode linears launch as programmatic dependent launches: the next kernel launches while the current one ends and waits (griddepcontrol.wait) before it reads anything, so each of the ~1,300 kernels a decode token loses most of its 2–3 µs launch gap. Every GLM kernel opens with glm_pdl::enter() (let the next grid in, then wait) and so reads and writes exactly as a plain launch; the kernels that write weights at load wait without letting a dependent in. qmmf's decode tile loads its weights and scales before the wait and its input rows after it. TF_GLM_PDL=0 launches them all plain (registered in platform/environment.zig, docs/environment.md). Experts, the router plan and the RoCE exchange stay plain launches.

Inputs a predecessor writes are never const __restrict__: nvcc gives those non-coherent loads, and ptxas places them above the wait (a first version did so in 12 kernels, and replies after a long prompt varied). Three guards: test-glm-pdl-scan (every GLM kernel opens with the wait; glm_mm's and qmmf's weight-first prologues load weights before it and inputs after, and their weight loads name no input row), tf-cuda-test glm-pdl-order on GB10 (a dependent launch after a slow writer reads finished bytes, GLM's kernels and qmmf's BF16, FP4 and MXFP8 decode rows, with a planted early read as the control), and zig build check-pdl-loads -Dnvcc=… (in the SASS of the GLM images and qmmf: no global read above the wait, no predicated wait and no branch past it).

Checks on this head

  • Head commit: 7017c23879 on main 3f1290ffe7; it merges without conflict into main f3307fb29a.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 221 on main 3f1290ffe7 and 221 on this head, 0 new findings.
  • Tests run, with the command and pass, fail and skip counts: zig build test-cuda-host test-glm-pdl-scan test-gradient-serving: 6,649/6,680 passed, 29 skipped, 2 failed on the first run (cuda_disk_test "kept states … restart", lane_host_rows_test "spill-only host", plus rows_async_test "spill I/O" in the summary: timing tests under load); both reruns of test-cuda-host pass with no failure. After the qmmf cluster tile record commit, test-cuda-host fails only test-server-deepseek-chat-host's three namespace pins, which fail the same way on main 3f1290ffe7 on this host. python3 tools/test_pdl_early_loads.py: 17 OK (CI's no-GPU job now runs it; check-pdl-loads itself needs nvcc, which CI lacks). tools/zig/cuda_common_check.py: 0 violations; the GLM images keep identical SASS with the shared wait and trigger helpers. zig build -Dfixed-cpu test-host-b test-glm-index-emulate test-glm-logprobs-host pass; in test-host-a only timing tests under this host's load (cuda_disk_test, lane_host_rows_test, rows_async_test, slide_metrics_off_test; each passes on rerun) and the DeepSeek pins (which fail on main 3f1290ffe7 here too) fail. zig fmt --check build.zig zig and git diff --check pass. On GB10: tf-cuda-test glm-pdl-order 17 PASS and its planted early read fails as planted; zig build check-pdl-loads: 0 problems in 402 functions of 9 images (sm_80, sm_120, sm_121; the first version had 12 early reads)
  • CI: all checks pass on 7017c23879 (fmt, pytest, zig, zig-b, zig-windows, zig-macos-dev-tools, release paths, benchmark clients; nightly jobs skipped).
  • Not run, and why: zig build test in full on x86 (the CUDA host suite, the scan and the pins are the parts this touches); hardware other than GB10 (below).

Receipt

Full receipt: docs/receipts/glm-decode-pdl-60e67379/README.md (raw JSON for every serve, tools, prompts).

  • Main against branch: cells and numbers, or why they can't be run: the table above; serves alternated main, head, head, main, then the head with TF_GLM_PDL=0 (24.21 tok/s, main's tokens).
  • Boxes it reaches: GLM on CUDA, sm_90 and newer (below sm_90 the waits compile to nothing and the driver keeps plain stream order for the dependent attribute).
  • New switch? Default, accepted values, profile row: TF_GLM_PDL, default 1 (on), accepted 0 or 1, a glm row in the switch table.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: main 077998f7d9, head 60e673799f (this branch before its rebase onto 3f1290ffe7; the rebase changed no line of the branch, and the commits it crossed touch no GLM or qmmf source); Zig 0.17.0, nvcc 13.5 (V13.5.37), driver 580.178.04, Ubuntu 24.04; 2 × GB10 (sm_121) at TP=2 over a direct RoCE link, NCCL 2.30; nvidia/GLM-5.3-Flash-FP4-Local at 76348ddb2be2e35e39ecfc00e75dc07703f4f3d5.
  • Paths and platforms the change reaches, which I ran and which I could not: GLM decode, MTP verify, DFlash2 (df_attn), prompt chunks, vision and the KV host tier launch GLM kernels; qmmf's dependent decode tile is reached only through GLM's lane. Ran: TP=2 on GB10, plain, drafted, four streams, cold 8k and 32k prompts. Not run on hardware: sm_90, sm_100, sm_120, TP=3, one GPU.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: on each binary, 1, 2 and 4 streams, greedy and sampled: 84/84 equal their alone runs and 30/30 their serial runs; drafted = plain on the 3 golden prompts, the same token sha256s on head and main; resumed = cold. 16-token replies after a cold 8k prompt, drafts off: head 60/60 one reply, main 30/30 the same reply; the first version, with const __restrict__ inputs, 24/30 that reply and 3 others.
  • 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: drafted 43.45, 42.70 → 45.17, 44.45 tok/s (+4.0%); plain (openai_aligned.py, drafts off) 24.60, 24.38 → 26.11, 26.20 (+6.8%).
  • Prompt speed before and after: cold first token, bench_cache.py --require-cold: 8k 5.666, 5.659 → 5.609, 5.610 s; 32k 22.83, 22.80 → 22.58, 22.73 s.
  • Licence of any new weights or drafter, or "n/a": n/a, no new weights.

The GLM load times its two expert forms once a binary and keeps the faster; this head's binary kept classic and main's factored, which alone moves plain decode by about 3%. The A/B above runs both on factored (the head's kept flag set to main's) so only this change differs; the receipt keeps the first, mixed A/B (+3.5%) and the per-kernel profiles that found it.

Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: no new served kernel; every GLM kernel gains its entry wait, the 12 kernels whose inputs dropped __restrict__ keep their arithmetic, and their records are re-measured where registers moved (nvcc 13.0 records, and the nvcc 13.3 set). qmmf's four 16-row cluster tiles move under 13.0 only; nvcc 13.3 compiles them as on main, so GLM's 13.2 set keeps main's records for them (nvcc 13.2 was not available to measure). The test kernels tf_probe_pdl_slow_copy, tf_probe_pdl_early_read and tf_probe_pdl_enter_read live in probe.cu for glm-pdl-order.
  • A planted control for each new kernel, and each one fails as planted: tf_probe_pdl_early_read reads before its wait and glm-pdl-order sees the stale bytes; a check-pdl-loads fixture with a load above the wait fails.
  • Each backend's SUMMARY line and exit status: tf-cuda-test kernel-contract (nvcc 13.3, sm_121): SUMMARY 661 kernels: 661 pass gates 1-4, 0 fail, 8 known findings; 422 controls: 422 red as planted, 0 missed; 387 limit problems, exit 1 from the limit problems alone. They are stale nvcc 13.3 records: kernel-contract-limits on the five-SM fatbins finds 834 on main 3f1290ffe7 and 832 on this branch, every branch one also stale on main, and no launch past a limit (5,330 PASS, 0 FAIL). The 8 known findings are the registered ones.
  • 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.
  • 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.
  • 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

A GLM-5.3-Flash decode step spends 2-3 us idle between each of its
~1,320 kernels. Every GLM kernel now opens with glm_pdl::enter()
(launch_dependents, then griddepcontrol.wait; weight writers wait
without the early trigger, since glm_mm reads weights first), so
each GLM launch may be a dependent one: cuda_pdl.launch makes it so
under TF_GLM_PDL, which already governed glm_mm, and the shared KDA
launcher takes an opt-in flag. test-glm-pdl-scan, now in the no-GPU
workflow, fails any GLM kernel body that does not open with the
wait; fake test drivers forward cuLaunchKernelEx. Same arithmetic,
so every output keeps its bits.
GLM's decode spends a launch gap before each of its ~192 qmmf linears
a token, and the PoC measured 1.3% more decode speed from making them
dependent. qmmf_kernel now triggers its dependents at entry and,
under TF_QMMF_WFIRST, loads its prologue stages' weights before
griddepcontrol.wait and the input rows after it; reduce_kernel waits
first. Lane.pdl (false by default, set only by GLM from TF_GLM_PDL)
makes the decode entries and the reduce dependent; prompt entries
stay plain. Same arithmetic and bits; the register records the
prologue moved are re-measured for nvcc 13.0 and 13.3.
With every GLM kernel opening on glm_pdl::enter(), nvcc 13.3 gives
tf_glm_chunks_16 and tf_glm_chunks_32 other registers on sm_120 and
sm_121, and df_sumn 40 on both (main's 13.3 build was already off
its record there). The 13.3 set records the five-SM measurement of
each, so the 13.3 limits audit has no new stale GLM entry; nvcc
13.0's records, which CI checks, did not move.
tf-cuda-test glm-pdl-order runs each kernel behind a slow writer that
lets it in at once: one kernel from every GLM image, glm_mm's reduce
and qmmf's decode row with K slices, a cluster and one K group,
through the production launchers. Each must give the bytes of a
plain launch and, with main's fatbins from the same nvcc, main's
bytes; a planted early reader must see the poison and go wrong, and
chains through another stream's events and host copies must hold.
On GB10 every case passes and the control goes red as planted.
The lean checker reads a C block comment's opening and closing marks
even inside Zig strings, and cuda_vision.zig crossed 600 lines with
the lanes' new pdl field. The scan test spells those marks from two
parts, and the vision tests build their lanes as struct literals so
the field defaults apply, which also drops the explicit pdl lines.
With GLM's kernels launched dependent, greedy replies after a cold
8k prompt varied (8 distinct 16-token replies in 30). ptxas placed
the non-coherent loads that nvcc emits for const __restrict__
inputs above griddepcontrol.wait in 12 kernels (the DSA selectors,
dsa_tokens, the KV-host kernels, df_attn), so a selector could read
a position or a score before the kernel writing it finished. Those
inputs drop __restrict__, which makes their loads coherent and keeps
them after the wait; 60 of 60 replies now match. Records of the
kernels whose registers moved are re-measured.
The source scan cannot see what ptxas schedules. check-pdl-loads,
with -Dnvcc, disassembles the GLM images and qmmf and fails any
sm_90 or later function that reads global memory before its
griddepcontrol.wait, or never waits unless it is a plain-only entry;
only the weight-first bodies may start async weight copies first.
The scan test now also checks that glm_mm's and qmmf's prologues
load weights before the wait and their inputs only after it.
GLM now launches its CUDA kernels as dependent launches, so the
ledger gains a row for the technique: GLM's cell points at the
issue, the other families stay unknown, the impact table names the
decode gain, and the entry records the rule that inputs a
predecessor writes must not be const __restrict__ and the SASS
check that enforces it.
The qmmf commit re-measured four 16-row cluster tiles under nvcc 13.0
(50 and 58 registers on sm_120 and sm_121), but nvcc 13.3 still
compiles them at 48 and 56, as on main, and with no later entry they
showed as stale records. GLM's 13.2 set now holds them at main's
values, so 13.2 and later releases check them as main does; with it
the branch's 13.3 limits flag no record main does not already flag.
The receipt for GLM's kernels and qmmf's decode linears as dependent
launches at TP=2 on two GB10s: main against this branch on the same
expert form (plain decode +6.8%, drafted +4.0%, four streams +4.6%,
cold prompts no slower), equal tokens in every serve, the exactness
suites, the determinism runs that found the early-load race, the
kernel contract and limits against main's, the order test and the
SASS check, with raw results, prompts, tools and their checksums.
check-pdl-loads took the first ACQBULK in a function's listing as its
wait, so a predicated wait, or a branch from before the wait to code
past it, let a read run before the predecessor ended and still pass.
The checker now fails a predicated wait, an indirect branch before
the wait and any branch before it to a target past it other than an
EXIT, with fixtures for each; the GLM images and qmmf stay clean.
The SASS check lets weight-first bodies start async copies before the
wait without telling weights from inputs, and glm-pdl-order ran only
qmmf's BF16 decode rows, while GLM serves FP4 and MXFP8 ones. The
source scan now fails a weight load in qmmf or glm_mm that names the
input rows, and glm-pdl-order adds FP4 and MXFP8 decode rows, K
slices and clusters, from random finite codes and scales near one.
The guards grew after the receipt was written: glm-pdl-order now runs
qmmf's FP4 and MXFP8 decode rows too, and check-pdl-loads also fails
a predicated wait or a branch past it. The receipt carries their
reruns on GB10, 17 of 17 order cases passing and no problem in 402
functions, with its checksums refreshed.
The receipt named the qmmf cluster tile record commit by a hash that
the published branch does not carry, since that branch is a copy
without the local plans. It now names the commit by its subject,
which both branches share, and its checksums are refreshed.
@laudney

laudney commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart this is ready for review at ef3f6a8ee5 on main 3f1290ffe7 (it merges without conflict into f3307fb29a). GLM's CUDA kernels and qmmf's decode linears launch as dependent launches: +6.8% plain decode and +4.0% drafted at TP=2 on 2 × GB10, tokens equal in every serve. Inputs that a predecessor writes are no longer const __restrict__, because ptxas hoisted their loads above the wait. Three guards keep it so: a source scan, glm-pdl-order on GB10, and check-pdl-loads on the SASS. The receipt is under docs/receipts/glm-decode-pdl-60e67379/. Fixes #3652.

CI's shared-primitive check rejects griddepcontrol instructions
written outside the common headers, and glm_pdl.cuh carried its own
copies of the wait and the trigger. It now calls qmm_frag's
grid_wait and grid_launch, which emit the same instructions under
the same sm_90 guard; the eight GLM images rebuilt with it keep
identical SASS on sm_80, sm_120 and sm_121.
@laudney

laudney commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart pushed c870acd2de: glm_pdl.cuh now calls qmm_frag::grid_launch/grid_wait from common/qmm_frag.cuh instead of its own griddepcontrol asm, which fixes the "Shared CUDA primitive copies" CI step. The 8 GLM images rebuilt with it have identical SASS on sm_80, sm_120 and sm_121. The description is updated.

check-pdl-loads needs nvcc, which no CI job has, so its rules ran
only on machines with a CUDA toolkit. Its fixtures need neither: the
no-GPU job now runs them beside the shared CUDA primitive checks, so
CI fails when the checker stops failing an early read, a predicated
wait or a branch past the wait.
@laudney

laudney commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart pushed bb9de58e67: CI's no-GPU job now runs the SASS checker's fixtures (python3 tools/test_pdl_early_loads.py), because check-pdl-loads needs nvcc. The description is updated.

CI's host jobs failed two ways. The index emulator compiles GLM's
kernels as host C++ without CUDA headers, so glm_pdl.cuh now includes
qmm_frag and calls its wait and trigger only under __CUDACC__. The
safe-build name check in cuda_pdl.launch read cuFuncGetName through
test drivers that leave it unset; it is removed, the source scan
already proving each GLM kernel opens with its wait, and the
prompt-logprobs host test routes dependent launches to its recorder.
@laudney

laudney commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart pushed 7017c23879, which fixes the two host CI failures:

  • test-glm-index-emulate compiles GLM kernels as host C++. glm_pdl.cuh now includes common/qmm_frag.cuh and calls its wait and trigger only under __CUDACC__, so nvcc output is unchanged.
  • glm_prompt_logprobs_host aborted in the safe-build name check, because cuFuncGetName is unset in its fake driver. I removed that check; the source scan already proves every GLM kernel opens with its wait. The test now routes dependent launches to its recorder, as the other GLM host tests do.

@ultradaoto

Copy link
Copy Markdown
Contributor

A TP=3 receipt for this head, since the description lists TP=3 as not run.

Three GB10s on a switchless triangle (NCCL carries every gather), GLM-5.3-Flash EXL3, --parallel 4 --kv-cache fp8 --decode-share 0.5, --drafter incoai/GLM-5.3-Flash-DFlash2 at 6cc6c481, TF_GLM_DENSE_BITS=8 TF_GLM_HEAD_BITS=8 TF_GLM_KDA_PAD=1 TF_ROCE=1, greedy. Main 3f1290f and this head ef3f6a8 built on these boxes the same way (Zig 0.17.0, nvcc 13.0 V13.0.88, driver 580.159.03). Five starts in one session, in this order: main, head, head with TF_GLM_PDL=0, head, main. One number per start:

main 3f1290f this head this head, TF_GLM_PDL=0
16 varied greedy requests one at a time, aggregate tok/s 58.45 / 58.39 61.09 / 60.81 (+4.3%) 57.46
tokens a round over those requests 3.058 / 3.058 3.058 / 3.058 3.058
tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0, code, median tok/s 62.00 / 61.67 65.34 / 64.91 (+5.3%) 61.55
the same, chat with thinking off 49.47 / 49.31 52.02 / 51.90 (+5.2%) 49.11
tools/bench_concurrent.py --tokens 256 --reps 3 --temperatures 0 --levels 1,4 --alone --serial, 4 streams, code, aggregate 122.1 / 127.2 134.4 / 133.9 126.0
the same, chat 106.9 / 108.0 113.7 / 114.8 107.2
four 512-token greedy decodes at once (four different prompts), aggregate tok/s 85.4 / 85.8 88.9 / 88.4 (+3.6%) 85.8

Tokens: 13 greedy replies (8 prompts alone, 4 at once, one prompt of about 8K tokens) hash the same in all five starts, and in the four profile starts below.

Where the time went: TF_GLM_PROF=1 with MTP drafts (--mtp-confidence 0.5), the 4-row verify calls, mean ms a call on rank 0, starts in the order main, head, head, main:

rank 0, ms a call main head head main
wall 47.98 45.96 45.88 47.64
kda 9.62 9.22 9.21 9.59
mla 4.40 4.01 4.02 4.37
shared 2.93 2.45 2.48 2.93
router 1.84 1.34 1.36 1.80
dense 0.81 0.77 0.76 0.81
head 1.01 1.02 1.02 1.02
routed 23.11 23.18 23.10 23.14
gathers (both) 4.15 3.89 3.87 3.91

Ranks 1 and 2 move the same way (wall 47.88 / 47.54 to 45.87 / 45.77 on rank 1). The routed experts are level, as the description says they stay plain launches (EXL3's grouped kernels here). They are half of rank 0's call at TP=3, so they are where a follow-up would pay most on this checkpoint.

The three guards with this toolchain, which is older than the receipt's nvcc 13.5:

  • zig build check-pdl-loads -Dnvcc=/usr/local/cuda-13.0/bin/nvcc: 0 early read(s) in 201 function(s) of 9 image(s).
  • zig build test-glm-pdl-scan: passes.
  • tf-cuda-test glm-pdl-order on one GB10: 17 PASS, 0 FAIL, and the control line reads a read before the wait saw the poison (try 2) and wrote the wrong value, as planted.

Not run here: prompts longer than 8K tokens, images, and a soak.

@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
@ultradaoto

Copy link
Copy Markdown
Contributor

@ashhart, a question now that this is closed: would you still want this change in TensorFold if someone else carried it?

At TP=3 on three GB10s it measured +4.3% decode with the same tokens (the receipt above), and its three guards pass here with nvcc 13.0, so it would be a pity to lose it. If you want it, and @laudney does not object, I can open a PR that carries this branch from 7017c23 onto main with their credit, rerun the TP=3 receipt and the guards on that head, and take the review from there.

If the answer is no, I will leave it. If you would rather have it in a smaller form, say which and I will look at that instead.

@laudney

laudney commented Nov 17, 2026 via email

Copy link
Copy Markdown
Contributor Author

@ultradaoto

Copy link
Copy Markdown
Contributor

Carried forward as #3776: these 17 commits on main af9777b, with the guards and a TP=3 receipt rerun on that head (+3.7% decode on three GB10s, same tokens; long cold prompts about 1% slower there, which I am looking into). Thank you, @laudney.

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.

GLM CUDA decode: its kernels as dependent launches, +6.8% decode at TP=2, same tokens

2 participants