Skip to content
Merged
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
17 changes: 17 additions & 0 deletions python/tvm/relay/frontend/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,22 @@ def zeros_like(self, inputs, input_types):

return out

def new_zeros(self, inputs, input_types):
data = inputs[1]

import torch

if not isinstance(data, (_expr.Expr, list, tuple, torch.Size)):
msg = "Data type %s could not be parsed in new_zeros op" % (type(data))
raise AssertionError(msg)

if inputs[2] is not None:
dtype = _convert_dtype_value(inputs[2])
else:
# if dtype is None, use the dtype of the input tensor
dtype = self.infer_type(inputs[0])
return self.full_impl(data, 0, dtype)

def full(self, inputs, input_types):
data = inputs[0]
fill_value = inputs[1]
Expand Down Expand Up @@ -3755,6 +3771,7 @@ def create_convert_map(self):
"aten::zeros": self.zeros,
"aten::zero_": self.zero_,
"aten::zeros_like": self.zeros_like,
"aten::new_zeros": self.new_zeros,
"aten::new_ones": self.new_ones,
"aten::full": self.full,
"aten::full_like": self.full_like,
Expand Down
7 changes: 7 additions & 0 deletions tests/python/frontend/pytorch/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3348,6 +3348,13 @@ def forward(self, *args):
verify_model(ZerosLike3().float().eval(), input_data=input_data)


def test_forward_new_zeros():
def test_func(x):
return x.new_zeros((2, 3))

verify_model_with_input(test_func, [torch.rand([1, 3, 10, 10]).float()])


@tvm.testing.uses_gpu
def test_forward_full():
"""test_forward_full"""
Expand Down