[AIMIGRAPHX-1002] Match nop reshapes with broadcasted inputs#4841
[AIMIGRAPHX-1002] Match nop reshapes with broadcasted inputs#4841eddieliao wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Updates simplify_reshapes matching so that reductions over size-1 axes on broadcasted inputs can be recognized as no-ops even when input/output strides differ (fixing cases like broadcast -> reduce_mean where the reduce gets optimized away incorrectly in downstream fusion scenarios).
Changes:
- Split the “nop reshape” matcher into shape-equality vs lens-equality cases, using lens-only matching for
reduce_*ops. - Add a new matcher combinator
match::same_lens(...)to support lens-only equivalence checks. - Add a regression test covering
broadcast -> reduce_meanas a nop-reduction case.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
test/simplify_reshapes_test.cpp |
Adds regression test ensuring a nop reduce_mean over a size-1 broadcast axis is eliminated. |
src/simplify_reshapes.cpp |
Updates nop-reshape matching to use full-shape equality for reshape-like ops and lens-only equality for reduce_*. |
src/include/migraphx/matcher.hpp |
Introduces same_lens matcher utility used by simplify_reshapes. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #4841 +/- ##
===========================================
+ Coverage 92.80% 92.85% +0.05%
===========================================
Files 584 584
Lines 30146 30159 +13
===========================================
+ Hits 27976 28003 +27
+ Misses 2170 2156 -14
🚀 New features to boost your workflow:
|
shivadbhavsar
left a comment
There was a problem hiding this comment.
The core issue to me sounds like the reduce compute_shape methods are not preserving broadcast strides. Is there a potential fix there instead of changing the noop condition in this matcher?
Co-authored-by: Paul Fultz II <paul.fultz@amd.com>
|
Rekicked due to CI internal issue |
Motivation
bcast → reduce_mean over axis of size 1 currently fails as the reduce op inside fused_reduce gets optimized out, leaving an submodule with no reduce ins
Technical Details
The matcher for simplify_reshapes needs to be updated to account for such cases in which the strides may not match, but the result is still a nop.
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot Applicable