Repository navigation
[CUDA][QMoE] Wire LaunchFusedRouteMaps into CutlassMoeFCRunner for S<=8 and E<=512 - #33596
Conversation
…-expert routing Extend isFusedMoeRoutingSupported and launchFusedRoutingBuildExpertMaps in moe_kernels.cu to dispatch to onnxruntime::cuda::LaunchFusedRouteMaps (FusedSoftmaxTopKMapsKernel) when CanUseFusedRouteMaps(num_tokens, num_experts, experts_per_token) holds (e.g. num_tokens <= 8, num_experts <= 512, experts_per_token <= 16 for FP16/BF16 router logits), while preserving the single-warp fusedRoutingBuildExpertMapsSingleTokenKernel fast path for num_tokens == 1 && num_experts <= 32. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The eligibility helper is undefined, the launcher call is incompatible with the existing API, and the new path lacks regression coverage.
3 open issues
What changed in this PR
This PR aims to reduce CUDA INT4 QMoE routing overhead by integrating fused routing and expert-map generation into CutlassMoeFCRunner for small token batches and larger expert counts.
Changes:
- Extends fused-routing eligibility beyond the existing single-token, ≤32-expert path.
- Adds FP16/BF16 dispatch to
LaunchFusedRouteMaps, while preserving the existing small-expert kernel. - Passes the token count into the routing launcher.
| File | Description |
|---|---|
onnxruntime/contrib_ops/cuda/llm/moe_gemm/moe_kernels.cu |
Extends routing eligibility and connects the runner to fused route-map generation. |
Review effort: Balanced
…l and fallback, and add tests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
kunal-vaishnavi
left a comment
There was a problem hiding this comment.
From Copilot:
Completed an implementation pass and a second edge-case/regression pass at 3290281. No actionable finding.
Checked architecture/alignment rejection, float-logit fallback, expert-map ordering and permutation conventions, routing-weight normalization, expert-parallel eligibility, and routing-snapshot timing. A declined fused launch explicitly computes softmax/top-k before the standard expert-map prologue, rather than leaving the caller's routing buffers uninitialized. Existing map/output-scale tests were inspected.
Validation: source and existing-test review only for this PR. No PR-specific ORT build, provider/Python suite execution, cross-architecture qualification, or performance benchmark was performed. This is a source-review outcome, not a formal approval or a claim that all tests and CI passed.


Description
isFusedMoeRoutingSupportedinonnxruntime/contrib_ops/cuda/llm/moe_gemm/moe_kernels.cuto queryonnxruntime::cuda::CanUseFusedRouteMaps(num_tokens, num_experts, experts_per_token)when(num_tokens == 1 && num_experts <= 32)does not apply.launchFusedRoutingBuildExpertMapsto dispatch toonnxruntime::cuda::LaunchFusedRouteMaps<T>(FusedSoftmaxTopKMapsKernel) forhalfand__nv_bfloat16router logits whennum_tokens > 1ornum_experts > 32, while preservingfusedRoutingBuildExpertMapsSingleTokenKernelfornum_tokens == 1 && num_experts <= 32.Motivation and Context
FusedSoftmaxTopKMapsKernel(LaunchFusedRouteMapsinqmoe_fused_route.cuh) was already used by the INT2/INT3 fast path inmoe_quantization.ccfor1 <= num_tokens <= 8,64 <= num_experts <= 512,experts_per_token <= 16, butisFusedMoeRoutingSupportedinmoe_kernels.cuonly allowednum_tokens == 1 && num_experts <= 32.num_experts = 512and speculative verification batches (S = 8) fell back to two separate kernel launches per layer (SoftmaxTopKMergeKernel+fusedBuildExpertMapsSortFirstToken,~9.0 µs/layer).LaunchFusedRouteMapsintoCutlassMoeFCRunnerreplaces both launches with a single-CTAFusedSoftmaxTopKMapsKernel(4.31 µs/layeron H200 atS = 8, E = 512, K = 10), eliminating 1 kernel launch and~4.7 µsper INT4 MoE layer (48launches /~0.22 msper 48-layer decode cycle).