Skip to content

Conversation

@justinchuby
Copy link
Collaborator

This pull request introduces new utility functions for comparing shapes and dimensions in the intermediate representation (IR) utilities, and refactors existing rewrite rules to use these new utilities. The goal is to improve semantic correctness and code clarity when checking shape and dimension equality, especially in the presence of symbolic or unknown values.

Key changes:

New IR utility functions:

  • Added same_shape and same_dim functions to _ir_utils.py for more robust and semantically correct comparison of shapes and dimensions, accounting for unknown or symbolic values.

Refactoring of rewrite rules to use new utilities:

  • Updated _collapse_slices.py and _redundant_scatter_nd.py to use _ir_utils.same_shape and _ir_utils.same_dim instead of direct equality checks or previous logic, ensuring that shape and dimension comparisons are handled consistently and correctly. [1] [2] [3]

Code consistency improvements:

  • Standardized imports in affected files to use _ir_utils consistently, replacing previous aliasing or direct imports. [1] [2] [3]

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 pull request introduces semantic shape and dimension comparison utilities to improve correctness when handling symbolic or unknown values in the intermediate representation. The changes replace direct equality checks with more robust comparison functions that properly handle edge cases.

Key changes:

  • Added same_shape and same_dim utility functions to _ir_utils.py for robust shape/dimension comparison
  • Refactored existing rewrite rules to use the new utilities instead of direct equality checks
  • Standardized imports to use _ir_utils consistently across affected files

Reviewed Changes

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

File Description
onnxscript/rewriter/_ir_utils.py Added new same_shape and same_dim utility functions for semantic comparison
onnxscript/rewriter/rules/common/_redundant_scatter_nd.py Updated to use new utilities and standardized import format
onnxscript/rewriter/rules/common/_collapse_slices.py Refactored shape comparison logic to use new utilities

justinchuby and others added 3 commits October 9, 2025 12:19
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby justinchuby requested a review from Copilot October 9, 2025 19:23
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

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

@codecov
Copy link

codecov bot commented Oct 9, 2025

Codecov Report

❌ Patch coverage is 54.54545% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.31%. Comparing base (cb6f873) to head (77b7248).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
onnxscript/rewriter/_ir_utils.py 46.66% 4 Missing and 4 partials ⚠️
...ipt/rewriter/rules/common/_redundant_scatter_nd.py 50.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2620      +/-   ##
==========================================
- Coverage   70.32%   70.31%   -0.01%     
==========================================
  Files         222      222              
  Lines       26224    26237      +13     
  Branches     2624     2628       +4     
==========================================
+ Hits        18442    18449       +7     
- Misses       6865     6868       +3     
- Partials      917      920       +3     

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

@justinchuby justinchuby added this to the 0.5.4 milestone Oct 9, 2025
@justinchuby justinchuby enabled auto-merge (squash) October 10, 2025 18:19
@justinchuby justinchuby merged commit 071ff1e into main Oct 10, 2025
32 checks passed
@justinchuby justinchuby deleted the justinchu/same-shape branch October 10, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

3 participants