Create helper for comparing semantic equivalence of shapes#2620
Merged
justinchuby merged 4 commits intomainfrom Oct 10, 2025
Merged
Create helper for comparing semantic equivalence of shapes#2620justinchuby merged 4 commits intomainfrom
justinchuby merged 4 commits intomainfrom
Conversation
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
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_shapeandsame_dimutility functions to_ir_utils.pyfor robust shape/dimension comparison - Refactored existing rewrite rules to use the new utilities instead of direct equality checks
- Standardized imports to use
_ir_utilsconsistently 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 |
Codecov Report❌ Patch coverage is
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. |
titaiwangms
reviewed
Oct 9, 2025
titaiwangms
approved these changes
Oct 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
same_shapeandsame_dimfunctions to_ir_utils.pyfor more robust and semantically correct comparison of shapes and dimensions, accounting for unknown or symbolic values.Refactoring of rewrite rules to use new utilities:
_collapse_slices.pyand_redundant_scatter_nd.pyto use_ir_utils.same_shapeand_ir_utils.same_diminstead of direct equality checks or previous logic, ensuring that shape and dimension comparisons are handled consistently and correctly. [1] [2] [3]Code consistency improvements:
_ir_utilsconsistently, replacing previous aliasing or direct imports. [1] [2] [3]