Skip to content

Commit 8f24714

Browse files
titaiwangmsCopilot
andcommitted
Clarify MoE reference precision and runtime qualification
Separate lowered graph structure from native runtime evidence, distinguish supported ABI from verified native execution, and disclose near-tie Softmax and platform-specific half-GEMM limitations raised during review. Clarify that lowering arithmetic and constants use FLOAT; no execution behavior changes. Co-authored-by: Copilot <[email protected]> Signed-off-by: titaiwangms <[email protected]>
1 parent 8e49f1c commit 8f24714

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

‎docs/moe-lowering.md‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ MoELayer dispatch/fallbacks, configuration, or checkpoint loading.
1919

2020
This replaces `com.microsoft::MoE` with two standard `GroupedMatMul-29` calls,
2121
targeting the pinned **CPU reference**, not all execution providers. It requires
22-
ONNX opset-29 schemas and a qualified runtime. ORT 1.31.1 cannot execute these
22+
ONNX opset-29 schemas and a runtime implementing them. ORT 1.31.1 cannot execute these
2323
graphs directly; tests expand GroupedMatMul on a test copy at opset 24. There is
2424
no production expansion or performance/memory-use promise.
2525

26-
## Qualified ABI
26+
## Supported ABI
2727

2828
* Input 0: FLOAT or FLOAT16 hidden states `[T,H]` or `[B,S,H]`, positive static
2929
H. Dynamic token axes and empty token dimensions are supported; `T=B*S`.
@@ -79,7 +79,19 @@ from QMoE's FLOAT-through-both-GEMMs behavior. CPU thread/expert accumulation
7979
order and math-library implementations may differ; bitwise equality is not
8080
claimed.
8181

82-
### Native runtime qualification
82+
This defines a FLOAT-accumulation reference, not parity with every
83+
platform-specific MLAS half-GEMM kernel. Near a top-k boundary, different Softmax
84+
implementations may round probabilities differently and select different experts.
85+
The higher-ID tie rule applies to equal probabilities produced by the graph.
86+
87+
The first GMM maps `[T,H]` to `[T,k,N]`; activation produces `[T,k,I]`.
88+
The second GMM consumes `[T*k,I]` and expert indices `[T*k,1]`, then reshapes
89+
to `[T,k,H]`. After optional bias2, route weighting, and reduction, the result
90+
is restored using `Shape(X)` with `allowzero=1`, including empty rank-3 axes.
91+
Original initializer names and input/output names, shape/type, documentation,
92+
and output metadata are preserved.
93+
94+
## Native runtime qualification
8395

8496
The tested ORT **1.31.1** wheel reports build commit
8597
`6af1a932e2286d5c58166085d24c68783033edee`. Its CPU MoE kernel registration
@@ -104,19 +116,12 @@ instead correctly copies whenever input and output buffers alias.
104116
Native parity tests inspect the CPU kernel's **actual T dtype constraint**
105117
and explicitly skip unsupported dtypes, rather than accepting automatic
106118
FLOAT fallback or marking discrepancies as expected failures. FLOAT native
107-
comparisons remain active. FLOAT16 qualification in this environment rests on
119+
comparisons remain active. FLOAT16 verification here is reference-based, using
108120
the pinned CPU source and independent rounded-stage NumPy reference, with
109121
test-copy GroupedMatMul expansion; every independent FLOAT16 test remains
110122
active, including the proof that intermediate half rounding is observable.
111123
This is not a claim of native-half parity against the 1.31.1 wheel.
112124

113-
The first GMM maps `[T,H]` to `[T,k,N]`; activation produces `[T,k,I]`.
114-
The second GMM consumes `[T*k,I]` and expert indices `[T*k,1]`, then reshapes
115-
to `[T,k,H]`. After optional bias2, route weighting, and reduction, the result
116-
is restored using `Shape(X)` with `allowzero=1`, including empty rank-3 axes.
117-
Original initializer names and input/output names, shape/type, documentation,
118-
and output metadata are preserved.
119-
120125
## Atomicity and import alignment
121126

122127
All target calls, all existing scopes, and every detached replacement are

‎src/mobius/functions/moe.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def _lower(node: ir.Node, c: _Config, prefix: str) -> tuple[list[ir.Node], ir.Va
172172
assert x is not None and router is not None and w1 is not None and w2 is not None
173173
half = x.dtype == ir.DataType.FLOAT16
174174

175+
# Arithmetic and scalar constants are FLOAT; half storage is modeled explicitly.
175176
def compute(value: ir.Value) -> ir.Value:
176177
return e.op("Cast", value, to=ir.DataType.FLOAT) if half else value
177178

0 commit comments

Comments
 (0)