[pass] Remove unused initialized inputs in DCE#2212
[pass] Remove unused initialized inputs in DCE#2212justinchuby merged 30 commits intomicrosoft:mainfrom
Conversation
Let's affect only inputs that are initializers
|
Looks good to me, thanks! Maybe create an option in the initializer so users can control? |
[::-1]->reversed
trailing spaces remove
May be. There are three alternatives: How about parameter |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2212 +/- ##
==========================================
+ Coverage 73.60% 73.62% +0.02%
==========================================
Files 227 227
Lines 29052 29080 +28
Branches 3327 3330 +3
==========================================
+ Hits 21383 21411 +28
Misses 6544 6544
Partials 1125 1125 ☔ View full report in Codecov by Sentry. |
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
|
I think option three (remove unused inputs-initializers) is a good balance between correctness and user expectation. It sounds like a good idea to default it to True. |
|
Maybe call the option |
RemoveUnusedNodesPass + parameter remove_initialized_inputs
remove_unused_noodles + parameter remove_initialized_inputs
tests for issue microsoft#2211
|
@microsoft-github-policy-service agree |
|
https://github.com/onnx/onnx/blob/baae427e70c27d740f5bea859111e3b63d33512b/onnx/onnx.proto#L72C1-L74C25 mentions initializers does not have to follow inputs. I need to think about the default behavior a little more |
After thinking about this, I suggest to keep the same logic, but default the option to False. |
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
For API compatibility!
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
|
Final round of suggestions. Thanks! |
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
parametrization
justinchuby
left a comment
There was a problem hiding this comment.
Thank you for making the contribution!
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the unused node removal functionality by introducing a configurable option to remove unused initialized inputs. Key changes include:
- Updating the optimizer’s remove_unused_nodes function to accept a new remove_initialized_inputs parameter.
- Modifying tests in unused_removal_test.py to verify that unused initializer inputs are removed when requested.
- Updating the RemoveUnusedNodesPass to conditionally remove graph inputs matching unused initializers.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| onnxscript/optimizer/init.py | Modified call signature to pass remove_initialized_inputs parameter |
| onnxscript/ir/passes/common/unused_removal_test.py | Added tests to verify removal of unused initialized inputs |
| onnxscript/ir/passes/common/unused_removal.py | Updated pass implementation to remove corresponding graph inputs |
Comments suppressed due to low confidence (1)
onnxscript/ir/passes/common/unused_removal.py:113
- [nitpick] Consider renaming the variable 'input' to avoid shadowing the built-in function 'input'.
for i, input in reversed(list(enumerate(graph_inputs))):
|
I think there is a format change required you can fix by running |
|
Errr... The above exception was the direct cause of the following exception: |
|
Those checks are fine. They are unrelated. |
|
Hurray! |
Fix #2211
This pull request enhances the functionality of the
RemoveUnusedNodesPassclass and its associated methods by introducing an option to remove unused initialized inputs. It also updates the corresponding tests to validate this new behavior. The changes improve the flexibility of the unused node removal process and ensure the model input signature remains consistent unless explicitly modified.Enhancements to
RemoveUnusedNodesPass:remove_initialized_inputsattribute to theRemoveUnusedNodesPassclass, allowing the removal of unused initialized inputs when enabled. This change modifies the model input signature if unused inputs are removed (onnxscript/ir/passes/common/unused_removal.py).