Annotate moe_sorting_dispatch_policy as int for fused_moe#2639
Merged
Annotate moe_sorting_dispatch_policy as int for fused_moe#2639
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
5 tasks
tpopp
added a commit
to amdsiloai/aiter
that referenced
this pull request
Apr 9, 2026
Fix type annotation so PyTorch custom op schema doesn't silently coerce values like 2 to bool(2)==1. Signed-off-by: Tres Popp <tres.popp@amd.com> Made-with: Cursor
The type annotation bool was incorrect for moe_sorting_dispatch_policy, which accepts int values. The @torch_compile_guard decorator uses these annotations to generate PyTorch custom op schemas; with bool, PyTorch schema enforcement casts any value to bool, so dispatch_policy=2 becomes bool(2)=True (1), silently losing the intended policy. Using int allows callers to set dispatch_policy=2 correctly. Fixes: ROCm#2576 Signed-off-by: Tres Popp <tres.popp@amd.com>
adc6a2a to
83c358d
Compare
valarLip
approved these changes
Apr 16, 2026
Zzz9990
pushed a commit
that referenced
this pull request
Apr 16, 2026
The type annotation bool was incorrect for moe_sorting_dispatch_policy, which accepts int values. The @torch_compile_guard decorator uses these annotations to generate PyTorch custom op schemas; with bool, PyTorch schema enforcement casts any value to bool, so dispatch_policy=2 becomes bool(2)=True (1), silently losing the intended policy. Using int allows callers to set dispatch_policy=2 correctly. Fixes: #2576 Signed-off-by: Tres Popp <tres.popp@amd.com> Co-authored-by: Tres Popp <tres.popp@amd.com>
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.
Motivation
The type annotation bool was incorrect for moe_sorting_dispatch_policy, which accepts int values. The @torch_compile_guard decorator uses these annotations to generate PyTorch custom op schemas; with bool, PyTorch schema enforcement casts any value to bool, so dispatch_policy=2 becomes bool(2)=True (1), silently losing the intended policy. Using int allows callers to set dispatch_policy=2 correctly.
Fixes: #2576
Technical Details
2-line change in aiter/fused_moe.py:
Line 191: moe_sorting_dispatch_policy: bool = 0 → int = 0 (in fused_moe_fake)
Line 225: moe_sorting_dispatch_policy: bool = 0 → int = 0 (in fused_moe_)
Will be followed up by vLLM change to enable user to set the policy.
Test Plan
Test Result
No accuracy regression. Modest throughput improvement from correct dispatch policy.
Submission Checklist