Skip to content

Conversation

@justinchuby
Copy link
Member

@justinchuby justinchuby commented Nov 3, 2025

This pull request introduces new methods to dynamically resize the inputs and outputs of a Node in the ONNX IR core, making graph manipulation more flexible and robust. It updates the API to support these operations and adds comprehensive tests to ensure correct behavior, including edge cases and error handling.

API Enhancements for Node Inputs and Outputs

  • Added resize_inputs method to Node, allowing the number of inputs to be increased (by adding None values) or decreased (removing extra inputs and cleaning up their uses). The setter error message for inputs was also updated to reference the new method.
  • Added resize_outputs method to Node, enabling dynamic resizing of outputs. Outputs can be increased (new Value objects created) or decreased, but removal is only allowed if the outputs have no uses; otherwise, a ValueError is raised. The setter error message for outputs was updated accordingly.

Comprehensive Testing

  • Added extensive unit tests for resize_inputs, covering increasing, decreasing, unchanged size, zeroing, growing from zero, and preservation of None inputs.
  • Added thorough unit tests for resize_outputs, including increasing, decreasing, unchanged size, zeroing, growing from zero, and error handling when attempting to remove outputs that are still in use.

Why not create pop and add to the inputs/outputs object

Currently inputs and outputs are implemented as tuple, which means there are a lot of methods associated to it that we get for free. Since there is not a usertuple class in python, defining an immutable sequence that supports all of the tuple methods may be complex (have to implement the full Sequence interface). And since the current interface says Node.inputs, Node.outputs return Sequence interfaces, having selected mutable methods on them (pop, add) makes it confusing.

Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby justinchuby requested review from a team and titaiwangms as code owners November 3, 2025 19:04
@justinchuby justinchuby added this to the 0.1.13 milestone Nov 3, 2025
@codecov
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

❌ Patch coverage is 89.47368% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.99%. Comparing base (135eccc) to head (83bdb1a).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/onnx_ir/passes/common/unused_removal.py 78.57% 1 Missing and 2 partials ⚠️
src/onnx_ir/_core.py 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #244      +/-   ##
==========================================
+ Coverage   76.86%   76.99%   +0.13%     
==========================================
  Files          40       40              
  Lines        4997     5034      +37     
  Branches      996     1008      +12     
==========================================
+ Hits         3841     3876      +35     
- Misses        867      868       +1     
- Partials      289      290       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

Copilot AI left a 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 resize_inputs and resize_outputs methods to the Node class in the ONNX IR, providing a way to dynamically adjust the number of inputs and outputs of a node.

  • Adds resize_inputs() method to adjust node input count dynamically
  • Adds resize_outputs() method to adjust node output count dynamically
  • Updates error messages for property setters to reference the new methods
  • Comprehensive test coverage for all edge cases

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/onnx_ir/_core.py Implements resize_inputs and resize_outputs methods and updates setter error messages
src/onnx_ir/_core_test.py Adds comprehensive test coverage for the new resizing methods

Signed-off-by: Justin Chu <[email protected]>
@justinchuby justinchuby marked this pull request as draft November 3, 2025 19:14
@justinchuby justinchuby marked this pull request as ready for review November 3, 2025 19:15
justinchuby and others added 2 commits November 3, 2025 11:15
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby
Copy link
Member Author

cc @gramalingam

@justinchuby justinchuby merged commit 926397c into main Nov 6, 2025
25 checks passed
@justinchuby justinchuby deleted the justinchu/resize-io branch November 6, 2025 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants