Repository navigation
glm cuda: an uneven KDA stack padded to 16-byte rows keeps its bytes; cold first tokens 10-11% sooner at TP=3 - #3697
Conversation
|
Thanks @ultradaoto. Padding each rank's stack to its own width rounded up to eight columns is a neat way to keep the unpadded bytes and still reach the staged tiles.
On your question: please keep The code applies to current main as it is. The only conflict is the CHANGELOG line, which we settle when it lands. Nothing to change. CI on this fork still needs approval to run, and it has to be green at this head before landing.
|
|
I ran On a scratch merge of that main plus #3697 and #3689, I built Igor Lessio - AIFLOW LABS |
5edf171 to
3ea1454
Compare
…on the staged tiles (for ashhart#3516) At worlds where a rank's fused KDA input is not eight columns wide (3, 5, 6, 7), its rows are not 16-byte aligned, so prompt windows ran on tf_glm_bmm_rows and never on the staged tiles, which give the same bytes. The stack is now always padded at load to its own width rounded up to eight columns and stays row-major bf16: prompt windows take tf_glm_bmm_tile and tf_glm_bmm_tile1, decode windows keep tf_glm_bmm_decode. TF_GLM_KDA_PAD=1 keeps main's common width and still tiles the stack for glm_mm. No kernel changes, no new switch. glm-ref checks both of TP=3's shapes and the f_b view at 144 row counts from 1 to 2,048: every byte as the uneven rows'.
Forward cuLaunchKernelEx to the existing Capture.launch recorder, as the adjacent TP3 test already does. Keep the test assertions and production PDL default unchanged.
3ea1454 to
f00e5f0
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. |
For #3516, as invited when #3519 was closed: the pad's first-token gain with the unpadded stack's exact bytes. No switch and no new kernel.
What this changes
At worlds where a rank's fused KDA input is not eight columns wide (3, 5, 6 and 7 among the first eight), the stack's rows are not 16-byte aligned. So
b16.matmulsends its prompt windows totf_glm_bmm_rows, the unstaged kernel, and never to the staged tiles. The staged tiles give that kernel's bytes: the same mma chain per K slice, slices added in order (glm-refchecks it for aligned shapes today).Now the engine always sets the stack's row width (
kb.pad_to):kb.alignedWidth: at TP=3, 8,726 → 8,728 on rank 0 and 8,341 → 8,344 on ranks 1 and 2; at worlds 1, 2, 4 and 8 it is the stack's width and nothing moves). The padded stack stays row-major bf16 on the B16 kernels. Prompt windows from 128 rows taketf_glm_bmm_tile(the stack) andtf_glm_bmm_tile1(the f_b and g_b views, whose input rows are now 16-byte aligned). Decode windows keeptf_glm_bmm_decodefor the stack; the views take Triton's staged tile wheredecode_tileshas their shape.TF_GLM_KDA_PAD=1: as on main. The stack is padded to the common width and tiled for glm_mm, and packed underTF_GLM_DENSE_BITS.kb.tile_padcarries the switch, andLayer.tiledInput()is true for an even stack or a padded one with the switch.tile.padKdaInputsmoves fromtileLinearsto the engine's load step, so the pad also runs withTF_GLM_MM=0.No kernel changes, no new switch, no fingerprint change. The pad is two zero rows a layer on TP=3's rank 0 and three on ranks 1 and 2.
Tests
tf-cuda-test glm-refon a GB10, new checkpaddedStack: both of TP=3's shapes, the stack [8726, 4096] padded to 8,728 and [8341, 4096] padded to 8,344, and the f_b view [2816, 128] / [2688, 128] read from the projected rows at the uneven and at the padded stride. 144 row counts each: every count from 1 to 130, then prompt passes up to 2,048 rows. Every byte of the first n columns equals the uneven rows' call, and every pad column is zero.glm-ref: 27 PASS, 0 FAIL.glm-kda-pad-split: PASS.cuda_kda_tp3_test.zig, new host test: at worlds 3 and 5 with the width set asEngine.opensets it, which kernel each of the three projections takes at 1, 17, 127, 128 and 2,066 rows, unset and with the switch; at worlds 1, 2, 4 and 8 the width is the stack's own and glm_mm reads it as before. The old test (width unset) is untouched.zig build test-cuda-hostona437511plus this diff: one failure,cli_config_test'sserve --config: expand reads the file ..., which fails the same way on main on this host (6,830 of 6,864 passed and 33 skipped on the branch's first full run).zig fmt --checkclean.pr_check --base a437511: 0 errors, 0 new lean findings.git merge-treeis clean against main9489c38and against glm cuda: decode kernels as dependent launches, +6.8% decode at TP=2, same tokens #3673's head7017c23.Receipts
Three GB10s on a switchless triangle, TP=3, GLM-5.3-Flash EXL3,
--parallel 4 --kv-cache fp8 --decode-share 0.5, bf16 (noTF_GLM_DENSE_BITS, noTF_GLM_KDA_PAD), MTP drafts, greedy. Maina437511and the branch built here the same way (Zig 0.17.0, nvcc 13.0). Starts in one session, in this order: main, (the first version twice, see below), main, branch, branch, (a main start that is not used, see below), main. One number per start, or two where the tool takes two:a437511tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0, code, median tok/stools/bench_concurrent.py --tokens 256 --reps 3 --temperatures 0 --levels 1,4 --alone --serial, 4 streams, codeThe cold prompts are a nonce line and Python source,
max_tokens1, thinking off, each length twice a start.Tokens: 13 greedy replies (8 prompts alone, 4 at once, one prompt of about 8K tokens) hash the same in every start, and so do
bench_concurrent's 36 (alone and serial, 1 and 4 streams). One cold 1440x900 image answers the same in every start.Decode is level.
TF_GLM_PROF=1,--mtp-confidence 0.5, the 4-row verify calls, mean ms a call, starts in the order main, (the first version twice), main, branch, branch, main:The switches around it, one start each of main and the branch on the same settings:
TF_GLM_DENSE_BITS=8 TF_GLM_HEAD_BITS=8without the pad switch: both log188 linears packed, so the stack stays bf16 on the branch as on main. 13 of 13 hashes equal between them. Cold 7.2K 5.02 → 4.54 s, 28.8K 19.18 → 17.16 s; the 16 requests 45.69 → 45.84 tok/s.TF_GLM_MM=0: 13 of 13 hashes equal between them. Cold 7.2K 5.00 → 4.51 s, 28.8K 19.04 → 16.99 s; the 16 requests 39.65 → 39.62 tok/s.TF_GLM_KDA_PAD=1with the dense bits and a DFlash2 drafter, on the branch:290 linears packed, and 13 of 13 hashes equal to the 1.2.9 release's on those settings.Two things about how these were taken:
TF_GLM_KDA_PAD=1does. It had the same first tokens, but ranks 1 and 2 then carried a 4.6% wider stack: their kda went 16.4 → 16.9 ms and every rank's wall 60.9 → 61.2 ms. That is why unset pads each rank to its own width.Not run: TP=2 and one GPU (the row width there is the stack's own, which the host test walks), and FP4-Local's split stack on a served model (
glm-kda-pad-splitcovers its pad).One question: I left
TF_GLM_KDA_PAD=1on the common width. If nothing needs one width across the ranks, it could take each rank's own width too and spare ranks 1 and 2 the wider rows. Say so and I will add it here or after.CI: this fork's runs wait for a maintainer's approval, as on my other PRs.