[torchlib] Improve handling of SymInt[]#2522
Merged
justinchuby merged 24 commits intomainfrom Sep 4, 2025
Merged
Conversation
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves the handling of SymInt[] parameters in torch_lib operations by avoiding unnecessary conversion to INT64 tensors and enabling better optimization of static dimensions.
- Updates functions to accept
Sequence[INT64]instead ofIntTypefor shape parameters - Introduces a
merge_dimshelper function to optimize consecutive constant dimensions - Removes unnecessary
Absoperations inaten_expandby handling constant -1 values directly
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| onnxscript/function_libs/torch_lib/ops/core.py | Updates multiple torch operations to use new shape handling approach and removes unnecessary type casting |
| onnxscript/function_libs/torch_lib/ops/common.py | Adds new merge_dims helper function to optimize consecutive constant dimensions |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2522 +/- ##
==========================================
+ Coverage 69.93% 69.98% +0.04%
==========================================
Files 216 216
Lines 26052 26058 +6
Branches 2616 2618 +2
==========================================
+ Hits 18219 18236 +17
+ Misses 6931 6920 -11
Partials 902 902 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
gramalingam
reviewed
Aug 27, 2025
gramalingam
reviewed
Aug 27, 2025
gramalingam
reviewed
Aug 27, 2025
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
xadupre
reviewed
Aug 28, 2025
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
xadupre
approved these changes
Sep 4, 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.
Previously sizes coming in as
SymInt[]are first concatenated as INT64 then used. This created inefficiencies where we could not process any static dims from the size list and had to treat the whole shape as dynamic. In aten_expand, this meant we needed to addAbson the shape.This change updates the functions that take
SymInt[]such that they are no longer turned into INT64 first. I updated aten_expand to process constant-1values so anAbsis not required. I also added a helpermerge_dimsto create constants for consecutive constant dims first before concatinating.