Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding aten::unsqueeze_ to PT Frontend #7231

Merged
merged 6 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions python/tvm/relay/frontend/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,13 @@ def clone(self, inputs, input_types):
data = inputs[0]
return _op.tensor.copy(data)

def copy_(self, inputs, input_types):
assert self.infer_shape(inputs[0]) == self.infer_shape(
inputs[1]
), "Shapes of source and destination tensors must be the same"

return _op.tensor.copy(_op.cast(inputs[1], input_types[0]))

def log_softmax(self, inputs, input_types):
data = inputs[0]
axis = int(inputs[1])
Expand Down Expand Up @@ -2117,6 +2124,7 @@ def create_convert_map(self):
"aten::to": self.to,
"aten::squeeze": self.squeeze,
"aten::unsqueeze": self.unsqueeze,
"aten::unsqueeze_": self.unsqueeze,
"aten::cat": self.concatenate,
"aten::slice": self.slice,
"aten::split": self.split,
Expand Down Expand Up @@ -2162,6 +2170,7 @@ def create_convert_map(self):
"aten::view": self.view,
"aten::reshape": self.reshape,
"aten::clone": self.clone,
"aten::copy_": self.copy_,
"aten::log_softmax": self.log_softmax,
"aten::sigmoid": self.sigmoid,
"aten::softplus": self.softplus,
Expand Down
19 changes: 19 additions & 0 deletions tests/python/frontend/pytorch/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,13 @@ class Unsqueeze1(Module):
def forward(self, *args):
return args[0].unsqueeze(2)

class Unsqueeze2(Module):
def forward(self, *args):
return args[0].unsqueeze_(2)

input_data = torch.rand(input_shape).float()
verify_model(Unsqueeze1().float().eval(), input_data=input_data)
verify_model(Unsqueeze2().float().eval(), input_data=input_data)


@tvm.testing.uses_gpu
Expand Down Expand Up @@ -1178,6 +1183,19 @@ def forward(self, *args):
verify_model(Clone1().float().eval(), input_data=input_data)


@tvm.testing.uses_gpu
def test_forward_copy_():
torch.set_grad_enabled(False)
input_shape = [10]

class Copy_(Module):
def forward(self, *args):
return torch.zeros_like(args[0]).copy_(args[0])

input_data = torch.rand(input_shape).float()
verify_model(Copy_().float().eval(), input_data=input_data)


@tvm.testing.uses_gpu
def test_forward_gather():
torch.set_grad_enabled(False)
Expand Down Expand Up @@ -3508,6 +3526,7 @@ def test_hard_swish():
test_forward_true_divide()
test_forward_is_floating_point()
test_forward_clone()
test_forward_copy_()
test_forward_softplus()
test_forward_softsign()
test_forward_logsoftmax()
Expand Down