Skip to content

Commit

Permalink
[Relax][ONNX] Add Exp op (apache#28)
Browse files Browse the repository at this point in the history
Add exp operation to ONNX front-end of Relax

---------

Co-authored-by: Valery Chernov <[email protected]>
  • Loading branch information
vvchernov and Valery Chernov authored Mar 22, 2023
1 parent 9bead30 commit 39ea587
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions python/tvm/relax/frontend/onnx/onnx_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,32 @@ def _impl_v13(cls, bb, inputs, attr):
return attach_span(relax.op.log(inputs[0]))


class Exp(OnnxOpConverter):
"""Converts an onnx Exp node into an equivalent Relax expression."""

@classmethod
def _check_type(cls, dtype, valid_types):
assert dtype in valid_types, "Types {} are supported only, but {} is given".format(
valid_types, dtype
)

@classmethod
def _impl_v1(cls, bb, inputs, attr):
data = inputs[0]
valid_types = ["float", "float32", "double", "float64", "float16"]
cls._check_type(data.checked_type.dtype, valid_types)

return relax.op.exp(data)

@classmethod
def _impl_v13(cls, bb, inputs, attr):
data = inputs[0]
valid_types = ["float", "float32", "double", "float64", "float16", "bfloat16"]
cls._check_type(data.checked_type.dtype, valid_types)

return relax.op.exp(data)


class Less(OnnxOpConverter):
"""Converts an onnx Less node into an equivalent Relax expression."""

Expand Down Expand Up @@ -1705,6 +1731,7 @@ def _get_convert_map():
"Min": Min,
"Max": Max,
"Log": Log,
"Exp": Exp,
"Less": Less,
"LessOrEqual": LessOrEqual,
"LayerNormalization": LayerNormalization,
Expand Down
4 changes: 4 additions & 0 deletions tests/python/relax/frontend/test_onnx_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,10 @@ def test_log():
verify_unary("Log", [32, 16])


def test_exp():
verify_unary("Exp", [32, 16])


def test_instance_norm():
verify_ternary(
"InstanceNormalization", [1, 3, 32, 32], [3], [3], [1, 3, 32, 32], attrs={"epsilon": 1e-12}
Expand Down

0 comments on commit 39ea587

Please sign in to comment.