[Rewriter]: add fusion rules for successive Min/Max patterns#2500
[Rewriter]: add fusion rules for successive Min/Max patterns#2500justinchuby merged 5 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements fusion rules for successive Min/Max patterns in the ONNX rewriter. The PR adds optimizations to simplify chains of Min/Max operations by collapsing redundant operations and converting specific patterns to more efficient Clip operations.
- Adds fusion of successive Min operations: Min(Min(X)) -> Min(X)
- Adds fusion of successive Max operations: Max(Max(X)) -> Max(X)
- Adds conversion of Min(Max(X)) and Max(Min(X)) patterns to Clip operations
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| onnxscript/rewriter/min_max_to_clip.py | Implements the core rewrite rules with abstract base class and concrete fusion implementations |
| onnxscript/rewriter/min_max_to_clip_test.py | Comprehensive test suite covering successful fusion cases and failure conditions |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2500 +/- ##
==========================================
+ Coverage 69.99% 70.17% +0.18%
==========================================
Files 216 218 +2
Lines 26074 26248 +174
Branches 2618 2625 +7
==========================================
+ Hits 18250 18420 +170
- Misses 6921 6923 +2
- Partials 903 905 +2 ☔ View full report in Codecov by Sentry. |
|
Thanks! I think we can enable these patterns by default. Could you share on what models these patterns will appear? |
c21bb05 to
28105cc
Compare
|
I think the rules are reasonable. I will look at them more closely |
gramalingam
left a comment
There was a problem hiding this comment.
LGTM ... had just a couple of minor comments/suggestions. Thanks!
28105cc to
717fa45
Compare
- Min(Min(X)) -> Min(X) - Max(Max(X)) -> Max(X) - Min(Max(X)) -> Clip(X) - Max(Min(X)) -> Clip(X)
717fa45 to
e2125dc
Compare

This PR adds the following transformation: