Add fuse_consecutive_mul pass - #5
Open
take-cheeze wants to merge 1 commit into
Open
Conversation
Folds Mul(Mul(X, C1), C2) -> Mul(X, C1 * C2) when C1/C2 are constants (initializers or Constant nodes) and the inner Mul feeds only the outer one. The combined scale is materialised with numpy-style broadcasting, so the rewrite is numerically identical (X * C1 * C2 at every position). Covers e.g. PoolFormer's LayerScale, a per-channel (C,1,1) scale times a scalar factor. Conservatively limited to FLOAT/DOUBLE constants; other dtypes are left to constant folding. Registered as a default Fuse pass. Adds unit tests for the fuse cases (scalar, per-channel) and the no-fuse guards (inner multiple-use, non-constant operand) with onnxruntime numeric-equivalence checks. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V63N6PXYEgNEe1BWbKi6cU
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.
Implements the
fuse_consecutive_mulpass from thedocs/proposed_passesdesign draft. Split out of #4 so each pass is reviewed on its own.What it does
Folds
Mul(Mul(X, C1), C2) -> Mul(X, C1 * C2)whenC1/C2are constants (initializers orConstantnodes) and the innerMulfeeds only the outer one. The combined scale is materialised with numpy-style broadcasting, so the rewrite is numerically identical (X * C1 * C2at every position). Covers e.g. PoolFormer's LayerScale, exported as a per-channel(C,1,1)scale times a scalar factor. Conservatively limited toFLOAT/DOUBLEconstants; other dtypes are left to constant folding.Registered as a default
Fusepass, so it runs in the default fuse set.Tests
Adds unit tests — scalar and per-channel fuse cases, plus no-fuse guards (inner Mul with multiple uses, non-constant operand) — with onnxruntime numeric-equivalence checks.
Generated by Claude Code