Repository navigation
Validate MoE hidden dimensions - #33820
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The QMoE test’s float32 scales are incompatible with its FP16 kernel, preventing it from reaching the intended validation, and the new zero-inter_size guard lacks regression coverage.
2 open issues
What changed in this PR
This PR strengthens dimension validation in ONNX Runtime’s MoE input helper and adds CPU tests for invalid dimensions and empty inputs.
Changes:
- Reject non-positive
hidden_sizeandinter_size. - Add zero-hidden-size rejection cases for MoE and QMoE.
- Verify that MoE still supports zero rows with a positive hidden size.
| File | Description |
|---|---|
onnxruntime/test/contrib_ops/moe_test.cc |
Adds CPU rejection and empty-input regression tests. |
onnxruntime/contrib_ops/cpu/moe/moe_helper.h |
Adds positive hidden and intermediate dimension checks. |
Review effort: Balanced
Ti-Tai Wang (titaiwangms)
left a comment
There was a problem hiding this comment.
No blocking issues found in a bounded static review of the diff, shared input validation, direct CPU MoE/QMoE consumers, and added tests. The hidden-size guard is before the intermediate-size modulo/division, and the tests distinguish zero hidden/intermediate dimensions from the supported zero-row case.
Validation scope: static inspection only; I did not build or run the tests or sanitizers.


This pull request strengthens input validation for the Mixture-of-Experts (MoE) operator on CPU by ensuring that the
hidden_sizeandinter_sizeparameters are positive. It also adds new unit tests to verify that invalid input shapes are correctly rejected and that valid, but edge-case, inputs remain supported.Input Validation Improvements
moe_helper.hto ensure thathidden_sizeis positive; otherwise, an error is returned.moe_helper.hto ensure thatinter_sizeis positive; otherwise, an error is returned.Unit Test Additions
ZeroHiddenSizeRejectedOnCPUtest inmoe_test.ccto verify that MoE and QMoE operators reject inputs with zerohidden_size.ZeroRowsWithPositiveHiddenSizeRemainsSupportedOnCPUtest inmoe_test.ccto confirm that inputs with zero rows and positivehidden_sizeare still supported.