Skip to content

Conversation

@sebimarkgraf
Copy link
Contributor

@sebimarkgraf sebimarkgraf commented Nov 5, 2025

This fixes the issue of

  return [op.Squeeze(out, [dim]) for out in outputs]
                                              ^^^^^^^
TypeError: 'SymbolicTensor' object is not iterable

when trying to export LSTM modules in torch.
This also already appeared in torch issues in pytorch/pytorch#126339

The core seems to be the changes in #2597.
To my understanding the split returns a single SymbolicTensor instead of a sequence when dim=1.
The fix implemented here is the casting of the return type to a list.

I struggled with writing a test that reproduces this nicely in here, any guidance on that would be welcome.

@justinchuby
Copy link
Collaborator

If num_outputs=1, should we still use a Split node, or is Identity ok?

@gramalingam
Copy link
Collaborator

If num_outputs=1, should we still use a Split node, or is Identity ok?

Seems worthwhile emitting the optimized version without Split ... but it would still need the Squeeze ... no need for even Identity if we handle the two cases completely separately.

@titaiwangms titaiwangms added the module: torchlib Related to the torch/aten function lib in development label Nov 5, 2025
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.14%. Comparing base (d80575d) to head (58a1672).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
onnxscript/function_libs/torch_lib/ops/core.py 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2684      +/-   ##
==========================================
+ Coverage   70.11%   70.14%   +0.02%     
==========================================
  Files         224      225       +1     
  Lines       26982    27042      +60     
  Branches     2705     2717      +12     
==========================================
+ Hits        18919    18969      +50     
- Misses       7129     7135       +6     
- Partials      934      938       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sebimarkgraf
Copy link
Contributor Author

If num_outputs=1, should we still use a Split node, or is Identity ok?

Using Identity definitely makes sense, especially since this is already an optimization to my understanding.

@github-project-automation github-project-automation bot moved this from Todo to Done in ONNX Script Review Board Nov 6, 2025
@justinchuby justinchuby changed the title fix(outputs): Cast to sequence if num_outputs=1 [torchlib] Fix unbind.int if num_outputs=1 Nov 6, 2025
@justinchuby justinchuby merged commit 478acf7 into microsoft:main Nov 6, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: torchlib Related to the torch/aten function lib in development

Projects

Development

Successfully merging this pull request may close these issues.

5 participants