-
Notifications
You must be signed in to change notification settings - Fork 83
Add constant folding of Split with all constant inputs #2506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add constant folding of Split with all constant inputs #2506
Conversation
Signed-off-by: Christoph Berganski <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds constant folding optimization for the Split operator when all inputs are constants, replacing them with individual Constant nodes. It also optimizes single-output Split operations by replacing them with Identity nodes.
- Implements constant folding for Split operations with all constant inputs
- Adds optimization to replace single-output Splits with Identity operations
- Includes comprehensive test coverage for both num_outputs and splits parameter variants
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
onnxscript/optimizer/_constant_folding.py | Adds the split function to handle constant folding and Identity replacement for Split operations |
onnxscript/optimizer/_constant_folding_test.py | Adds 5 test cases covering Identity replacement and constant folding scenarios |
Thank you! |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Justin Chu <[email protected]>
Co-authored-by: Copilot <[email protected]>
Note: Only add this temporarily until this is properly supported by onnxscript, see microsoft/onnxscript#2506
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @gramalingam what do you think?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2506 +/- ##
==========================================
+ Coverage 70.08% 70.13% +0.05%
==========================================
Files 215 215
Lines 25810 25938 +128
Branches 2587 2612 +25
==========================================
+ Hits 18089 18192 +103
- Misses 6823 6841 +18
- Partials 898 905 +7 ☔ View full report in Codecov by Sentry. |
Co-authored-by: Justin Chu <[email protected]>
Signed-off-by: Christoph Berganski <[email protected]>
return None | ||
|
||
|
||
@register("Split") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better, more general, solution would be to fix the restriction in the general constant-folding (this else branch) ... so the underlying evaluator evaluates the Split op ... and we just need to bind each output value to the corresponding constant value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you share what needs to be done to enable that part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iksnagreb as suggested here, we will instead fix handling for multi-output nodes. Please feel free to contribute or provide your inputs, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. What needs to be done is create an appropriate Replacement
object which wraps the list of new nodes (a list of Constant nodes like in current PR), and a list of values (which should be more or less what is returned by the reference implementation).
I realize that this is lacking even in the current PR down below ... if we don't specify the list of new values (to replace the list of old values produced by the constant-folded node), we are not going to connect these values to the consumers of the old values.
So, if we added a test-case where the outputs of Split are used subsequently (or if we test the graph outputs in the tests below actually refer to the correct split const values), we will likely find that this PR doesn't work. It stems from a limitation in the core constant-folding logic that needs to be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking for now according to reviews, thanks!
Adds constant folding of Split with all constant inputs as well as replacing single-output Splits by Identity via the registry. Also adds 5 simple test cases covering both options: Second input specifying the sizes per split as well as nearly even splits into
num_outputs
via the attribute.