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/03/13 03:57:37 UTC

[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5020: [Frontend][TensorFlow]TensorFlow Parser Control Flow Enhancement

zhiics commented on a change in pull request #5020: [Frontend][TensorFlow]TensorFlow Parser Control Flow Enhancement
URL: https://github.com/apache/incubator-tvm/pull/5020#discussion_r392017143
 
 

 ##########
 File path: python/tvm/relay/frontend/tensorflow.py
 ##########
 @@ -2029,6 +2096,73 @@ def if_node(self):
         return self._if
 
 
+class LoopBound(ExprVisitor):
+    """
+    When a loop body is create, we get a Relay expression backtracing all
+    the way back to input node. This will result in lots of unnecessary
+    expression placed into loop body and compute multiple times. For example,
+    consider the following tensorflow code:
+
+    .. code-block:: python
+
+        i = tf.constant(0)
+        data = tf.compat.v1.placeholder(tf.float32, shape=(1024, 1024))
+        slice = tf.strided_slice(data, 0, 512)
+        def c(i): return tf.less(i, 10)
+        def b(i): return [tf.add(i, 1), tf.add(i, 1) + slice]
+        r = tf.while_loop(c, b, [i])
+
+    If we directly create recursive function, slice will be placed into function body.
 
 Review comment:
   Maybe we need to add a loop-invariant code motion (LICM) pass so that we don't need to handle this in different frameworks. It can benefit general Relay program as well, though it is not necessarily in this PR.

----------------------------------------------------------------
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