Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for the com.microsoft::FusedMatMul ONNX contrib operator in MIGraphX, along with parser/verification tests and generated ONNX fixtures to validate transpose/batch-transpose/alpha behaviors.
Changes:
- Implemented a new ONNX parser for
FusedMatMulthat lowers to MIGraphX ops (transpose,dot, optionalmul) with 1-D promotion/squeeze behavior. - Added ONNX parse tests covering
transA,transB,transBatchA,transBatchB,alpha, and an invalid-rank error case. - Added a numerical verify test and updated
gen_onnx.py+ embedded.onnxmodels for the new operator.
Reviewed changes
Copilot reviewed 22 out of 25 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/onnx/parse_fused_matmul.cpp | Adds the FusedMatMul parser/lowering logic. |
| test/onnx/gen_onnx.py | Generates ONNX models for FusedMatMul test cases. |
| test/onnx/parse/fused_matmul_*.cpp | Adds parser equivalence tests for various attribute combinations and an error case. |
| test/onnx/verify/fused_matmul_verify_test.cpp | Adds numeric verification of FusedMatMul output vs gold values. |
| test/onnx/fused_matmul_*.onnx | Adds embedded ONNX fixtures used by the new tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if(s0.dynamic() or s1.dynamic()) | ||
| { | ||
| MIGRAPHX_THROW("PARSE_FUSEDMATMUL: dynamic inputs not supported"); | ||
| } | ||
|
|
There was a problem hiding this comment.
FusedMatMul currently throws on any dynamic input shapes, even though the underlying ops used here (transpose, unsqueeze, and the op-builder dot which already handles dynamic broadcasting via broadcast_for_dot) support dynamic shapes. This makes FusedMatMul unnecessarily less capable than the existing MatMul parser. Consider removing this restriction and letting dot/transpose handle dynamic shapes (or only rejecting specific unsupported dynamic cases, if any).
| if(s0.dynamic() or s1.dynamic()) | |
| { | |
| MIGRAPHX_THROW("PARSE_FUSEDMATMUL: dynamic inputs not supported"); | |
| } |
There was a problem hiding this comment.
+1
Is there an issue you run into if you just apply the same transposes, etc. for the dynamic case?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #4806 +/- ##
===========================================
- Coverage 92.49% 92.48% -0.01%
===========================================
Files 583 584 +1
Lines 29562 29628 +66
===========================================
+ Hits 27343 27400 +57
- Misses 2219 2228 +9
🚀 New features to boost your workflow:
|
Regressions detected 🔴 |
|
| // transBatchA : int, for rank-R A, permute [1, 2, ..., R-2, 0, R-1] (default 0) | ||
| // transBatchB : int, for rank-R B, permute [1, 2, ..., R-2, 0, R-1] (default 0) |
There was a problem hiding this comment.
Are we sure that this the transpose that is intended? Reading the spec I would think it's
[0, 1, 2, ..., R-1] -> [R-2, 0, 1, 2, ..., R-3, R-1]. The spec is really imprecise about it however.
| static instruction_ref apply_trans_last_two(const onnx_parser::node_info& info, | ||
| instruction_ref x) | ||
| { | ||
| auto r = x->get_shape().ndim(); |
There was a problem hiding this comment.
might be good to assert r >= 2 to help debug if this parser is modified in the future that causes a rank 1 x to sneak in here
| if(s0.dynamic() or s1.dynamic()) | ||
| { | ||
| MIGRAPHX_THROW("PARSE_FUSEDMATMUL: dynamic inputs not supported"); | ||
| } | ||
|
|
There was a problem hiding this comment.
+1
Is there an issue you run into if you just apply the same transposes, etc. for the dynamic case?
|
|
||
| return ([node], [m1, m2], [y]) | ||
|
|
||
|
|
There was a problem hiding this comment.
There seem to be a few missing scenarios for test case completeness:
- 1D tensors and tensors that need batch broadcasting
- Verify with more variations of attributes (setting transA, the transBatch attrs, etc.)
Motivation
Add fused MatMul operator
Technical Details
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot Applicable