kevinthesun 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_r392361254
##########
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:
Yes. In the future we can add a pass automatically detect invariant part
inside loop/function, I'll add a TODO here.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services