Commit 597d5f7
authored
Fix aten_unbind for torch >= 2.7 dynamo export (#2719)
Fix aten_unbind for torch >= 2.7 dynamo export
## Problem
When exporting PyTorch models to ONNX with `dynamo=True` on torch >=
2.7, the `aten_unbind` operation fails with:
```
TypeError: 'SymbolicTensor' object is not iterable
```
This occurs because `op.Split(self, axis=dim, num_outputs=num_outputs)`
returns a single `SymbolicTensor` object 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 `Split` op approach with explicit `Slice` operations:
- For each output along the unbind dimension, create an individual
`Slice` operation to extract one element
- Apply `Squeeze` to remove the size-1 dimension
- Collect all results in a list
## Test coverage:
- num_outputs = 1: test_unbind_size_one
- num_outputs = 2: test_unbind_with_lstm, test_unbind_dim1 (size 2 along
some dims)
- num_outputs = 3: test_unbind_dim0, test_unbind_dim1
- num_outputs = 4: test_unbind_negative_dim
- Negative dimensions: test_unbind_negative_dim
## Related Issues
Fixes pytorch/pytorch#1689691 parent 9dbf685 commit 597d5f7
File tree
2 files changed
+120
-9
lines changed- onnxscript/function_libs/torch_lib/ops
- tests/function_libs/torch_lib
2 files changed
+120
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9200 | 9200 | | |
9201 | 9201 | | |
9202 | 9202 | | |
9203 | | - | |
9204 | | - | |
9205 | | - | |
| 9203 | + | |
9206 | 9204 | | |
9207 | | - | |
9208 | | - | |
9209 | | - | |
9210 | | - | |
9211 | | - | |
9212 | | - | |
| 9205 | + | |
| 9206 | + | |
| 9207 | + | |
| 9208 | + | |
| 9209 | + | |
| 9210 | + | |
| 9211 | + | |
| 9212 | + | |
| 9213 | + | |
| 9214 | + | |
| 9215 | + | |
| 9216 | + | |
| 9217 | + | |
9213 | 9218 | | |
9214 | 9219 | | |
9215 | 9220 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
523 | 629 | | |
524 | 630 | | |
525 | 631 | | |
0 commit comments