onnxruntime
dc1ae7a1 - Skip MatMul BatchNormalization fusion when the channel axis moves (#33392)

Commit
9 days ago
Skip MatMul BatchNormalization fusion when the channel axis moves (#33392) ### Description Skip `MatmulBNFusion` unless the Reshape and Transpose nodes between MatMul and BatchNormalization keep the MatMul output columns on the BatchNormalization channel axis. The check follows the column axis through each node's inferred output shape, and skips the fusion if a shape is unknown. Add a test for the Reshape from #33364 and for a Reshape that keeps the channels, comparing against the unfused graph. `FuseMatmulBNWithOnlyReshape` and `FuseMatmulBNWithOnlyTranspose` now expect no fusion. Their models fail without optimizations (`Invalid input scale: 0th dimension != 1`), since the channel axis has size 1 and scale has 5 values. ### Motivation and Context The fusion scales column j of the MatMul weight by channel j of the BatchNormalization. A Reshape such as [2, 4] -> [1, 4, 2, 1] moves the columns off the channel axis, so the Basic, Extended and All levels returned wrong values. Fixes #33364. ### Validation Linux aarch64 CPU, Release build: - The new test fails before the change and passes after it. - `GraphTransformationTests.*`: 430 passed, 18 skipped (17 CUDA/WebGPU-only, 1 FP16 fallback test skipped on this CPU). - The repro from #33364 matches the expected output at every optimization level. - clang-format 20.1.8 and `git diff --check` pass.
Author
Parents
Loading