Skip to content

Commit

Permalink
[PyTorch] Add aten::square operator (apache#10766)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeexyz authored Mar 24, 2022
1 parent f07fd8b commit 73ec860
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/tvm/relay/frontend/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ def log1p(self, inputs, input_types):
one = _expr.const(1, dtype=dtype)
return _op.log(inputs[0] + one)

def square(self, inputs, input_types):
(dtype,) = input_types
return _op.power(inputs[0], _expr.const(2, dtype))

def arange(self, inputs, input_types):
def _get_value(val, dtype):
# dtype is a tvm dtype
Expand Down Expand Up @@ -3093,6 +3097,7 @@ def create_convert_map(self):
"aten::sign": self.make_unary("sign"),
"aten::sqrt": self.make_unary("sqrt"),
"aten::rsqrt": self.make_unary("rsqrt"),
"aten::square": self.square,
"aten::ceil": self.make_unary("ceil"),
"aten::floor": self.make_unary("floor"),
"aten::round": self.make_unary("round"),
Expand Down
5 changes: 5 additions & 0 deletions tests/python/frontend/pytorch/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3309,8 +3309,13 @@ class Log1p_1(Module):
def forward(self, *args):
return torch.log1p(args[0])

class Square(Module):
def forward(self, *args):
return torch.square(args[0])

input_shape = [1, 3, 10, 10]
input_data = torch.rand(input_shape).float()
verify_model(Square().float().eval(), input_data=input_data)
verify_model(Sqrt1().float().eval(), input_data=input_data)
verify_model(RSqrt1().float().eval(), input_data=input_data)
verify_model(Ceil1().float().eval(), input_data=input_data)
Expand Down

0 comments on commit 73ec860

Please sign in to comment.