grouped gemm: accept canonical (sum_m,k)/(l,n,k) layouts and flat SF buffers - #796
Draft
hwanseoc wants to merge 1 commit into
Draft
grouped gemm: accept canonical (sum_m,k)/(l,n,k) layouts and flat SF buffers#796hwanseoc wants to merge 1 commit into
hwanseoc wants to merge 1 commit into
Conversation
…buffers The contiguous grouped GEMM SwiGLU/dSwiGLU wrappers and API classes now additionally accept natural row-major inputs -- A (sum_m, k), B (l, n, k) C-contiguous, dense C-contiguous SFA/SFB buffers (flat or physical atom shape), prob (sum_m,) fp32/bf16 -- and normalize them internally. Canonical SF buffers compile as flat 1-D pointers: the kernels already rebuild the MMA-tiled SF layouts from the GEMM shapes and read only the base pointer. Canonical calls return natural-shaped outputs; alpha defaults to cached ones. Pre-permuted kernel-facing inputs keep working unchanged.
Member
Author
|
@coderabbitai ignore |
Contributor
|
Note Reviews pausedUse the following commands to manage reviews:
Use the checkboxes below for quick actions:
Comment |
Contributor
✅ Action performedReviews paused. |
hwanseoc
marked this pull request as draft
August 28, 2026 23:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements the canonical-layout proposal for the contiguous grouped GEMM SwiGLU forward and dSwiGLU backward APIs (Slack thread): callers hand cuDNN the buffers they already own, in natural row-major form, instead of pre-permuting every operand into kernel-facing cute views. This removes the per-call layout gymnastics TE does today (e.g.
sf.view(dtype=e8m0).view(1, m//128, k//128, 32, 4, 4).permute(3, 4, 1, 5, 2, 0)ingrouped_mlp.py), and it makes every input of these two kernels expressible as a dense row-major array — the prerequisite for ajax_api.pyforgrouped/swiglu+grouped/dswiglu(follow-up PR; today they are the only grouped variants without one, blocking TE JAX MoE).New accepted signatures (additive — every pre-permuted form keeps working unchanged)
grouped_gemm_swiglu_wrapper_sm100/GroupedGemmSwigluSm100andgrouped_gemm_dswiglu_wrapper_sm100/GroupedGemmDswigluSm100now also accept, per operand and independently:A(valid_m, k, 1)k-major(valid_m, k)row-majorB(n, k, l)k-major strided view(l, n, k)C-contiguousC(dswiglu input)(valid_m, 2n, 1)n-major(valid_m, 2n)row-majorSFA/SFB(32, 4, mn/128, 4, rest_k, l)strided view(l, mn/128, rest_k, 32, 4, 4)prob(valid_m, 1, 1)float32(valid_m,)float32 or bfloat16alphaNone→ cached onesWhen
Ais canonical (2-D), outputs come back natural-shaped:c (m, n),d/d_col (m, n/2)(dswiglu:d_row/d_col (m, 2n),dprob (m,)) row-major, andsfd_row/sfd_colas C-contiguous physical(1, mn/128, rest, 32, 4, 4)buffers.What FE derives internally
tile_atom_to_shape_SFand consume only the base pointer (grouped_gemm_swiglu_quant.py:588). A canonical SF buffer therefore compiles as a flat 1-D dynamic-length fake tensor; no MMA-permuted view is ever materialized, host- or device-side. Kernel bodies unchanged.unsqueeze/permuteat the API boundary (grouped/canonical.py); form detection is by rank/stride, so the two forms coexist and cache separately (compile signatures differ; the wrapper cache keys carry the form)..to(cutlass.Float32)at the prob load site in both kernels (no-op for fp32 prob).Compat
jax_api.pylands (the eager wrapper remains torch-lazy).Host latency at Jeremy's DSv3 shape
benchmark/gemm/bench_grouped_gemm_canonical_host_latency.py, (sum_m, n, k) = (24576, 7168, 2048), 8 experts, MXFP8, first dim overallocated 1.5–4×, B200, GPU idle before each timed call. "Legacy" includes the TE-style per-call view/permute gymnastics the old contract forces on the caller.The wrapper host cost is dominated by descriptor validation + tvm-ffi marshalling (see #627/#589), so retiring the caller-side view/permute is worth ~3 µs/call (~5%) here; what it doesn't capture is TE's surrounding per-call weight
copy()/swizzle staging and the code it deletes on the TE side. The primary win of this PR is the contract: every input is now a plain dense row-major buffer.Testing
test/python/fe_api/grouped_gemm/test_grouped_gemm_canonical_layouts.py(9 tests, L0): canonical (physical and flat SF) vs legacy runs on identical device buffers must match bitwise, for swiglu (fp8 + fp4) and dswiglu (fp8); bf16-prob parity; alpha-default parity; natural output shape checks.test_grouped_gemm_swiglu.py,test_grouped_gemm_dswiglu.py, and the JAX-rejection tests. Drive-by: the swiglu wrapper cache key now includes the SF dtype (dswiglu already did); previously e8m0-vs-e4m3 runs of the same config collided on one compiled signature, which surfaced asMismatched Tensor ... expected dtype=float8_e8m0fnuerrors (18 pre-existing test skips on develop now pass).Out of scope (follow-ups)
jax_api.pyforgrouped/swiglu+grouped/dswigluoncudnn.jax.call— this PR makes the representation expressible; the bridge is a separate small PR.grouped/glu/dgluentry points and the bias(n, l)repack, if TE wants it there too.