Repository navigation
glm cuda: decode kernels as dependent launches (carries #3673), +3.7% decode at TP=3, same tokens - #3776
Conversation
|
The slower cold prompts are the dependent launches themselves. Three more cold-prompt starts of this branch, same settings, in the order
With the switch off the branch is at main's 17.61 to 17.69 s; with it on, all three starts so far are at 17.80 to 17.95 s. So at TP=3 the launches gain 3.7% in decode and cost about 1.2% on a long cold prompt. The 13 reply hashes are the same in these starts too. Next I will look at keeping the prompt passes' launches plain and measure that. |
|
The cold-prompt cost is KDA's three-kernel chain in prompt chunks, and one small commit removes it: How I found it. Lab builds of this branch (not pushed) that launch one group of kernels plain during prompt passes only, each with two requests at 28.8K new prompt tokens a start, first token in seconds. Main is 17.61 to 17.69 s and this branch as first posted 17.80 to 17.95 s.
A different cut, launching plain every grid of more than 256 or more than 1,024 blocks whatever the pass, did not help (17.83 to 17.96 s). So it is not the size of the grids; it is KDA in a prompt chunk. I did not establish why a dependent launch costs there. glm_mm's row says its dependent launches help prompts, as main has them. The fix. Measured, same three GB10s and settings as the description, starts in the order fix, branch before the fix, fix, branch before the fix:
The 13 reply hashes are the same in all four starts and equal main's. With the fix the long cold prompts are at main's time (17.61 to 17.69 s and 4.69 to 4.72 s in the description's starts) and decode keeps its gain. Checks on I have updated the description's head commit, its cold-prompt row and its checklist to match. |
f5baf0e to
4b0e298
Compare
|
Rebased onto main What the rebase touched
Over Checks on
Timing again, 3 x GB10 at TP=3, main Starts in the order main, PR, PR, main, with the settings of the first receipt (DFlash2 drafter, fp8 KV cache, 8-bit dense and head linears,
Not re-run on this head: the device |
|
Thank you @ultradaoto. The isolation of the cold-prompt cost to KDA's three-kernel chain in prompt chunks, and the small fix that launches that chain plain from 64 rows while keeping the decode gain and the same token hashes, reads clearly. We will run a device check on our side on the GB10 class with GLM-5.3-Flash, comparing token hashes to main and to TF_GLM_PDL=0 and checking the aggregate decode and 28.8K cold-prompt timings. One small thing from you: please trim the two trailing-whitespace lines in the captured receipt. We have started CI on this head.
|
4b0e298 to
7175e8d
Compare
|
Done: the two trailing-whitespace lines in Main had moved, so the branch is also rebased onto On this head so far: |
|
Thank you @ultradaoto. Thanks for trimming the two trailing-whitespace receipt lines, updating the checksum row and rebasing onto current main; that closes the one code point we raised. We will run our own GB10 check with GLM-5.3-Flash, comparing token hashes to main and to TF_GLM_PDL=0 and checking the aggregate decode and 28.8K cold-prompt timings. One thing to confirm from your side: please post the green CI result on the current head, since the earlier build and device checks ran on the previous head. Nothing else is needed from you.
|
7175e8d to
b7fee36
Compare
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.
Main's 450d5d8 added ledger rows 30-32 (Flash Next HIP fusion, stream-tile prefetch and the filled-item prompt grid), so the previous commit's "30. Dependent launches" rows and entry take the next free number, 33. Nothing else changes.
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.
b7fee36 to
0d674a7
Compare
|
Thank you @ultradaoto. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
… row 33 Main's dependent-launches row (ashhart#3776) took ledger row 33, so the previous commit's four below-target CUDA experiments take the next free numbers: FP8 KV prefill waits 34, Qwen normalization and head 35, text metadata uploads 36, greedy readback 37. Nothing else changes.
… (rebase-1120/)
…dependent launches) Main's 720f207 gave dependent launches (ashhart#3776) ledger row 33 while ashhart#3395 was in review, so its rows-together row and entry become 34 in every table and the entry list. Nothing else changes.
…dependent launches) Main's 720f207 gave dependent launches (ashhart#3776) ledger row 33 while ashhart#3395 was in review, so its rows-together row and entry become 34 in every table and the entry list. Nothing else changes.
…se-1120/tp4, tp2), and the cold prompts' token checks at TP=3
… row 33 Main's dependent-launches row (ashhart#3776) took ledger row 33, so the previous commit's four below-target CUDA experiments take the next free numbers: FP8 KV prefill waits 34, Qwen normalization and head 35, text metadata uploads 36, greedy readback 37. Nothing else changes.
… row 33 Main's dependent-launches row (ashhart#3776) took ledger row 33, so the previous commit's four below-target CUDA experiments take the next free numbers: FP8 KV prefill waits 34, Qwen normalization and head 35, text metadata uploads 36, greedy readback 37. Nothing else changes.
… row 33 Main's dependent-launches row (ashhart#3776) took ledger row 33, so the previous commit's four below-target CUDA experiments take the next free numbers: FP8 KV prefill waits 34, Qwen normalization and head 35, text metadata uploads 36, greedy readback 37. Nothing else changes.
Main's dependent-launches row (#3776) took ledger row 33, so the previous commit's four below-target CUDA experiments take the next free numbers: FP8 KV prefill waits 34, Qwen normalization and head 35, text metadata uploads 36, greedy readback 37. Nothing else changes.
This carries @laudney's #3673 onto current main, with their agreement (#3673 (comment) and the reply under it). The first 17 commits are theirs, unchanged in content and authorship; I only moved them from main
3f1290ffe7to mainaf9777b(no conflicts) and reran the guards and a TP=3 receipt on the new head. Two commits of mine follow: the CHANGELOG line, and a seven-line fix inkda.zigfor the prompt time. The design is theirs and #3673's description is the place to read it in full.af9777bTF_GLM_PDL=0tools/bench_openai.py, code, median tok/sAt TP=3 the 17 carried commits measured long cold prompts about 1% slower than main (#3673 measured them 0.7 to 0.9% faster at TP=2). The cause is KDA's three-kernel chain launched dependent in prompt chunks; the last commit here,
f5baf0e14, launches that chain plain from 64 rows and brings the prompts back to main's time with decode unchanged. The comments below have the isolation and the before and after.What this changes
As #3673: 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 a decode token's kernels lose most of their launch gaps. Every GLM kernel opens withglm_pdl::enter(); qmmf's decode tile loads its weights and scales before the wait and its input rows after it.TF_GLM_PDL=0launches them all plain. Experts, the router plan and the RoCE exchange stay plain launches. Three guards keep a read from moving above the wait:test-glm-pdl-scan,tf-cuda-test glm-pdl-orderandzig build check-pdl-loads -Dnvcc=….atc overlap --json: not run, I do not have the tool installed. glm cuda: decode kernels as dependent launches, +6.8% decode at TP=2, same tokens #3673's description lists the open pull requests it found in shared files.git merge-treeof this head into main8cbef9777bis clean.Checks on this head
f5baf0e14don mainaf9777b; it merges without conflict into main8cbef9777b. It isdf0a2a2614(the last of glm cuda: decode kernels as dependent launches, +6.8% decode at TP=2, same tokens #3673's commits, and the head every check and number in this description was taken on unless it names another), then the CHANGELOG commit, thenf5baf0e14(the KDA fix; its own checks and numbers are in my comment below).python3 tools/zig/lean_check.py, on the base and on this head: 221 and 221, 0 new findings.zig build test-cuda-host: 7,116 of 7,150 passed, 33 skipped, 1 failed (cli_config_test, "serve --config: expand reads the file …"). The same command on mainaf9777bon this box: 7,114 of 7,148 passed, 33 skipped, and the same 1 test failed, so it is not this change.zig build test-kernel-contract: exit 0.zig build -Dfixed-cpu test-gradient-serving test-glm-index-emulate test-glm-logprobs-host: exit 0.zig build test-glm-pdl-scan: passes.python3 tools/test_pdl_early_loads.py: 17 OK.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).tf-cuda-test glm-pdl-orderon one GB10: 17 PASS, 0 FAIL; the control readsa read before the wait saw the poison (try 2) and wrote the wrong value, as planted.zig fmt --check build.zig zig: clean.python3 tools/zig/cuda_common_check.py: 0 violations.python3 tools/pr_check.py --base origin/main --pr 3776ondd2a74bff5: 0 errors, 0 warnings.git diff --check: two lines with trailing whitespace indocs/receipts/glm-decode-pdl-60e67379/contract/sass-early-loads.txt, a captured tool output in glm cuda: decode kernels as dependent launches, +6.8% decode at TP=2, same tokens #3673's receipt. Left as it is; say if you want it trimmed.atc overlap(tool not installed); TP=1 and TP=2 on this head (the three boxes were used as one TP=3 set; glm cuda: decode kernels as dependent launches, +6.8% decode at TP=2, same tokens #3673's receipt is TP=2 on its own head); nvcc 13.2 to 13.5 (these boxes have 13.0 only, so I could not check the nvcc 13.3 records the branch carries); chips other than GB10; a soak on this head.Receipt
Main against branch: the table above. Three GB10s on a switchless triangle (NCCL carries every gather), main
af9777band headdf0a2a2614built on these boxes the same way. Starts in one session in this order: main, branch, branch withTF_GLM_PDL=0, branch, main; one number a start. Then four profile starts and four cold-prompt starts, each in the order main, branch, branch, main.Boxes it reaches: GLM-5.3-Flash on CUDA, every TP.
New switch? Default, accepted values, profile row: as glm cuda: decode kernels as dependent launches, +6.8% decode at TP=2, same tokens #3673,
TF_GLM_PDL, on by default,0launches plain; registered inplatform/environment.ziganddocs/environment.md.Environment: Zig 0.17.0, nvcc 13.0 (
cuda_13.0.r13.0/compiler.36424714_0), driver 580.159.03, Ubuntu 24.04.4, kernel 6.17.0-1018-nvidia, 3 × DGX Spark (GB10). GLM-5.3-Flash-Uncensored EXL3 at revision07135ec082f8,--parallel 4 --kv-cache fp8 --reasoning-effort high --decode-share 0.5,--drafterincoai/GLM-5.3-Flash-DFlash2 at6cc6c481,TF_GLM_CLEAR_THINKING=1 TF_GLM_REQUEST_STARTS=1 TF_GLM_DENSE_BITS=8 TF_GLM_HEAD_BITS=8 TF_GLM_KDA_PAD=1 TF_ROCE=1, greedy.Paths and platforms the change reaches, which I ran and which I could not: ran TP=3 drafted decode at one and four streams, cold prompts to 28.8K tokens, one 1440 × 900 image a start. Could not run TP=1 and TP=2, other chips, other nvcc versions.
Exactness: 13 greedy replies (8 prompts alone, 4 at once, one prompt of about 8K tokens) hash the same in all 13 starts of this receipt, with the switch on and off.
tools/bench_concurrent.py --alone --serialreported 0 failed and 0 unmeasured in each of the five timing starts.Decode speed before and after, from
tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0: the table's rows 2 and 3.tools/bench_concurrent.py --tokens 256 --reps 3 --temperatures 0 --levels 1,4 --alone --serial:TF_GLM_PDL=0Four streams show no clear gain here: the two starts of one build differ by more than the builds do. The tokens a round over the 16 requests are 3.058 in every start.
Prompt speed before and after: not from
tools/bench_cache.py; I used a script that sends two prompts of new text at each size to a fresh start and reads the first token's time. Seconds, two requests a start, starts in the order main, branch, branch, main:So about 1% slower on long cold prompts at TP=3 on
df0a2a2614, the same in both branch starts;f5baf0e14removes it (17.70, 17.73 and 17.61, 17.68 s at 28.8K, in the comment below). The first 1440 × 900 image of a start took 2.91 and 2.90 s on main and 2.88 and 2.87 s on the branch.Where the decode time went:
TF_GLM_PROF=1with MTP drafts (--mtp-confidence 0.5), the 4-row verify calls, mean ms a call on rank 0, starts in the order main, branch, branch, main:Ranks 1 and 2 move the same way (wall 47.41 / 47.51 to 45.84 / 45.59 on rank 1, 47.39 / 47.50 to 45.84 / 45.58 on rank 2).
Licence of any new weights or drafter: n/a.
Kernel contract, only when a GPU kernel is new or changed
glm_cuda_records.zig,lane_half_records.zig,modelopt_lane_records.zig,nvcc_133_records.zigandregistry.zig.glm-pdl-order's planted early read fails as planted (above).SUMMARYline and exit status: CUDA on GB10 with nvcc 13.0, exit 1:SUMMARY 661 kernels: 661 pass gates 1-4, 0 fail, 8 known findings; 422 controls: 422 red as planted, 0 missed; 186 limit problems. All 186 limit problems readno compiled usage recorded(183 in the table check, and 3 of the same kernels in the live check). They are on 43 records in the flashnext_mtp, exl3_experts, nvfp4_experts_tile, qwen35 and qwen4 images; none is a GLM or qmmf record, and each record's line is the same text on mainaf9777bas on this head. I did not run the full contract on main to confirm it prints the same 186.Checklist
pr_checkreports no errors.)"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Concurrent equals solo and the 13 hashes: measured. I did not run a"draft": falsecomparison on this head.)f5baf0e14, about 1% slower before it.)