-
Notifications
You must be signed in to change notification settings - Fork 101
Improve Reshape and Slice folding #2807
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
base: main
Are you sure you want to change the base?
Conversation
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 pull request improves constant folding for Reshape operations by materializing shape inputs as constants when the output shape is known from shape inference. It also adds support for INT32 dtype shape inputs, which are common in TFLite models.
Changes:
- Added INT32 fallback support in
get_shape_value()for shape inputs (common in TFLite models) - Implemented
_try_materialize_reshape_shape()to create constant shape inputs from inferred output shapes - Updated
reshape()function to leverage shape materialization for optimization
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2807 +/- ##
==========================================
+ Coverage 70.50% 70.61% +0.11%
==========================================
Files 228 230 +2
Lines 27114 27246 +132
Branches 2726 2746 +20
==========================================
+ Hits 19116 19240 +124
- Misses 7065 7066 +1
- Partials 933 940 +7 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
a67ab69 to
3c550df
Compare
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
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
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
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
| # All steps must be 1 | ||
| steps_np = _ir_utils.get_numpy_value(steps) | ||
| if steps_np is not None: | ||
| if not all(s == 1 for s in steps_np.flatten()): |
Copilot
AI
Feb 13, 2026
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.
Using flatten() creates a copy of the array. For better performance with potentially large step arrays, use steps_np.ravel() which returns a view when possible, or iterate directly with steps_np.flat which is a flat iterator.
| if not all(s == 1 for s in steps_np.flatten()): | |
| if not all(s == 1 for s in steps_np.flat): |
Uh oh!
There was an error while loading. Please reload this page.