Skip to content

GLM CUDA: pipeline four-bit EXL3 prompt expert tiles on SM121 - #4701

Draft
MaverickKB wants to merge 1 commit into
ashhart:mainfrom
MaverickKB:codex/exl3-sm121-four-bit-prompt
Draft

MaverickKB wants to merge 1 commit into
ashhart:mainfrom
MaverickKB:codex/exl3-sm121-four-bit-prompt

Conversation

@MaverickKB

Copy link
Copy Markdown
Contributor

What this changes

On SM121, four-bit MCG gate/up and down prompt kernels select the number of eight-member row groups at compile time for each expert tile. They overlap the next K tile's trellis decode with the current tile's MMA operations. The existing skip ID, nine output slots, arithmetic order, rotations and activation epilogues remain in the path. GLM already runs a whole prefill pass of up to 4,096 rows through these kernels.

The pipeline adapts patch 0078 by Mia's AI Lab, licensed under Apache-2.0. That patch credits the K12 loop in Aevonix’s GLM recipe. The public source notice identifies both. TensorFold's whole-pass and mixed-width support landed separately. Original patch · Whole-pass support · Mixed-width support

Checks on this head

  • Head commit: c8737dd.
  • zig build -j2 test-exl3-prompt-host test-glm-exl3-host --summary all passed all 23 tests. The focused registry tests passed all 10, including the new compiler-resource case. A host comparison using TensorFold's cubin parser matched all 20 measured compiler records and returned zero launch-limit problems across four kernels and five architectures.
  • zig fmt --check build.zig zig and git diff --check passed. The lean checker reported 165 findings on base and head. The comparison program builds with g++ -O2 -std=c++17 -Wall -Wextra -Werror and a CUDA driver SDK and OpenSSL.
  • CUDA 13.3.1 builds completed for SM80, SM86, SM89, SM120 and SM121. The native instructions, constant tables, relocations and shared sizes of all five prompt kernels match main exactly on the first four. On SM121 the three-bit variants and the rotation kernel match main. The four-bit kernels from this branch match the native code used for the device results below.
  • CI: Available after publication. Full host, alternate-compiler and other-device numerical suites were not run for this receipt.

Receipt

The direct comparison used one GB10 on Linux aarch64, CUDA 13.3.1, synthetic trellises and the GLM TP2 expert geometry. Each rank sees hidden width 4,096, intermediate width 1,024, 288 routed experts and eight picks plus the shared slot. The comparison reads complete independent trellises for every expert. Inputs in this fixture contain no prompt text or checkpoint weights.

Values below are median device kernel milliseconds, five alternating pairs at each point. The fixture times one projection per process. No speed claim uses a sum of overlapping GPU activity.

Rows Routing Gate/up, main Gate/up, branch Down, main Down, branch
2,048 Balanced 14.046 13.779 9.157 6.612
2,048 Skewed 14.688 14.431 9.464 9.243
4,096 Balanced 21.637 16.417 11.162 11.104
4,096 Skewed 23.362 19.205 14.949 14.292

The repeatable device result is strongest for 4,096-row gate/up. It won four of five balanced pairs and all five skewed pairs. The span of the 2,048-row and down samples includes substantial variability. Peak registers on SM121 fell from 128 to 122 for gate/up and 127 to 122 for down. Both use 43,264 static shared bytes at 256 threads, with zero spill loads or stores.

The verifier compared SHA-256 digests of every contiguous 4 MiB block of raw FP16 or FP32 output against main. All blocks matched. It separately checked every ninth-slot sentinel, finite routed FP32 values, and nonzero routed output. The assignments exercised full and partial tiles, all eight row-group classes, four deliberately empty experts, and excess grid blocks. Every target layer in the measured checkpoint uses the shared gate/up input rotation exercised here. The upstream device suite also offers separate-rotation and non-finite cases. Those cases were not run on this PR head.

The comparison program and its build and run commands are in tools/bench/exl3_prompt_gb10.cpp. Build exl3_experts.fatbin on the two revisions with the same compiler and SM121 target, then pass those files in order to the program in gu and down mode. The 4,096-row projection fixture allocates about 1.23 GiB for gate/up and 1.20 GiB for down, plus the CUDA context.

  • New setting or newly licensed model: None.
  • Other numerical devices: No numerical run on SM80, SM86, SM89 or SM120. The native code comparison above covers all five prompt entry points on those targets.
    Live two-GB10 serving. Three cold SparkDash samples per size reported zero cached tokens on a GLM-5.3-Flash EXL3 TP2 worker with DFlash2. These are a production baseline against a combined downstream image, with other traffic present. The new worker was also processing a large production prompt. A post-benchmark snapshot showed one active request, zero generation and KV usage above 14%.
Prompt size Baseline tok/s Combined image tok/s Change
4K 924.17 1,295.66 +40.2%
16K 1,353.71 1,131.43 −16.4%

