Repository navigation
glm cuda: Flash pieces take full GLM-5.3's shapes (slice (a) of #3063) - #3949
Conversation
f45dfca to
759a736
Compare
|
Thanks @bjornmonnens for this. One thing before we review it: three of the commits (
Once the new head is up we will review the change itself.
|
759a736 to
19c043e
Compare
|
Thanks. The committer lines are fixed: the new head 19c043e has noreply author and committer addresses on every commit. Only this PR's own 4 commits were rewritten; #2094's commits keep their hashes so the stack stays on 9e24139. Main's dependent-launch change (7948cc4, c4f29fb) now conflicts with this PR's DSA indexer commit. I'll rebase onto it once #2094 moves onto current main, or right away on top of #2094 if you'd rather review it that way. |
|
I reran One detail to add to the repro is the emulator's platform requirement at this head. The stock emulator command on macOS fails at the two new I also tried merging the stack into Igor Lessio - AIFLOW LABS |
|
Thanks for the cross-platform runs. The emulator fix is in 2be617d: on macOS the emulator's Checked on Zig 0.17.0:
When #2094 moves onto current main I'll rebase the indexer commit onto the dependent launches and rerun the emulator next to the host checks, as you suggest. |
2be617d to
0ebd809
Compare
0ebd809 to
5e27861
Compare
5e27861 to
1cf7eac
Compare
1cf7eac to
91320a4
Compare
|
Thanks for rebasing this onto current main overnight. When #2094 moved to
Checked on GB10 with Zig 0.17.0:
|
91320a4 to
18c78a3
Compare
|
Thanks for landing #2094. I've rebased this onto Checked on GB10 with Zig 0.17.0:
|
18c78a3 to
02e2349
Compare
|
Rebased onto |
…s, state and snapshot plans (ashhart#3063) Full GLM-5.3 keeps 79 latent caches (78 DSA layers and the MTP layer) of 576-value rows (kv_lora 512 and qk_rope 64), a pooled key a row and no KDA layers. config.zig reads qk_rope_head_dim into Config.rope (still refused unless 0 for GLM-5.3-Flash) and latentRow() is kv_lora + rope. cuda_state's Shape carries the cache count, the row width, the index key dims and the pool size (Config.kpool) that pages, a State's arena and onPages lay out from, and the snapshot plan takes its latent and pooled spans from the same shape; its parts hold up to 79 caches instead of max_layers' 47. The KV host gather's row bytes follow latentRow(). GLM-5.3-Flash's 12 caches of 512 values and pools of 4 give the same 13,056 bytes a row and the same plans.
…arameters (ashhart#3063) Full GLM-5.3 scores every index key (no pooling, top 2,048 over the whole history) and ropes the first 64 dims of its index keys and queries in interleaved pairs. cuda_sparse.Geometry carries the pool size, the pools a row keeps, the roped dims and their fp32 frequencies; dsa_block.Index holds one, set from Config.kpool and index_topk (GLM-5.3-Flash: 4, 512, none). The kernels take the pool size where they divided by 4: tf_glm_scores, tf_glm_index_scores (a page's pools become 512 / pool), tf_glm_select_rows and its wide form, tf_glm_index_pools, tf_glm_dsel_scan and _merge, and tf_glm_dsa_tokens (pool K tokens and a tail of pool - 1). tf_glm_pool_keys keeps its gated softmax for pools of 4; pools of 1 store each LayerNormed key as written and read neither gates nor ape, so scoring pool 1 is scoring every key directly. tf_glm_index_write ropes its LayerNormed key below `rope` before the bf16 store, and both score kernels rope the query fragments they load (glm_index_rope.cuh; the angle's sincosf out of line). A State's index key rows come from Shape.keys (index_ring, or maxInt for a whole sequence) and its rebase keeps whole pools of State.pool. Every existing call passes GLM-5.3-Flash's values, so its launches compute the same bytes. The emulator (test-glm-index-emulate) adds pool-1 scores, paged at 512 keys a page, with queries roped on 64 dims against a model that ropes them itself, and pool-1 top-2,048 picks through tf_glm_index_pools and the decode select. The GPU contract and check launchers pass the new arguments at GLM-5.3-Flash's values, and nvcc 13.0's records follow the six changed launches (tf_glm_pool_keys, tf_glm_scores, tf_glm_index_scores, tf_glm_select_rows, tf_glm_dsel_merge, tf_glm_dsa_tokens). The contract also runs full GLM-5.3's values on these kernels (contract_glm_full.zig): tf_glm_scores at pools of 1 with 64 roped query dims against float64, allowing the roped queries' bf16 rounding; tf_glm_index_scores bit-equal to it; tf_glm_dsa_tokens at pools of 1; and tf_glm_index_write's LayerNormed keys roped on 64 dims against float64. Four planted controls go red: queries or keys left unroped, keys read as pools of 4, and token lists one position late. A score's -inf (a pool the row cannot see) is checked exactly.
… the mla image (ashhart#3063) Full GLM-5.3 keeps 64 roped key columns past its 512-value latent and splits each 256-wide q head into 192 latent-path dims and 64 roped ones. The DSA block's Layer carries rope (Config.rope, 0 on GLM-5.3-Flash) and its fp32 frequencies; row() is lw + rope and qHead() qk + rope, which size the kv_a and q_b widths, the latent and absorbed q rows, their scratch and the token lists' page rows, and the softmax scale is 1 / sqrt(qk + rope) (1 / 16 on both). A roped row takes cuda.mla's image (loaded only when Config.rope is set): its GPT-J rope turns k_pe at pos + r into the latent row before the cache write and each head's q_pe into qa past the absorbed latent; the chunk tiles are tf_mla_chunks_r16 (chunks_wide<16, false, 64>), now launched on pages and over token lists through Mla.chunksOn as GLM's own chunks are. Roped rows keep 16 heads a block in prompt chunks too: wide_smem<32, 64>() is 113,408 bytes, past the 99 KiB a block may take on sm_86 to sm_121. The merge and expand_v stay GLM's (the values are the latent's). The one new kernel is tf_mla_absorb_q_192 (tf_mla::absorb_q<192>, q rows 256 apart, qa rows 576), under the contract with a planted control and nvcc 13.0 records (72 registers on every SM). A page is padded to whole 576-wide rows and whole token bytes (their lcm), so a token list's page rows stay whole: full GLM-5.3's 79 caches take 4,096 bytes more a page (49,440 rows). GLM-5.3-Flash's page, buffers, kernels and launch arguments are unchanged, pinned by host tests at both shapes.
Main 7948cc4 routes GLM launches through cuLaunchKernelEx. Forward that entry through main's pdl.forwardEx in the new recording fixtures and keep the merged code in zig fmt style.
02e2349 to
a970627
Compare
|
Thank you @bjornmonnens. 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. |
What this changes
GLM-5.3-Flash's CUDA pieces take full GLM-5.3's shapes as parameters, slice (a) of #3063: pages, state and snapshot plans take the latent row width (576) and cache count (79), the DSA indexer takes its pool size (1), whole-history key store and 64-dim index rope, and the latent path takes 576-wide roped rows on the mla image with one new kernel,
tf_mla_absorb_q_192. Every GLM-5.3-Flash call passes today's values, so Flash computes the same bytes and its replies are unchanged.main579450c2c, after glm cuda: EXL3 mcg experts at any whole-bit width, mixed by projection #2094 (full GLM-5.3's mixed 2- to 4-bit EXL3 experts) landed: 3 commits (7d90b8b02,73d0d178c,8a310fcd3), the CHANGELOG line (4bf0dcc9e), a macOS fix for the index emulator (76dd30e95) and @ashhart's two commits for main's dependent launches (9040d8f84,02e234998).atc overlap --json: ATC 0.9.6 (overlap --base upstream/main --pullswith the 11 PRs below) found shared files with glm cuda: EXL3 mcg experts at any whole-bit width, mixed by projection #2094 (20), Ling-3.1-flash on CUDA, on one or two GB10s #2340 (3), cuda: Qwen 3.5, Gemma 4, Nemotron and Flash Next keep states through core's walk, no gain, a cleanup (#1293, on #2215) #2392 (1), GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415 (10), GLM on CUDA: owner-only latent rows and owner-computed attention (TF_GLM_KV_SPLIT, #1431 part 2; stacked on #2415) #2935 (13), GLM on CUDA: the prompt history fetch under the latent split (TF_GLM_KV_SPLIT, #1431 part 3; stacked on #2935) #2937 (14) and GLM on CUDA: kept states, carries and prompt twins under the latent split (TF_GLM_KV_SPLIT, #1431 part 4; stacked on #2937) #2938 (16); its conflict check was unavailable (git older than 2.38 on that machine) and it reached its time limit before kv classes (#2444 C1): admission by owner class, the owner chosen once inside the reservation #3676, glm cuda: a dense MLP stored bf16 is read as bf16 in any checkpoint, not only an EXL3 one #3680, GLM-5.3-Flash on CUDA: a decode window's DSA index scores on tf_glm_index_scores (TF_GLM_DSCORES) #3689 and glm cuda: decode kernels as dependent launches (carries #3673), +3.7% decode at TP=3, same tokens #3776. The full check done by hand on git 2.43: every open pull request's head test-merged against this branch withgit merge-tree. Of 464 open PRs, 158 touch a file this changes; conflicts this branch adds against main's: glm cuda: decode kernels as dependent launches (carries #3673), +3.7% decode at TP=3, same tokens #3776, GLM-5.3-Flash on CUDA: a decode window's DSA index scores on tf_glm_index_scores (TF_GLM_DSCORES) #3689 and glm cuda: a dense MLP stored bf16 is read as bf16 in any checkpoint, not only an EXL3 one #3680 (GLM CUDA files this also edits) and Ling-3.1-flash on CUDA, on one or two GB10s #2340 (cuda_latent.zig); kv classes (#2444 C1): admission by owner class, the owner chosen once inside the reservation #3676, GLM on CUDA: kept states, carries and prompt twins under the latent split (TF_GLM_KV_SPLIT, #1431 part 4; stacked on #2937) #2938, GLM on CUDA: the prompt history fetch under the latent split (TF_GLM_KV_SPLIT, #1431 part 3; stacked on #2935) #2937, GLM on CUDA: owner-only latent rows and owner-computed attention (TF_GLM_KV_SPLIT, #1431 part 2; stacked on #2415) #2935, GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415 and cuda: Qwen 3.5, Gemma 4, Nemotron and Flash Next keep states through core's walk, no gain, a cleanup (#1293, on #2215) #2392 already conflict with main. Whichever lands second rebases; none of them changes what this does.Notes for review, against the 2026-11-17 comment:
chunks_wide<32, false, 64>does not fit, aswide_smem<32, 64>()is 113,408 bytes, past the 99 KiB a block may take on sm_86 to sm_121, so roped rows run as two head blocks of 16 (tf_mla_chunks_r16, the second guarded past the rank's heads) in prompt chunks as in decode. No new head-block shape.tf_mla_absorb_q_192) are reached by the GLM family's code whenConfig.rope/kpoolsay so, by host tests at both shapes and by the kernel contract; the first checkpoint that sets them loads in (b). If you would rather havetf_mla_absorb_q_192land with (b), I can move that commit's kernel there.Checks on this head
02e234998, onmain579450c2c. The DSA indexer commit also passes its geometry through main's decode scores (TF_GLM_DSCORES:scoresTiles, the decode call inselectTokens, the contract's decode shapes andglm-index-check), at GLM-5.3-Flash's values there.python3 tools/zig/lean_check.py:main579450c2c165, this head 165, 0 new.tools/pr_check.py --base 579450c2c --pr 3949: 0 errors, 0 warnings.zig build test-cuda-host compile-cuda-tests test-glm-index-emulate test-glm-exl3-prompt-host test-exl3-prompt-host test-glm-index-host test-glm-ring-host -Dnvcc=/usr/local/cuda/bin/nvcc: 657/657 steps, 8183/8226 tests passed, 43 skipped, 0 failed (Zig 0.17.0, GB10).zig build test: passes.zig build -Dgpu=spark -Dnvcc=/usr/local/cuda/bin/nvcc -Doptimize=fast: builds.main0900b484ewith a 4th commit of ours that read the mixed widths in place of glm cuda: EXL3 mcg experts at any whole-bit width, mixed by projection #2094; GLM-5.3-Flash's 4-bit experts take the same bytes and kernels under either (glm cuda: EXL3 mcg experts at any whole-bit width, mixed by projection #2094 keeps the 4-bit path upstream's), and the kernels this changes are the same code.tools/conformance.pyon GLM-5.3-Flash at TP=2 (profile:qwen35-cuda.json's prompts and gates with Flash's serve flags and levels 1 and 2; the cache-off server,--prompt-cache-gib 0, and the cached one,--prompt-cache-gib 2, run one after the other on the same two Sparks): 7 passed, 0 failed, 0 skipped. drafted == plain 10/10 (392 of 749 drafts accepted), repeat 10/10, concurrent == solo 28/28 (drafted and plain, 16 with a long prompt among decoders), resumed == fresh 6/6 (resumed turns at 4,096 cached tokens), refusals 4/4, cancel 4/4, evict 3/3.--drafter(DFlash2) not run, MTP drafts only.Receipt
Main against branch: GLM-5.3-Flash EXL3 4bpw at TP=2 on two DGX Spark (GB10), greedy,
main0900b484eagainst this head on the same machines and checkpoint.Boxes it reaches: CUDA GLM-5.3-Flash (unchanged values); full GLM-5.3's paths (no caller yet, see above).
New switch? None.
Environment: TensorFold
c548cc601(these 3 commits and our own mixed-width loader over main0900b484e, the tree measured on the GPU); Zig 0.17.0; CUDA 13.0 (nvcc 13.0); 2× DGX Spark, NVIDIA GB10 (sm_121), Linux aarch64;Mia-AiLab/GLM-5.3-Flash-EXL3-4bpw-TensorFoldrevision078455ffe6472f9a52fbc1139f58b9db2881b25c.Paths and platforms the change reaches: CUDA only. Ran on sm_121; sm_80/86/89/120 compile with nvcc 13.0 records but were not run.
Exactness: 8 of 8 greedy replies identical, main against branch (4 solo, 2 long prompts of about 9k and 22k tokens, 2 paired), and the paired replies equal their solo ones on both; the cold 16,384-token prompt's
token_shais the same (5e6751dc5ed6) alone and at 2 streams. Drafted, resumed and concurrent against plain, fresh and solo: the conformance gates above.Main against this branch, same machine and checkpoint: below.
Decode speed before and after,
tools/bench_openai.py --tokens 256 --reps 5 --temperatures 0(median tok/s):Within run-to-run spread: an earlier round of the same commits on
e7ff97e13gave 60.8 against 63.3 and 25.9 against 27.9.Prompt speed before and after,
tools/bench_cache.py --require-cold, 16,384-token prompt, cold first requestttft_s: main 13.92 s, branch 14.60 s (earlier round: 15.14 s against 14.21 s).Licence of any new weights or drafter: n/a.
Kernel contract, only when a GPU kernel is new or changed
tf_mla_absorb_q_192(new;tf_mla::absorb_q<192>, 21 and 22 heads) against float64.zig/tests/cuda/contract_glm_full.zig):tf_glm_scoresat pools of 1 with 64 roped query dims against float64;tf_glm_index_scoresreplaces (bit-equal to)tf_glm_scoresthere;tf_glm_dsa_tokensat pools of 1;tf_glm_index_write(LayerNorm + 64-dim key rope) against float64.tf_glm_pool_keys,tf_glm_scores,tf_glm_index_scores,tf_glm_select_rows,tf_glm_dsel_merge,tf_glm_dsa_tokens), with nvcc 13.0 records.tf_mla_absorb_q_192reading the next head's weights; scores with queries left unroped; scores reading keys as pools of 4; token lists one position late; index write leaving keys unroped.SUMMARYon GB10 (sm_121):kernel-contract glm GLM48/48 pass, 23/23 controls red, 4 findings (the existingreluNaN rule, also in the two new scores cases);kernel-contract mla8/8 pass, 9/9 controls red.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. (Measured at--parallel 2without a drafter.)