Add mixed-width weight contract for QMoE - #32697
Open
David Fan (jiafatom) wants to merge 6 commits into
Open
David Fan (jiafatom) wants to merge 6 commits into
David Fan (jiafatom) wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
CUDA returns the wrong status in some paths, generated schema documentation is stale, and provider-specific coverage is incomplete.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 3
Open (4)
What changed in this PR
Adds mixed-width QMoE weight metadata and validation while deferring execution support.
Changes:
- Adds per-FC bit-width attributes and shape validation.
- Wires effective widths through CPU, CUDA, and WebGPU.
- Adds CPU contract tests and rejects mixed-width execution.
| File | Description |
|---|---|
onnxruntime/test/contrib_ops/moe_test.cc |
Adds mixed-width CPU tests. |
onnxruntime/core/graph/contrib_ops/contrib_defs.cc |
Extends the QMoE schema. |
onnxruntime/contrib_ops/webgpu/moe/qmoe.h |
Parses per-FC widths. |
onnxruntime/contrib_ops/webgpu/moe/qmoe.cc |
Validates and rejects mixed-width execution. |
onnxruntime/contrib_ops/cuda/moe/moe_quantization.h |
Stores per-FC widths. |
onnxruntime/contrib_ops/cuda/moe/moe_quantization.cc |
Adds CUDA validation and prepack bypass. |
onnxruntime/contrib_ops/cpu/moe/moe_quantization_cpu.h |
Stores per-FC widths. |
onnxruntime/contrib_ops/cpu/moe/moe_quantization_cpu.cc |
Adds CPU validation and prepack bypass. |
onnxruntime/contrib_ops/cpu/moe/moe_helper.h |
Supports FC-specific packing dimensions. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Tianlei Wu (tianleiwu)
left a comment
Contributor
There was a problem hiding this comment.
The FC-specific validation and provider rejection paths are coherent for this contract-only change. I left two non-blocking inline comments where the public contract and its regression coverage can be tightened.
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
Add the schema and validation contract needed for mixed-width QMoE expert weights.
fc1_expert_weight_bits,fc2_expert_weight_bits, andfc3_expert_weight_bitsattributes, inheriting fromexpert_weight_bitswhen omitted.logical_elements * bits / 8.pack_sizehelper overloads and existing 2/4/8 validation diagnostics.NOT_IMPLEMENTEDstatus for mixed-width execution. Execution support will follow separately.Attribute semantics
expert_weight_bitsremains the legacy global value and the fallback for each optional projection override:If an override is omitted, it is never left uninitialized: it inherits
expert_weight_bits, whose schema default is 4. If all three overrides are present, each override takes precedence for its corresponding projection. All effective values are currently restricted to 2, 4, or 8 bits. Fused SwiGLU additionally requires effective FC1 and FC3 widths to match.Examples:
expert=4, no overrides -> effective widths(4, 4, 4), existing uniform 4-bit path.expert=4,fc1=2,fc2=4,fc3=2-> effective widths(2, 4, 2), mixed-width contract path.expert=4,fc1=2,fc2=2,fc3=2-> effective widths(2, 2, 2), but currently still treated as an override/mixed configuration because the effective widths differ from the legacy global value.expert_weight_bits=2and omit the overrides.Current execution boundary
For this contract-only change,
is_mixed_widthmeans that at least one effective projection width differs fromexpert_weight_bits:This intentionally rejects even
expert=4, fc1=2, fc2=2, fc3=2. Shape and zero-point validation use the effective 2-bit widths, while the existing execution and dispatch paths still use the legacy global width. Allowing execution in that state could interpret 2-bit data as 4-bit data. The explicit rejection prevents silent incorrect results.Follow-up execution support must make prepacking, scale/zero-point interpretation, packed layouts, workspace sizing, and kernel dispatch projection-aware. Once dispatch consumes effective widths, uniformly overridden configurations can be normalized to one effective width, while genuinely mixed configurations can dispatch FC1/FC2/FC3 independently.
Testing
onnxruntime_provider_testwith CUDA enabled.Related to #32657.