A separate earlier 4K best was 1,044.28 tok/s. The table uses the baseline from this comparison. These serving figures describe the combined image under mixed load. The isolated two-kernel measurement above is the performance evidence attributable to this PR.

  • Decode speed, resumed/parallel versus serial output tokens, and cold first-token latency isolated to this branch were not measured in this receipt. The independent gate/up and down output checks reached every row of the reported shapes.
  • Full base and drafter revisions are outside this synthetic kernel receipt. The live combined test used TensorFold v1.3.4 plus downstream changes. The scoped kernel sources tested by the device micro were verified against this PR's main base and head.
Kernel contract

The existing tf_exl3_prompt_gu and tf_exl3_prompt_down entries replace their existing SM121 four-bit bodies. The three-bit twins have matching compiler-resource records for the shared-ID ABI. Each recorded CUDA 13.3 launch matched its compiled cubin on all five supported targets. Earlier compilers still report their prior pending status. This receipt includes the direct raw-output comparison and compiler gate 5 above. The full GPU kernel-contract numerical SUMMARY and planted controls have not been run on this head.

Raw paired CUDA event measurements in milliseconds

The two lists in each row are matched by position. Launch order alternated between pairs.

Rows Routing Projection Main Branch
2048 balanced gu 14.046, 13.712, 13.818, 14.240, 14.397 13.779, 14.102, 13.975, 13.522, 13.681
2048 skew gu 15.918, 14.579, 14.688, 14.774, 14.641 14.735, 14.431, 10.550, 13.877, 14.475
4096 balanced gu 21.637, 19.440, 19.907, 22.707, 23.129 15.250, 15.551, 16.417, 23.333, 18.131
4096 skew gu 25.836, 20.032, 23.362, 23.467, 20.889 19.205, 18.938, 19.508, 19.410, 19.172
2048 balanced down 11.310, 6.636, 9.471, 9.157, 9.085 6.631, 9.669, 6.501, 6.037, 6.612
2048 skew down 10.998, 9.464, 9.624, 9.299, 9.368 9.111, 9.966, 9.259, 9.183, 9.243
4096 balanced down 13.144, 11.162, 10.913, 10.923, 13.808 10.767, 13.865, 11.104, 13.720, 10.854
4096 skew down 12.930, 18.819, 14.973, 14.949, 14.071 14.200, 14.292, 14.720, 13.761, 14.597

Checklist

  • Scope, compiler, device and tested shapes identified.
  • Reproducer and raw paired measurements included.
  • Public source and license attribution included.
  • Full GPU kernel-contract numerical SUMMARY, planted controls and isolated model token/throughput matrix available. These remain open verification items.

Adapt Mia's AI Lab's GLM recipe patch 0078 to the shared-id prompt ABI. Keep the existing activation and output epilogues, shared-expert skip, MMA order and output layout. The source notice credits the K12 input from Aevonix.

Record nvcc 13.3 resources for each target and include a two-image driver comparison at the TP2 shape.
@chai-md

chai-md commented Nov 23, 2026 •

Copy link
Copy Markdown

We maintain the recipe patch this adapts (Mia's AI Lab), so a note from that side.

The adaptation is faithful where it matters: the launch ABI is left alone (nine slots, the skip slot kept), the row-group count is chosen at compile time, and the pipeline overlaps the next K tile's trellis decode with the current tile's MMA the same way the original does. Keeping the ABI is the right call for this tree — it keeps the change inside the kernel, and it is the part of the original we would otherwise have had to argue about.

We are not putting forward a competing implementation; we would rather see this land. If it helps, we have a 2× GB10 Spark pair (TP=2, KV=fp8 with the page pool) and can build this branch and post serving-level numbers — prefill at 16K and 64K, single-stream decode, and a run against a 1M-token KV pool — so the review has end-to-end figures next to the per-shape kernel ones.

@joshuaswarren

Copy link
Copy Markdown
Contributor

5060 Ti (sm_120) kernel-contract exl3 on head c8737dd — built off-card on aarch64 Spark (nvcc 13.0, zig baseline aarch64; records' reference toolchain is nvcc 13.5 per prior rows).

  • 20/20 kernels pass gates 1–4
  • 11/11 planted controls red, 0 missed
  • 7 limit problems:
    • exl3_experts prompt kernels (tf_exl3_prompt_gu, tf_exl3_prompt_down, ..._k6 pair): launch fine (256 threads, driver allows 256) but records read 0,0 — measured 124–127 regs, 40–43 KB shared
    • exl3_grouped tf_ctl_exl3_grouped_old_0/1/2: +64 B shared vs record (32896 vs 32832) and +1 reg on _0 — nvcc 13.0 vs recorded toolchain drift, not a functional diff

rc=1 is the limit-problem exit; no gate or control failures on sm_120.

This branch has not been deployed

No deployments
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.

3 participants