perf: add small-batch route MMA for MoE - #68
Open
Religious-J wants to merge 2 commits into
Open
Conversation
added 2 commits
July 19, 2026 12:58
Bypass expert sorting and task-map construction for small batches with route-direct SM90 WGMMA, split-K Gate/Up, fused activation quantization, and per-tensor plus blockwise coverage.
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.
perf(moe): add a route-direct WGMMA path for small-batch FP8 MoE
Summary
This PR adds an SM90a route-direct WGMMA path for small-batch FP8 MoE decode, covering both per-tensor and 128x128 blockwise quantization.
For the production dispatch range (batch 1-4, top-k 8), the new path reduces single-op CUDA Graph latency by 9.25%-38.57% (1.10x-1.63x) on the three H20 workloads measured below.
The fast path:
Shapes outside the selected range continue to use the existing implementation.
Motivation
The existing MoE path is designed around grouping rows by expert:
count/sort -> gather -> prefix/task map -> Gate/Up grouped GEMM -> activation/quantization -> Down grouped GEMM -> scatter/top-k reductionThis is efficient once each expert receives enough rows. During decode, however,
B * top_kcan be much smaller than the expert count. For example, batch 1 with top-k 8 creates only eight routes across 128 or 192 experts. Most experts receive zero rows, so sorting, padding, gathering, metadata construction, and intermediate traffic dominate the useful matrix multiplication.The new path keeps data in route order:
topk routes -> route Gate/Up WGMMA -> split reduction + SwiGLU + FP8 quantization -> route Down WGMMA -> contiguous top-k reductionEach logical route is assigned to one SM90 M=8 WGMMA tile. Row 0 carries the route and rows 1-7 are zero-filled. Although this intentionally under-utilizes the M dimension, it avoids the larger fixed cost of expert grouping for very small batches.
Code changes
src/fuse_moe/small_batch_route_mma.{h,cu}to orchestrate the per-tensor and blockwise route pipelines.src/group_gemm/cp_async/group_gemm.{h,cu}.src/fuse_moe/entry.cc.src/fuse_moe/reduce.cuto reduce contiguous route-order outputs without atopk_posmap.Dispatch
The production dispatch remains deliberately conservative.
Per-tensor FP8
1 <= batch <= 4top_k == 80 < I <= 512H % 64 == 0I % 64 == 0Blockwise FP8
1 <= batch <= 4top_k == 8H <= 4096128 <= I <= 768H % 128 == 0I % 64 == 0All other shapes use the existing path. The forced B=5-8 measurements below characterize the profitability boundary only; this PR does not enable those batches in production dispatch.
Correctness
Regression and targeted validation
Reference-comparison metrics:
Performance
Methodology
top_k=8To isolate the fast path, both binaries were built from the same clean
bc97d55source:Speedup = fallback latency / route-MMA latency.Per-tensor Hunyuan-V3 TP8: E=192, H=4096, I=192
This shape remains profitable through B=8. A future shape-aware dispatch could extend its range independently of the blockwise paths.
Blockwise Qwen3: E=128, H=2048, I=768
Route-MMA remains profitable through B=6 for this measured shape and crosses over between B=6 and B=7.
Blockwise: E=128, H=4096, I=512
B=5-6 are effectively at the noise boundary, while B=7-8 regress. The conservative B<=4 production threshold is appropriate for this shape.
Conclusions
Within the current B=1-4 production range, route-MMA improves all three measured workloads by 1.10x-1.63x.