Skip to content

Commit

Permalink
[Onnx Operators] Celu (apache#8741)
Browse files Browse the repository at this point in the history
* complete celu op

* forgot to add test

* change order in convert_map, remove comment, delete import hiccup

Co-authored-by: CircleSpin <jocelyn@pop-os.localdomain>
  • Loading branch information
2 people authored and ylc committed Sep 29, 2021
1 parent a3cb287 commit a6a0605
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 14 additions & 0 deletions python/tvm/relay/frontend/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3480,6 +3480,7 @@ def _get_convert_map(opset):
"IsNaN": Renamer("isnan"),
"Sqrt": Renamer("sqrt"),
"Relu": Renamer("relu"),
"Celu": Celu.get_converter(opset),
"LeakyRelu": Renamer("leaky_relu"),
"Selu": Selu.get_converter(opset),
"Elu": Elu.get_converter(opset),
Expand Down Expand Up @@ -3925,6 +3926,19 @@ def _fix_outputs(self, op_name, outputs):
return outputs


class Celu(OnnxOpConverter):
"""Operator convereter for celu"""

@classmethod
def _impl_v12(cls, inputs, attr, params):
x = inputs[0]
dtype = infer_type(x).checked_type.dtype
alpha = _op.const(attr.get("alpha", 1.0), dtype)
zero = _op.const(0, dtype)
one = _op.const(1, dtype)
return _op.maximum(zero, x) + _op.minimum(zero, alpha * (_op.exp(x / alpha) - one))


def from_onnx(
model, shape=None, dtype="float32", opset=None, freeze_params=False, convert_config=None
):
Expand Down
1 change: 0 additions & 1 deletion tests/python/frontend/onnx/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -4668,7 +4668,6 @@ def verify_eyelike(indata):
"test_cast_FLOAT_to_BFLOAT16",
"test_cast_FLOAT_to_STRING",
"test_cast_STRING_to_FLOAT",
"test_celu",
"test_compress_0",
"test_compress_1",
"test_compress_default_axis",
Expand Down

0 comments on commit a6a0605

Please sign in to comment.