Group_topk: moe_fused_gate support num expert is not power of 2#2604
Merged
Group_topk: moe_fused_gate support num expert is not power of 2#2604
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
ebf320d to
3b15019
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to extend the MoE fused gating/top-k path to handle non-power-of-two expert counts by relaxing prior constraints and adding specialized dispatch configurations, and updates the Python wrapper to rely less on the previous “power-of-2 experts only” limitation.
Changes:
- Relaxed
moe_fused_gate’s host-side “num_experts must be power-of-2” constraint and added tuned specializations fornum_experts= 192 and 96. - Adjusted
moe_fused_gate_implloading logic to use scalar loads for dynamic params and vector loads for static params. - Updated
biased_grouped_topkrouting logic to no longer force a fallback for non-power-of-two expert counts.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
csrc/kernels/moe_fused_gate.cu |
Adds new expert-count specializations, changes input/bias loading strategy, and introduces a HIP device guard; removes (comments out) the power-of-2 check. |
aiter/ops/topk.py |
Updates wrapper routing logic to use moe_fused_gate without checking num_experts power-of-2; updates copyright year. |
Comments suppressed due to low confidence (1)
csrc/kernels/moe_fused_gate.cu:581
- The comment above the divisibility check is incorrect:
num_experts % num_expert_group == 0does not implynum_expert_groupis a power of 2. Also,multithread_reduce(..., thread_num)in hip_reduce.h only has explicit implementations for thread_num in {1,2,4,8,16,32}, so non-power-of-twonum_expert_groupwill fall through and produce incorrect results. Please add aTORCH_CHECKthatnum_expert_groupis a supported power-of-two (and ideally <= 32), and update/remove the misleading comment.
// Check 2: Ensure that num_experts is divisible by num_expert_group. (this also means
// num_expert_group is power of 2)
TORCH_CHECK(num_experts % num_expert_group == 0,
"num_experts must be divisible by num_expert_group, but got ",
num_experts,
" / ",
num_expert_group);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
valarLip
approved these changes
Apr 3, 2026
3 tasks
yzhou103
pushed a commit
that referenced
this pull request
Apr 8, 2026
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.
test on MI308:


Motivation
Technical Details
Test Plan
Test Result
Submission Checklist