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

[Onnx] Pow support for other types #8933

Merged
merged 3 commits into from
Sep 8, 2021
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
28 changes: 27 additions & 1 deletion python/tvm/relay/frontend/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,32 @@ def _impl_v1(cls, inputs, attr, params):
return _op.log(_op.exp(beta * inputs[0]) + _expr.const(1.0)) * alpha


class Pow(OnnxOpConverter):
"""Operator converter for Pow."""

@classmethod
def _impl_v13(cls, inputs, attr, params):
x = inputs[0]
y = inputs[1]

x_type = infer_type(x).checked_type.dtype
output_type = x_type
y_type = infer_type(y).checked_type.dtype

if not x_type.startswith("float"):
x_type = "float32"
x = _op.cast(x, x_type)

if x_type != y_type:
y = _op.cast(y, x_type)

# TODO: come up with good default integer pow() func for common backends
result = _op.power(x, y)
if x_type != output_type:
return _op.cast(result, output_type)
return result


class Prelu(OnnxOpConverter):
"""Operator converter for Prelu."""

Expand Down Expand Up @@ -3644,7 +3670,7 @@ def _get_convert_map(opset):
"Sinh": Renamer("sinh"),
"Tan": Renamer("tan"),
"Tanh": Renamer("tanh"),
"Pow": Renamer("power"),
"Pow": Pow.get_converter(opset),
"PRelu": Prelu.get_converter(opset),
"Sigmoid": Renamer("sigmoid"),
"HardSigmoid": HardSigmoid.get_converter(opset),
Expand Down
10 changes: 0 additions & 10 deletions tests/python/frontend/onnx/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -4766,16 +4766,6 @@ def verify_eyelike(indata):
# This nllloss test is flaky and sometimes gives NaNs
# Investigate it here: https://github.com/apache/tvm/issues/8918
"test_nllloss_NCd1d2d3_none_no_weight_negative_ii",
"test_pow_types_float",
"test_pow_types_float32_int32",
"test_pow_types_float32_int64",
"test_pow_types_float32_uint32",
"test_pow_types_float32_uint64",
"test_pow_types_int",
"test_pow_types_int32_float32",
"test_pow_types_int32_int32",
"test_pow_types_int64_float32",
"test_pow_types_int64_int64",
"test_qlinearmatmul_2D",
"test_qlinearmatmul_3D",
"test_range_float_type_positive_delta_expanded",
Expand Down