Fix aten_unbind for torch >= 2.7 dynamo export#2719
Merged
titaiwangms merged 2 commits intomicrosoft:mainfrom Dec 1, 2025
Merged
Fix aten_unbind for torch >= 2.7 dynamo export#2719titaiwangms merged 2 commits intomicrosoft:mainfrom
titaiwangms merged 2 commits intomicrosoft:mainfrom
Conversation
Contributor
Author
|
@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. |
titaiwangms
reviewed
Nov 26, 2025
Contributor
There was a problem hiding this comment.
Can you add your test as well? https://github.com/microsoft/onnxscript/blob/main/tests/function_libs/torch_lib/e2e_ops_tests.py
justinchuby
approved these changes
Nov 26, 2025
Collaborator
justinchuby
left a comment
There was a problem hiding this comment.
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)
justinchuby
approved these changes
Nov 26, 2025
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
titaiwangms
approved these changes
Dec 1, 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.
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