-
Notifications
You must be signed in to change notification settings - Fork 72
Add add/remove initializers passes #2253
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
Conversation
Implement `RemoveInitializersFromInputsPass` and `AddInitializersToInputsPass` in `onnxscript/ir/passes/common/constant_manipulation.py`. * **RemoveInitializersFromInputsPass** - Add `RemoveInitializersFromInputsPass` class to find and remove graph inputs with `const_value`. - Implement `call` method to remove inputs with `const_value` from `graph.inputs`. - Register `RemoveInitializersFromInputsPass` in the `__all__` list. * **AddInitializersToInputsPass** - Add `AddInitializersToInputsPass` class to find and add initializers to the graph inputs. - Implement `call` method to add all initializers to the graph inputs if not already present. - Register `AddInitializersToInputsPass` in the `__all__` list. * **Tests** - Add test cases for `RemoveInitializersFromInputsPass` in `onnxscript/ir/passes/common/constant_manipulation_test.py` to verify removal of inputs with `const_value`. - Add test cases for `AddInitializersToInputsPass` in `onnxscript/ir/passes/common/constant_manipulation_test.py` to verify addition of initializers to the graph inputs. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/microsoft/onnxscript?shareId=XXXX-XXXX-XXXX-XXXX).
❌ 7 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
- Remove the `remove_initialized_inputs` option in dce because the contract of the pass it that it does not modify model signature. Fixed bugs where initializers are removed. Instead, users can use #2253 to remove the initialized inputs first. - Additionally updated RemoveUnusedOpsetsPass to always retain the default opset. --------- Co-authored-by: Copilot <[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 implements two passes for constant manipulation in ONNX graphs by removing and adding initializers from/to graph inputs, and updates test cases accordingly.
- Introduces RemoveInitializersFromInputsPass to filter initializer values from graph inputs.
- Implements AddInitializersToInputsPass to add missing initializers to graph inputs.
- Updates and expands tests in constant_manipulation_test.py.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
onnxscript/ir/passes/common/constant_manipulation.py | Adds two new pass classes and registers them in all. |
onnxscript/ir/passes/common/constant_manipulation_test.py | Adds tests to verify the behavior of both RemoveInitializersFromInputsPass and AddInitializersToInputsPass. |
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.
Put it into optimizer?
For now pytorch exporter doesn't need it because we don't produce models with initializers being inputs by default. When users turn the option on they are requesting initializers to the inputs explicitly so we don't want to undo it for users. Maybe put into ort optimizations if needed? |
Implement
RemoveInitializersFromInputsPass
andAddInitializersToInputsPass
inonnxscript/ir/passes/common/constant_manipulation.py
.RemoveInitializersFromInputsPass
RemoveInitializersFromInputsPass
class to find and remove graph inputs withconst_value
.call
method to remove inputs withconst_value
fromgraph.inputs
.RemoveInitializersFromInputsPass
in the__all__
list.AddInitializersToInputsPass
AddInitializersToInputsPass
class to find and add initializers to the graph inputs.call
method to add all initializers to the graph inputs if not already present.AddInitializersToInputsPass
in the__all__
list.Tests
RemoveInitializersFromInputsPass
inonnxscript/ir/passes/common/constant_manipulation_test.py
to verify removal of inputs withconst_value
.AddInitializersToInputsPass
inonnxscript/ir/passes/common/constant_manipulation_test.py
to verify addition of initializers to the graph inputs.For more details, open the Copilot Workspace session.