Skip to content

Validate MoE hidden dimensions - #33820

Merged
Akshay Sonawane (apsonawane) merged 3 commits into
mainfrom
fix/moe-hidden-size-validation
Nov 3, 2026
Merged

Akshay Sonawane (apsonawane) merged 3 commits into
mainfrom
fix/moe-hidden-size-validation

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request strengthens input validation for the Mixture-of-Experts (MoE) operator on CPU by ensuring that the hidden_size and inter_size parameters 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

  • Added a check in moe_helper.h to ensure that hidden_size is positive; otherwise, an error is returned.
  • Added a check in moe_helper.h to ensure that inter_size is positive; otherwise, an error is returned.

Unit Test Additions

  • Added ZeroHiddenSizeRejectedOnCPU test in moe_test.cc to verify that MoE and QMoE operators reject inputs with zero hidden_size.
  • Added ZeroRowsWithPositiveHiddenSizeRemainsSupportedOnCPU test in moe_test.cc to confirm that inputs with zero rows and positive hidden_size are still supported.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_size and inter_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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the CPU MoE input-validation changes.

No open issues 🎉

2 resolved since last review

Review effort: Max

@titaiwangms Ti-Tai Wang (titaiwangms) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@apsonawane
Akshay Sonawane (apsonawane) merged commit 84e45d9 into main Nov 3, 2026
95 of 98 checks passed
@apsonawane
Akshay Sonawane (apsonawane) deleted the fix/moe-hidden-size-validation branch November 3, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants