[CUDA] QMoE support shared experts - #29028
Draft
Tianlei Wu (tianleiwu) wants to merge 7 commits into
Draft
Tianlei Wu (tianleiwu) wants to merge 7 commits into
Tianlei Wu (tianleiwu) wants to merge 7 commits into
Conversation
Tianlei Wu (tianleiwu)
marked this pull request as draft
June 12, 2026 08:31
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the CUDA MoE/QMoE contrib ops to support Qwen3-style always-on shared experts via a new num_shared_experts attribute, where the last num_shared_experts expert slots are always selected and weighted by a per-token sigmoid gate (excluded from routed softmax/top-k/normalization).
Changes:
- Adds
num_shared_expertsto theMoEandQMoEoperator schemas and documents the fused shared-expert semantics. - Updates CUDA routing (Softmax+TopK) kernels and CUDA
MoE/QMoEexecution to size per-token selection buffers fork_total = k + num_shared_expertsand append shared experts with sigmoid-gated weights. - Adds CUDA parity tests validating fused shared-expert behavior for both fp32
MoEand INT4-fp16QMoE.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/test/python/transformers/test_moe_shared_expert_cuda.py | New parity tests comparing fused shared-expert outputs vs routed-only + isolated shared-expert reference composition. |
| onnxruntime/core/graph/contrib_ops/contrib_defs.cc | Adds num_shared_experts attribute (with semantics) to MoE and QMoE schemas. |
| onnxruntime/contrib_ops/cuda/moe/qmoe_kernels.h | Extends LaunchSoftmaxTopK API to accept num_shared_experts. |
| onnxruntime/contrib_ops/cuda/moe/qmoe_kernels.cu | Implements shared-expert routing behavior by sorting only routed experts and appending shared experts with sigmoid gates. |
| onnxruntime/contrib_ops/cuda/moe/moe.cc | Updates CUDA MoE to allocate/operate with k_total selection slots and pass num_shared_experts into routing. |
| onnxruntime/contrib_ops/cuda/moe/moe_quantization.cc | Updates CUDA QMoE similarly to use k_total and pass num_shared_experts into routing. |
| onnxruntime/contrib_ops/cuda/moe/moe_base.h | Parses/validates num_shared_experts (and disallows with use_sparse_mixer). |
| docs/contrib_ops/cuda/moe_qmoe.md | Documents num_shared_experts and adds a dedicated “Shared-Expert Fusion” section and test reference. |
This branch has not been deployed
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
Extend QMoE to support Qwen 3.5/3.6 style shared experts.
Limitation: The intermediate hidden size shall be same among all experts.