-
Notifications
You must be signed in to change notification settings - Fork 94
Fix aten_unbind for torch >= 2.7 dynamo export #2719
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
Fix aten_unbind for torch >= 2.7 dynamo export #2719
Conversation
|
@microsoft-github-policy-service agree |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2719 +/- ##
=======================================
Coverage 70.10% 70.11%
=======================================
Files 226 226
Lines 27226 27228 +2
Branches 2747 2747
=======================================
+ Hits 19086 19090 +4
+ Misses 7194 7193 -1
+ Partials 946 945 -1 ☔ View full report in Codecov by Sentry. |
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.
Can you add your test as well? https://github.com/microsoft/onnxscript/blob/main/tests/function_libs/torch_lib/e2e_ops_tests.py
justinchuby
left a comment
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.
Thanks. The fix is reasonable (and arguably better than the original because it's easier to optimize). Although I don't know why the exporter doesn't handle split correctly (it should)
74474d6 to
521cf5e
Compare
Replace Split op with explicit Slice operations to fix TypeError when unbind is called during ONNX export with dynamo=True. The Split op with num_outputs parameter returns a non-iterable SymbolicTensor instead of a sequence, causing the list comprehension to fail. The fix uses individual Slice + Squeeze operations for each output, which properly handles symbolic tensors during graph construction. Fixes pytorch/pytorch#168969
d4a450b to
7af0d47
Compare
Fix aten_unbind for torch >= 2.7 dynamo export
Problem
When exporting PyTorch models to ONNX with
dynamo=Trueon torch >= 2.7, theaten_unbindoperation fails with:This occurs because
op.Split(self, axis=dim, num_outputs=num_outputs)returns a singleSymbolicTensorobject rather than an iterable sequence during dynamo export. The subsequent list comprehension[op.Squeeze(out, [dim]) for out in outputs]attempts to iterate over this non-iterable object, causing that error.This affects models using LSTM and other operations that internally call
unbind, preventing successful ONNX export.Solution
Replace the
Splitop approach with explicitSliceoperations:Sliceoperation to extract one elementSqueezeto remove the size-1 dimensionTest coverage:
Related Issues
Fixes pytorch/pytorch#168969