-
Notifications
You must be signed in to change notification settings - Fork 71
Support dynamic shapes for aten_unfold #2407
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
Conversation
Amazing, thanks you! |
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 PR introduces support for dynamic shapes in the aten_unfold operator to resolve conversion errors when using symbolic dimensions with torch.onnx.export.
- Refactored the handling of dim_size by replacing direct tensor indexing with op.Shape and op.Gather.
- Reworked the window generation logic using op.Range, broadcasting, and reordering the output with op.Transpose to maintain shape consistency.
Comments suppressed due to low confidence (2)
onnxscript/function_libs/torch_lib/ops/core.py:8701
- [nitpick] Consider adding a clarifying inline comment explaining the permutation logic used in op.Transpose to improve maintainability and assist future reviewers.
perm.append(perm.pop(dimension + 1))
onnxscript/function_libs/torch_lib/ops/core.py:8669
- Ensure that op.Div performs floor division to correctly compute output_size as per '(input_size - kernel_size) // stride + 1'. If it doesn't, consider using an explicit floor division operator or integer casting.
)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2407 +/- ##
=======================================
Coverage 70.38% 70.39%
=======================================
Files 199 199
Lines 25223 25226 +3
Branches 2686 2686
=======================================
+ Hits 17753 17757 +4
+ Misses 6541 6540 -1
Partials 929 929 ☔ View full report in Codecov by Sentry. |
Thanks for the review 👍 Changes made ✅ |
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.
Thank you! The code is very skilled at using op.Gather and broadcasting!
While converting a new model that I'd like to add to Transformers.js, I ran into #2309, indicating that dynamic shapes aren't currently supported for
aten_unfold
:So, I dug a bit into the code and with some help from Claude, I got a version which works for my use-case (output matches exactly)! 👍
Code to reproduce (adapted from pytorch/pytorch#112844 (comment))
Logs (before)
Logs (after)
Closes #2309. cc @justinchuby