Fix SkipSimplifiedLayerNormalization fallback output arity - #387
Merged
Conversation
The standard-ONNX fallback body for com.microsoft::SkipSimplifiedLayer-
Normalization 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 output(0), mean(1), inv_std_var(2) and
input_skip_bias_sum(3), and the fusion rule in rewrite_rules/_skip_norm.py
emits a 4-output node and reads outputs[3] for the residual.
When InlinePass expands that 4-output node using the 2-output fallback,
onnx_ir's replace_all_uses_with raises ValueError ("number of values and
replacements must match") because the residual at index 3 has no
replacement; even without the guard, the sum would wrongly land in the
optional mean slot at index 1.
Emit four outputs with the sum at index 3. mean and inv_std_var are
training-only outputs that the RMS (simplified) variant does not compute
and that single-output RMSNormalization cannot supply, so they are unused
Constant placeholders (pruned by RemoveUnusedNodesPass right after inline).
Verified: onnx-standard inlining now succeeds with no dangling values and
produces byte-identical logits to the native op (max abs diff 0.0) on a
tiny Qwen2 model.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <11205048+justinchuby@users.noreply.github.com>
Performance Comparison
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a spec-conformance bug in the standard-ONNX fallback for com.microsoft::SkipSimplifiedLayerNormalization so that inlining a fused 4-output node correctly reconnects the residual output (input_skip_bias_sum) at positional output index 3.
Changes:
- Update
skip_simplified_layer_normalization()fallback body to return 4 outputs in spec order, using placeholders for the training-only outputs (mean / inv_std_var). - Add regression tests to assert correct output arity/order and to ensure
InlinePasscan inline fused skip-norm nodes without leaving dangling graph references.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/mobius/functions/skip_layer_normalization.py |
Adjusts the SkipSimplified fallback function signature to 4 outputs and documents the positional output contract. |
src/mobius/functions/skip_layer_normalization_test.py |
Adds unit/regression coverage for output arity/order and InlinePass inlining behavior (residual output wiring). |
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.
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:
output(normalized)mean(optional, training)inv_std_var(optional, training)input_skip_bias_sum(residual)The fusion rule in
rewrite_rules/_skip_norm.pyis already spec-correct — it emits a 4-output node and readsoutputs[3]for the residual. But whenInlinePassexpands that 4-output node using the 2-output fallback,onnx_ir.convenience.replace_all_uses_withraises:because the residual at index 3 has no replacement value. Even without that guard, the sum would silently land in the optional
meanslot 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.
meanandinv_std_varare training-only outputs that the simplified (RMS) variant does not compute and that single-outputRMSNormalizationcannot supply, so they are emitted as unusedConstantplaceholders and pruned byRemoveUnusedNodesPassimmediately after the function is inlined.Verification
InlinePasson a tiny Qwen2 model (onnx-standardEP) now expands all fused ops with no dangling values; the placeholderConstants are DCE'd.0.0).functions/skip_layer_normalization_test.py(output-arity + inline-residual regression tests).