This is an automated email from the ASF dual-hosted git repository.

junrushao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 2e24782  [Onnx Operators] Celu (#8741)
2e24782 is described below

commit 2e247825be4119882e6c5c691ccba69a2ad33836
Author: CircleSpin <[email protected]>
AuthorDate: Mon Aug 16 02:02:01 2021 -0400

    [Onnx Operators] Celu (#8741)
    
    * complete celu op
    
    * forgot to add test
    
    * change order in convert_map, remove comment, delete import hiccup
    
    Co-authored-by: CircleSpin <[email protected]>
---
 python/tvm/relay/frontend/onnx.py          | 14 ++++++++++++++
 tests/python/frontend/onnx/test_forward.py |  1 -
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/python/tvm/relay/frontend/onnx.py 
b/python/tvm/relay/frontend/onnx.py
index 70e6263..4866189 100644
--- a/python/tvm/relay/frontend/onnx.py
+++ b/python/tvm/relay/frontend/onnx.py
@@ -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),
@@ -3925,6 +3926,19 @@ class GraphProto:
         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
 ):
diff --git a/tests/python/frontend/onnx/test_forward.py 
b/tests/python/frontend/onnx/test_forward.py
index 8422cda..0b83b8d 100644
--- a/tests/python/frontend/onnx/test_forward.py
+++ b/tests/python/frontend/onnx/test_forward.py
@@ -4668,7 +4668,6 @@ unsupported_onnx_tests = [
     "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",

Reply via email to