Commit 095d1e5
Fix SkipSimplifiedLayerNormalization fallback output arity (#387)
## Problem
The standard-ONNX fallback body for
`com.microsoft::SkipSimplifiedLayerNormalization`
(`functions/skip_layer_normalization.py`) returned only **two** outputs,
`[norm_out, add_out]`, placing the residual sum (`input_skip_bias_sum`)
at **index 1**.
Per the operator spec the four positional outputs are:
| idx | output |
|-----|--------|
| 0 | `output` (normalized) |
| 1 | `mean` (optional, training) |
| 2 | `inv_std_var` (optional, training) |
| 3 | `input_skip_bias_sum` (residual) |
The fusion rule in `rewrite_rules/_skip_norm.py` is already spec-correct
— it emits a **4-output** node and reads `outputs[3]` for the residual.
But when `InlinePass` expands that 4-output node using the 2-output
fallback, `onnx_ir.convenience.replace_all_uses_with` raises:
```
ValueError: The number of values and replacements must match.
```
because the residual at index 3 has no replacement value. Even without
that guard, the sum would silently land in the optional `mean` slot at
index 1.
### Reachability
Fusion is gated on `supports_skip_layer_norm` (`_optimizations.py`), so
EPs that would inline this op (`onnx-standard`, `qnn`, `trt-rtx`) don't
create the node in a normal single-EP pass — the crash only surfaces on
a fuse-then-re-optimize path. It is nonetheless a real spec-conformance
bug in the fallback body.
## Fix
Emit four outputs with the residual sum at index 3. `mean` and
`inv_std_var` are training-only outputs that the simplified (RMS)
variant does not compute and that single-output `RMSNormalization`
cannot supply, so they are emitted as unused `Constant` placeholders and
pruned by `RemoveUnusedNodesPass` immediately after the function is
inlined.
## Verification
- `InlinePass` on a tiny Qwen2 model (`onnx-standard` EP) now expands
all fused ops with **no dangling values**; the placeholder `Constant`s
are DCE'd.
- Inlined fallback produces **byte-identical logits** to the native op
(max abs diff `0.0`).
- New `functions/skip_layer_normalization_test.py` (output-arity +
inline-residual regression tests).
- Existing skip-norm and EP-optimization suites pass; lint clean.
Signed-off-by: Justin Chu <11205048+justinchuby@users.noreply.github.com>
Co-authored-by: Justin Chu <11205048+justinchuby@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 1f04e6b commit 095d1e5
2 files changed
Lines changed: 138 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
99 | 111 | | |
100 | 112 | | |
101 | 113 | | |
| |||
110 | 122 | | |
111 | 123 | | |
112 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
113 | 130 | | |
| 131 | + | |
| 132 | + | |
114 | 133 | | |
115 | | - | |
| 134 | + | |
116 | 135 | | |
117 | 136 | | |
118 | 137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
0 commit comments