tune(sm90): improve W4A8 indexed MoE block-M selection - #64
Open
Missyinlll wants to merge 1 commit into
Open
Conversation
Collaborator
|
@Missyinlll Please migrate to the new structure and retest now that my PRs landed, thanks! |
Missyinlll
force-pushed
the
sm90-w4a8-bm-heuristic
branch
from
August 20, 2026 14:49
be34207 to
6604443
Compare
Collaborator
|
Can you also update the performance numbers compared to the latest main since other optimizations have landed? Just curious to understand directly what this affects |
Author
Thanks! This PR is already based on the latest I’ve also rerun the benchmarks against latest |
2 tasks
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.
Summary
BLOCK_Mselector for SM90 indexed MoE GEMMs with FP8 E4M3 activations and FP4 E2M1 weights using weight scale group size 32.max_block_m.Motivation
The existing SM90 indexed MoE heuristic selects
BLOCK_Mby minimizing an estimated block count based on a sampled routing distribution. For medium and large routed-M workloads, this can select overly large BM values.For a given minimum per-expert M-tile count, a smaller BM that preserves the same tile count can reduce padding without increasing the primary tile count. The new selector uses the expected routed rows per expert to determine the primary BM regime, then considers nearby legal candidates when the estimated last CTA wave is poorly utilized.
Implementation
The new selector is enabled only when all of the following are true:
num_experts > 0GemmType.INDEXEDLegal BM candidates are generated dynamically as 8-row-aligned values from 8 through the active
max_block_m, while retaining the existing dtype-specific legality constraints.The primary BM target is derived from:
For workloads above
max_block_m, the selector estimates the minimum number of M tiles required per expert and chooses a compact BM that preserves that tile count. A local candidate window is then evaluated using estimated CTA-wave utilization and padding.For the validated W4A8
get_config2path:BN=128is unchanged.BKis intentionally derived from the BM selected by the existing heuristic, so this change does not introduce a new K-reduction configuration.num_stages=4is unchanged.The selector is integrated into the current SM90 candidate-based tuning structure and uses the existing candidate legality/resource checks.
The experimental runtime switch used during development has been removed. The new selector is the default behavior for the eligible path.
Performance
Measured on an NVIDIA H100 80GB (SM90) using GLM-5.2-style indexed MoE shapes:
K=6144, N=4096K=2048, N=6144E=256,top_k=8Routed Mdenotes post-top-k routed rows. Withtop_k=8, the corresponding input-token count isrouted_m / 8.Routing is deterministic and evenly distributed across 256 experts for the reported cases.
The standalone kernel benchmark uses GEMM-only CUDA-event timing. Weight preparation, activation quantization, setup, JIT compilation, and warmup are outside the measured interval.
The A/B comparison uses separate source checkouts and subprocesses:
main/ Refactor SM90 tuning around bounded schedule candidates #59 at8611853cbf60cab5abf1f1c01fd96c8f85f9315b660444371df022fe8e153bb53b4449eb3c1ade09No forced-BM oracle or production environment switch is used.
Across the 8 latest-main standalone GEMM cases:
The gains increase with routed M, reaching about 19% at routed M=8192 and 71-82% at routed M=16384 for the tested W13/W2 shapes.
A reverse-order check on the two smallest W13 cases reproduced the gains at approximately:
This check was run with the PR checkout first and the upstream checkout second, and supports that the small-M gains are not explained by fixed benchmark execution order.
A standalone fused MoE wrapper benchmark covering W13, activation, W2, and combine reported:
Geometric mean fused-MoE speedup: +21.27%, with no regressions across the four tested routed-M values.
The fused wrapper includes activation quantization inside the timed path, unlike the standalone GEMM-only benchmark.
This is an operator-level benchmark, not a model-level end-to-end benchmark.
Correctness
Current-head correctness validation used:
8611853cbf60cab5abf1f1c01fd96c8f85f9315b660444371df022fe8e153bb53b4449eb3c1ade09GemmType.INDEXEDrtol=0.02atol=2.0The same 8 W13/W2 shapes used in the standalone performance table were validated:
Summary:
The baseline logical output is used as the reference. BM-specific padded routing metadata is regenerated independently for each checkout, and only the final logical routed output is compared.
The fused MoE wrapper validation also passed at routed-M values:
Repository tests additionally cover:
Validation
Targeted tests:
The targeted tests passed on an H100/SM90 environment.
Additional checks:
Scope
This change is limited to the SM90 indexed MoE path with:
num_experts > 0The change does not modify: