Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/onnx/test_pytorch_onnx_onnxruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,16 @@ def forward(self, input):
self.run_test(LenModel(), x, input_names=['input'], dynamic_axes={'input': {0: 'seq'}},
test_with_inputs=(torch.randn(5, 5),))

@skipIfUnsupportedMinOpsetVersion(9)
def test_len_list(self):
class LenListModel(torch.jit.ScriptModule):
@torch.jit.script_method
def forward(self, input):
return torch.ones(len(input.shape))

x = torch.randn(4, 5)
self.run_test(LenListModel(), x)

@skipIfUnsupportedMinOpsetVersion(11)
def test_unbind_dynamic(self):
class UnbindModel(torch.jit.ScriptModule):
Expand Down
4 changes: 3 additions & 1 deletion torch/onnx/symbolic_opset11.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ def masked_scatter(g, self, mask, source):


def _len(g, self):
return g.op("SequenceLength", self)
if self.type().isSubtypeOf(torch._C.ListType.ofTensors()):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Do we have tests to cover both branches in this symbolic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, test_len covers the if branch, test_len_list covers the else branch

return g.op("SequenceLength", self)
return g.op("Size", self)


def __getitem_(g, self, i):
Expand Down
4 changes: 4 additions & 0 deletions torch/onnx/symbolic_opset9.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ def floor(g, input):
return g.op("Floor", input)


def _len(g, self):
return g.op("Size", self)


@parse_args('v', 't', 't')
def threshold(g, self, threshold, value):
# See Note [Export inplace]
Expand Down