Skip to content

[CUDA][QMoE] Wire LaunchFusedRouteMaps into CutlassMoeFCRunner for S<=8 and E<=512 - #33596

Open
Tianlei Wu (tianleiwu) wants to merge 2 commits into
mainfrom
tlwu/20261025/qmoe-fused-route-maps
Open

Tianlei Wu (tianleiwu) wants to merge 2 commits into
mainfrom
tlwu/20261025/qmoe-fused-route-maps

Conversation

@tianleiwu

Copy link
Copy Markdown
Contributor

Description

  • Extend isFusedMoeRoutingSupported in onnxruntime/contrib_ops/cuda/llm/moe_gemm/moe_kernels.cu to query onnxruntime::cuda::CanUseFusedRouteMaps(num_tokens, num_experts, experts_per_token) when (num_tokens == 1 && num_experts <= 32) does not apply.
  • Update launchFusedRoutingBuildExpertMaps to dispatch to onnxruntime::cuda::LaunchFusedRouteMaps<T> (FusedSoftmaxTopKMapsKernel) for half and __nv_bfloat16 router logits when num_tokens > 1 or num_experts > 32, while preserving fusedRoutingBuildExpertMapsSingleTokenKernel for num_tokens == 1 && num_experts <= 32.

Motivation and Context

  • FusedSoftmaxTopKMapsKernel (LaunchFusedRouteMaps in qmoe_fused_route.cuh) was already used by the INT2/INT3 fast path in moe_quantization.cc for 1 <= num_tokens <= 8, 64 <= num_experts <= 512, experts_per_token <= 16, but isFusedMoeRoutingSupported in moe_kernels.cu only allowed num_tokens == 1 && num_experts <= 32.
  • Consequently, all INT4 QMoE layers with num_experts = 512 and speculative verification batches (S = 8) fell back to two separate kernel launches per layer (SoftmaxTopKMergeKernel + fusedBuildExpertMapsSortFirstToken, ~9.0 µs/layer).
  • Wiring LaunchFusedRouteMaps into CutlassMoeFCRunner replaces both launches with a single-CTA FusedSoftmaxTopKMapsKernel (4.31 µs/layer on H200 at S = 8, E = 512, K = 10), eliminating 1 kernel launch and ~4.7 µs per INT4 MoE layer (48 launches / ~0.22 ms per 48-layer decode cycle).

…-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>
Copilot AI balanced review requested due to automatic review settings October 25, 2026 23:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread onnxruntime/contrib_ops/cuda/llm/moe_gemm/moe_kernels.cu Outdated
Comment thread onnxruntime/contrib_ops/cuda/llm/moe_gemm/moe_kernels.cu Outdated
Comment thread onnxruntime/contrib_ops/cuda/llm/moe_gemm/moe_kernels.cu Outdated
…l and fallback, and add tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Architecture-dependent CUDA dispatch and fallback behavior require confirmed build and GPU validation before final approval.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants