You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/01/06 14:27:38 UTC

[GitHub] [incubator-tvm] inadob opened a new pull request #4634: [Relay][Frontend][Tflite] Add parses support for unary elemwise ops

inadob opened a new pull request #4634: [Relay][Frontend][Tflite] Add parses support for unary elemwise ops
URL: https://github.com/apache/incubator-tvm/pull/4634
 
 
   * Add generic method to convert unary math functions
   * Add support for: abs, exp, ceil, floor, log, sin, cos, sqrt, rsqrt, neg
   * Add relevant tests
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops

Posted by GitBox <gi...@apache.org>.
FrozenGene commented on a change in pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops
URL: https://github.com/apache/incubator-tvm/pull/4634#discussion_r363840301
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -616,6 +616,109 @@ def test_forward_concatenation():
          np.arange(6).reshape((2, 1, 1, 3)),
          np.arange(6).reshape((2, 1, 1, 3))], 1)
 
+#######################################################################
+# Unary elemwise
+# --------------
+
+def _test_unary_elemwise(math_op, data):
+    """ One iteration of unary elemwise """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype, name='in')
+        out = math_op(in_data)
+        compare_tflite_with_tvm(data, ['in:0'], in_data, [out])
+
+#######################################################################
+# Abs
+# ---
+
+def _test_abs(data):
+    """ One iteration of abs """
+    return _test_unary_elemwise(math_ops.abs, data)
+#######################################################################
+# Ceil
+# ----
+
+def _test_ceil(data):
+    """ One iteration of ceil """
+    return _test_unary_elemwise(math_ops.ceil, data)
+#######################################################################
+# Floor
+# -----
+
+def _test_floor(data):
+    """ One iteration of floor """
+    return _test_unary_elemwise(math_ops.floor, data)
+#######################################################################
+# Exp
+# ---
+
+def _test_exp(data):
+    """ One iteration of exp """
+    return _test_unary_elemwise(math_ops.exp, data)
+#######################################################################
+# Log
+# ---
+
+def _test_log(data):
+    """ One iteration of log """
+    return _test_unary_elemwise(math_ops.log, data)
+#######################################################################
+# Sin
+# ---
+
+def _test_sin(data):
+    """ One iteration of sin """
+    return _test_unary_elemwise(math_ops.sin, data)
+#######################################################################
+# Cos
+# ---
+
+def _test_cos(data):
+    """ One iteration of cos """
+    return _test_unary_elemwise(math_ops.cos, data)
+#######################################################################
+# Sqrt
+# ----
+
+def _test_sqrt(data):
+    """ One iteration of sqrt """
+    return _test_unary_elemwise(math_ops.sqrt, data)
+#######################################################################
+# Rsqrt
+# -----
+
+def _test_rsqrt(data):
+    """ One iteration of rsqrt """
+    return _test_unary_elemwise(math_ops.rsqrt, data)
+#######################################################################
+# Neg
+# ---
+
+def _test_neg(data):
+    """ One iteration of neg """
+    return _test_unary_elemwise(math_ops.neg, data)
+#######################################################################
+
+def _test_forward_unary_elemwise(testop):
 
 Review comment:
   Yes. I think you should only need to change this too:
   ```
       if test_op in {'_test_log', '_test_sqrt', '_test_rsqrt'}:
           test_op(np.arange(6.0, dtype=np.float32).reshape((2, 1, 3)))
           test_op(np.arange(6.0, dtype=np.int32).reshape((2, 1, 3)))
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen commented on issue #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops

Posted by GitBox <gi...@apache.org>.
tqchen commented on issue #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops
URL: https://github.com/apache/incubator-tvm/pull/4634#issuecomment-572698103
 
 
   Thanks @FrozenGene @anijain2305 @inadob 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] inadob commented on issue #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops

Posted by GitBox <gi...@apache.org>.
inadob commented on issue #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops
URL: https://github.com/apache/incubator-tvm/pull/4634#issuecomment-571224740
 
 
   @kevinthesun @FrozenGene can you please review this patch

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen commented on issue #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops

Posted by GitBox <gi...@apache.org>.
tqchen commented on issue #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops
URL: https://github.com/apache/incubator-tvm/pull/4634#issuecomment-571249950
 
 
   ping @FrozenGene please also take a look

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen edited a comment on issue #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops

Posted by GitBox <gi...@apache.org>.
tqchen edited a comment on issue #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops
URL: https://github.com/apache/incubator-tvm/pull/4634#issuecomment-571249950
 
 
   ping @FrozenGene @kazum please also take a look

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops

Posted by GitBox <gi...@apache.org>.
FrozenGene commented on a change in pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops
URL: https://github.com/apache/incubator-tvm/pull/4634#discussion_r363792924
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -616,6 +616,109 @@ def test_forward_concatenation():
          np.arange(6).reshape((2, 1, 1, 3)),
          np.arange(6).reshape((2, 1, 1, 3))], 1)
 
+#######################################################################
+# Unary elemwise
+# --------------
+
+def _test_unary_elemwise(math_op, data):
+    """ One iteration of unary elemwise """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype, name='in')
+        out = math_op(in_data)
+        compare_tflite_with_tvm(data, ['in:0'], in_data, [out])
+
+#######################################################################
+# Abs
+# ---
+
+def _test_abs(data):
+    """ One iteration of abs """
+    return _test_unary_elemwise(math_ops.abs, data)
+#######################################################################
+# Ceil
+# ----
+
+def _test_ceil(data):
+    """ One iteration of ceil """
+    return _test_unary_elemwise(math_ops.ceil, data)
+#######################################################################
+# Floor
+# -----
+
+def _test_floor(data):
+    """ One iteration of floor """
+    return _test_unary_elemwise(math_ops.floor, data)
+#######################################################################
+# Exp
+# ---
+
+def _test_exp(data):
+    """ One iteration of exp """
+    return _test_unary_elemwise(math_ops.exp, data)
+#######################################################################
+# Log
+# ---
+
+def _test_log(data):
+    """ One iteration of log """
+    return _test_unary_elemwise(math_ops.log, data)
+#######################################################################
+# Sin
+# ---
+
+def _test_sin(data):
+    """ One iteration of sin """
+    return _test_unary_elemwise(math_ops.sin, data)
+#######################################################################
+# Cos
+# ---
+
+def _test_cos(data):
+    """ One iteration of cos """
+    return _test_unary_elemwise(math_ops.cos, data)
+#######################################################################
+# Sqrt
+# ----
+
+def _test_sqrt(data):
+    """ One iteration of sqrt """
+    return _test_unary_elemwise(math_ops.sqrt, data)
+#######################################################################
+# Rsqrt
+# -----
+
+def _test_rsqrt(data):
+    """ One iteration of rsqrt """
+    return _test_unary_elemwise(math_ops.rsqrt, data)
+#######################################################################
+# Neg
+# ---
+
+def _test_neg(data):
+    """ One iteration of neg """
+    return _test_unary_elemwise(math_ops.neg, data)
+#######################################################################
+
+def _test_forward_unary_elemwise(testop):
 
 Review comment:
   testop -> test_op

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen merged pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops

Posted by GitBox <gi...@apache.org>.
tqchen merged pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops
URL: https://github.com/apache/incubator-tvm/pull/4634
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops

Posted by GitBox <gi...@apache.org>.
FrozenGene commented on a change in pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops
URL: https://github.com/apache/incubator-tvm/pull/4634#discussion_r363840301
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -616,6 +616,109 @@ def test_forward_concatenation():
          np.arange(6).reshape((2, 1, 1, 3)),
          np.arange(6).reshape((2, 1, 1, 3))], 1)
 
+#######################################################################
+# Unary elemwise
+# --------------
+
+def _test_unary_elemwise(math_op, data):
+    """ One iteration of unary elemwise """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype, name='in')
+        out = math_op(in_data)
+        compare_tflite_with_tvm(data, ['in:0'], in_data, [out])
+
+#######################################################################
+# Abs
+# ---
+
+def _test_abs(data):
+    """ One iteration of abs """
+    return _test_unary_elemwise(math_ops.abs, data)
+#######################################################################
+# Ceil
+# ----
+
+def _test_ceil(data):
+    """ One iteration of ceil """
+    return _test_unary_elemwise(math_ops.ceil, data)
+#######################################################################
+# Floor
+# -----
+
+def _test_floor(data):
+    """ One iteration of floor """
+    return _test_unary_elemwise(math_ops.floor, data)
+#######################################################################
+# Exp
+# ---
+
+def _test_exp(data):
+    """ One iteration of exp """
+    return _test_unary_elemwise(math_ops.exp, data)
+#######################################################################
+# Log
+# ---
+
+def _test_log(data):
+    """ One iteration of log """
+    return _test_unary_elemwise(math_ops.log, data)
+#######################################################################
+# Sin
+# ---
+
+def _test_sin(data):
+    """ One iteration of sin """
+    return _test_unary_elemwise(math_ops.sin, data)
+#######################################################################
+# Cos
+# ---
+
+def _test_cos(data):
+    """ One iteration of cos """
+    return _test_unary_elemwise(math_ops.cos, data)
+#######################################################################
+# Sqrt
+# ----
+
+def _test_sqrt(data):
+    """ One iteration of sqrt """
+    return _test_unary_elemwise(math_ops.sqrt, data)
+#######################################################################
+# Rsqrt
+# -----
+
+def _test_rsqrt(data):
+    """ One iteration of rsqrt """
+    return _test_unary_elemwise(math_ops.rsqrt, data)
+#######################################################################
+# Neg
+# ---
+
+def _test_neg(data):
+    """ One iteration of neg """
+    return _test_unary_elemwise(math_ops.neg, data)
+#######################################################################
+
+def _test_forward_unary_elemwise(testop):
 
 Review comment:
   Yes. I think you should only need to change this too:
   ```
       if test_op in {'_test_log', '_test_sqrt', '_test_rsqrt'}:
           test_op(np.arange(6.0, dtype=np.float32).reshape((2, 1, 3)))
           test_op(np.arange(6.0, dtype=np.int32).reshape((2, 1, 3)))
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] anijain2305 commented on a change in pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops

Posted by GitBox <gi...@apache.org>.
anijain2305 commented on a change in pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops
URL: https://github.com/apache/incubator-tvm/pull/4634#discussion_r363391296
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -616,6 +616,109 @@ def test_forward_concatenation():
          np.arange(6).reshape((2, 1, 1, 3)),
          np.arange(6).reshape((2, 1, 1, 3))], 1)
 
+#######################################################################
+# Unary elemwise
+# --------------
+
+def _test_unary_elemwise(math_op, data):
+    """ One iteration of unary elemwise """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype, name='in')
+        out = math_op(in_data)
+        compare_tflite_with_tvm(data, ['in:0'], in_data, [out])
+
+#######################################################################
+# Abs
+# ---
+
+def _test_abs(data):
+    """ One iteration of abs """
+    return _test_unary_elemwise(math_ops.abs, data)
+#######################################################################
+# Ceil
+# ----
+
+def _test_ceil(data):
+    """ One iteration of ceil """
+    return _test_unary_elemwise(math_ops.ceil, data)
+#######################################################################
+# Floor
+# -----
+
+def _test_floor(data):
+    """ One iteration of floor """
+    return _test_unary_elemwise(math_ops.floor, data)
+#######################################################################
+# Exp
+# -----
 
 Review comment:
   2 extra "--".

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] FrozenGene commented on a change in pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops

Posted by GitBox <gi...@apache.org>.
FrozenGene commented on a change in pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops
URL: https://github.com/apache/incubator-tvm/pull/4634#discussion_r363840526
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -616,6 +616,109 @@ def test_forward_concatenation():
          np.arange(6).reshape((2, 1, 1, 3)),
          np.arange(6).reshape((2, 1, 1, 3))], 1)
 
+#######################################################################
+# Unary elemwise
+# --------------
+
+def _test_unary_elemwise(math_op, data):
+    """ One iteration of unary elemwise """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype, name='in')
+        out = math_op(in_data)
+        compare_tflite_with_tvm(data, ['in:0'], in_data, [out])
+
+#######################################################################
+# Abs
+# ---
+
+def _test_abs(data):
+    """ One iteration of abs """
+    return _test_unary_elemwise(math_ops.abs, data)
+#######################################################################
+# Ceil
+# ----
+
+def _test_ceil(data):
+    """ One iteration of ceil """
+    return _test_unary_elemwise(math_ops.ceil, data)
+#######################################################################
+# Floor
+# -----
+
+def _test_floor(data):
+    """ One iteration of floor """
+    return _test_unary_elemwise(math_ops.floor, data)
+#######################################################################
+# Exp
+# ---
+
+def _test_exp(data):
+    """ One iteration of exp """
+    return _test_unary_elemwise(math_ops.exp, data)
+#######################################################################
+# Log
+# ---
+
+def _test_log(data):
+    """ One iteration of log """
+    return _test_unary_elemwise(math_ops.log, data)
+#######################################################################
+# Sin
+# ---
+
+def _test_sin(data):
+    """ One iteration of sin """
+    return _test_unary_elemwise(math_ops.sin, data)
+#######################################################################
+# Cos
+# ---
+
+def _test_cos(data):
+    """ One iteration of cos """
+    return _test_unary_elemwise(math_ops.cos, data)
+#######################################################################
+# Sqrt
+# ----
+
+def _test_sqrt(data):
+    """ One iteration of sqrt """
+    return _test_unary_elemwise(math_ops.sqrt, data)
+#######################################################################
+# Rsqrt
+# -----
+
+def _test_rsqrt(data):
+    """ One iteration of rsqrt """
+    return _test_unary_elemwise(math_ops.rsqrt, data)
+#######################################################################
+# Neg
+# ---
+
+def _test_neg(data):
+    """ One iteration of neg """
+    return _test_unary_elemwise(math_ops.neg, data)
+#######################################################################
+
+def _test_forward_unary_elemwise(testop):
 
 Review comment:
   Yes. I think you should only need to change this too:
   
       if test_op in {'_test_log', '_test_sqrt', '_test_rsqrt'}:
           test_op(np.arange(6.0, dtype=np.float32).reshape((2, 1, 3)))
           test_op(np.arange(6.0, dtype=np.int32).reshape((2, 1, 3)))

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] inadob commented on a change in pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops

Posted by GitBox <gi...@apache.org>.
inadob commented on a change in pull request #4634: [Relay][Frontend][TFlite] Add parses support for unary elemwise ops
URL: https://github.com/apache/incubator-tvm/pull/4634#discussion_r363838587
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -616,6 +616,109 @@ def test_forward_concatenation():
          np.arange(6).reshape((2, 1, 1, 3)),
          np.arange(6).reshape((2, 1, 1, 3))], 1)
 
+#######################################################################
+# Unary elemwise
+# --------------
+
+def _test_unary_elemwise(math_op, data):
+    """ One iteration of unary elemwise """
+
+    with tf.Graph().as_default():
+        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype, name='in')
+        out = math_op(in_data)
+        compare_tflite_with_tvm(data, ['in:0'], in_data, [out])
+
+#######################################################################
+# Abs
+# ---
+
+def _test_abs(data):
+    """ One iteration of abs """
+    return _test_unary_elemwise(math_ops.abs, data)
+#######################################################################
+# Ceil
+# ----
+
+def _test_ceil(data):
+    """ One iteration of ceil """
+    return _test_unary_elemwise(math_ops.ceil, data)
+#######################################################################
+# Floor
+# -----
+
+def _test_floor(data):
+    """ One iteration of floor """
+    return _test_unary_elemwise(math_ops.floor, data)
+#######################################################################
+# Exp
+# ---
+
+def _test_exp(data):
+    """ One iteration of exp """
+    return _test_unary_elemwise(math_ops.exp, data)
+#######################################################################
+# Log
+# ---
+
+def _test_log(data):
+    """ One iteration of log """
+    return _test_unary_elemwise(math_ops.log, data)
+#######################################################################
+# Sin
+# ---
+
+def _test_sin(data):
+    """ One iteration of sin """
+    return _test_unary_elemwise(math_ops.sin, data)
+#######################################################################
+# Cos
+# ---
+
+def _test_cos(data):
+    """ One iteration of cos """
+    return _test_unary_elemwise(math_ops.cos, data)
+#######################################################################
+# Sqrt
+# ----
+
+def _test_sqrt(data):
+    """ One iteration of sqrt """
+    return _test_unary_elemwise(math_ops.sqrt, data)
+#######################################################################
+# Rsqrt
+# -----
+
+def _test_rsqrt(data):
+    """ One iteration of rsqrt """
+    return _test_unary_elemwise(math_ops.rsqrt, data)
+#######################################################################
+# Neg
+# ---
+
+def _test_neg(data):
+    """ One iteration of neg """
+    return _test_unary_elemwise(math_ops.neg, data)
+#######################################################################
+
+def _test_forward_unary_elemwise(testop):
 
 Review comment:
   That's how the binary elementwise operators were implemented. Do you want me to change both?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services