Repository navigation
Race a Triton tile kernel against cuBLAS for GLM's BF16 head projections - #231
original-el8 wants to merge 2 commits into
Conversation
Flare compiles its Triton kernels against the CUDA toolkit's libdevice so that native discovery, compiled forwards and Inductor's eager-precision path share one program identity. That selection ran when a preparation session was constructed or a standalone declaration prepared. A kernel compiled earlier in the process against Triton's bundled libdevice stayed in its JIT memo, which is keyed by specialization and launch options only, and a later race materialization reused it under the bundled identity while discovery had declared the toolkit one. The BF16 batched GEMM test module hit this on its race test after its per-tactic tests compiled the same specialization: "preparation used undeclared programs for k-major". ignition.preparation.tuning now prepares the compiler toolchain at import, before any component kernel in the process can compile: it applies Ignition's runtime patches and then selects the toolkit libdevice. The session constructor and standalone declarations no longer repeat it. Compiler workers inherit the selection through TRITON_LIBDEVICE_PATH as before. Validation on 91cfb36 with this change: tests/preparation/test_toolchain.py passed 3 tests on CPU, including a case that checks the library identity right after import. The BF16 batched GEMM component that follows this commit runs its CUDA race test after its per-tactic tests in one process; see that commit for its results. SM103 kernels in moe_sm103.py and sm103_projection.py were not exercised. Design-Signed-Off-By: flare-02; design-review=4d3a
GLM 5.3 Flash's MLA query absorption and value expansion multiply token-major head stacks by per-head BF16 kv_b_proj slices through BatchedUnquantizedProjection, which launched torch.bmm directly. cuBLAS selects its strided-batched kernel by device: on GB10 it runs cutlass_80_wmma_tensorop_bf16_s161616gemm_bf16_32x32 for every layout, which moves the 403 MB of a TP2 8192-row absorption at about half of the device's measured 220 GB/s copy bandwidth. BatchedUnquantizedProjection now declares a prepared plan of the flare.bf16_bmm component. Its tuning race times cuBLAS against a Triton tiled kernel over the declared strides, with legal tiles chosen by the stack's row count and the output and reduction widths, and keeps the faster implementation on the preparing device. Both implementations accumulate in FP32 and round once to BF16; no scratch is used, and the output stays the caller's strided view. The compile factory registers the kernel with b12x's planning-artifact eviction, since b12x only evicts deferred programs of kernels defined in its own modules and a compile worker that planned a program would otherwise return the deferred entry instead of lowering it. One GB10 (DGX Spark), 8192 rows, torch.bmm versus the selected 64x128x64 tile: TP2 absorption 3.53 ms to 2.02 ms, TP2 expansion 2.62 ms to 2.02 ms, TP4 absorption 1.77 ms to 1.00 ms, TP4 expansion 1.27 ms to 1.01 ms. A plain copy of the same bytes takes 1.84 ms and 0.93 ms. Every tile produces results bitwise equal to torch.bmm at the probed GLM shapes on GB10 and RTX PRO 6000; the test contract allows one BF16 ulp. On RTX PRO 6000 the race also selects the 64x128x64 tile for 1024-row stacks. Validation on 91cfb36 with this change and the libdevice commit before it: tests/components/test_bf16_bmm.py, tests/components/test_linear.py and tests/preparation/test_toolchain.py passed 23 tests on CPU, and tests/components/test_bf16_bmm_cuda.py passed 5 tests on one RTX PRO 6000 (SM120) with an empty Triton cache, covering every legal tactic at 65-, 2- and 4096-row stacks with row-tail masking, and a raced session captured and replayed without allocation. The same component source, built on an integration branch, passed test_bf16_bmm_cuda.py on GB10 and tests/recipes/test_glm53_mla_cuda.py at TP2 and TP4 on RTX PRO 6000 with the GLM-5.3-Flash-FP4-Local checkpoint, whose kv_b_proj is BF16; the GB10 timings above come from that build. An exported GLM-5.3-Flash package that combines this component with other prefill changes served TP2 8,192-token prefill at 2945 tokens/s on two DGX Sparks, against 2620 to 2631 tokens/s for packages without those changes (three-request probe means); that difference is not attributed to this commit alone. The MXFP8 kv_b_proj path (BatchedQuantizedProjection) and SM103 are unchanged and were not run. Design-Signed-Off-By: flare-02; design-review=4d3a Signed-off-by: Jason Cook <jasonc@maxlyn.com>
|
Categorized as kernel performance work requiring Review the operator's placement and existing b12x alternatives, compile-worker cache eviction, and numerical/stride coverage before accepting the integration. The PR reports SM120 checks on this branch; GB10 and full-model throughput evidence comes from a combined branch, and SM103 is untested. Those combined results do not isolate this PR's serving gain. |
…integration Brings original-el8's perf/glm53-bf16-head-projections (0ba78eb) onto the integration branch: a prepared flare.bf16_bmm plan racing cuBLAS against a Triton tile for GLM's MLA absorption and expansion, and toolchain preparation at tuning-module import. Clean merge; no file overlaps with the integration branches. Validation on this box (no GPU): tests/components/test_bf16_bmm.py, tests/components/test_linear.py, tests/preparation/test_toolchain.py 20 passed 3 skipped; GLM recipe CPU tests 39 passed 215 skipped. GB10 export and test_bf16_bmm_cuda.py not run. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Design-Signed-Off-By: Claude Fable 5.1 (Claude Code); design-review=4d3a Signed-off-by: Kyonjova <kyonjova@pm.me>
|
@original-el8 GitHub reports merge conflicts with
Please reconcile the branch with main and rerun the checks affected by the resolution. |
|
Repository-split triage: this PR spans both repositories and remains open for its runtime changes.
The recipe portion needs a linked PR against the |
|
A case file has been opened for 231. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review for Agents · Value Proposition · Case File Recommendation: Changes RequestedThanks — the kernel and the prepared-operator shape are clean: the race is expressed as one declared contract, there is no duplicate kernel, no per-model branch, no fallback flag, and I found no concrete defect in Blockers:
Should fix:
Subtract / Simplify:Could remove ~30 of +373 added lines (and ~349 leave the repo with the split):
Nits:4 nits To opt out, include #autobot:ignore in your post or comment. |
GLM-5.3-Flash's MLA query absorption and value expansion multiply token-major head stacks by per-head BF16
kv_b_projslices throughBatchedUnquantizedProjection, which calledtorch.bmm. On GB10, cuBLAS runs one 32x32 WMMA kernel for every layout of these strided batches and moves an 8,192-row TP2 absorption (403 MB) at about half of the device's measured copy bandwidth.Behavior
BatchedUnquantizedProjectiondeclares a preparedflare.bf16_bmmplan. Its tuning race times cuBLAS against a Triton tiled kernel over the declared strides and keeps the faster one on the preparing device. Both accumulate in FP32 and round once to BF16, use no scratch, and write the caller's strided output view.ignition.preparation.tuningprepares the compiler toolchain (runtime patches, then the CUDA toolkit libdevice) at import instead of at session construction. Triton memoizes compiled kernels by specialization and launch options only, so a kernel compiled against Triton's bundled libdevice before a session existed was later reused under an identity that native discovery had not declared ("preparation used undeclared programs"). The new component's CUDA tests compile per-tactic kernels before their race test in one process and need this ordering.Measurements
One GB10 (DGX Spark), 8,192 rows,
torch.bmmagainst the selected 64x128x64 tile:Every tile is bitwise equal to
torch.bmmat the probed GLM shapes on GB10 and RTX PRO 6000; the test contract allows one BF16 ulp.Validation
tests/components/test_bf16_bmm.py,tests/components/test_linear.pyandtests/preparation/test_toolchain.pypassed 23 tests on CPU;tests/components/test_bf16_bmm_cuda.pypassed 5 tests on one RTX PRO 6000 (SM120) with an empty Triton cache.test_bf16_bmm_cuda.pyon GB10 andtests/recipes/test_glm53_mla_cuda.pyat TP2 and TP4 on RTX PRO 6000 with the GLM-5.3-Flash-FP4-Local checkpoint.Limitations
kv_b_projpath (BatchedQuantizedProjection) is unchanged._NATIVE_JITSso compile workers evict its deferred planning entries; b12x evicts only kernels defined in its own modules otherwise.