Is tensorflow lazy?

后端 未结 1 832
借酒劲吻你
借酒劲吻你 2021-01-01 23:00

Let\'s say you have some piece of code like this

import tensorflow as tf
...
f = h*y + z*t  #Just some expression involving other tensors.
e = ... # some exp         


        
1条回答
  •  -上瘾入骨i
    2021-01-01 23:27

    TL;DR: TensorFlow is strict, so both e and f will be evaluated before the tf.select() node executes.

    This has caused some confusion. TensorFlow first prunes the dataflow graph based on which operations are statically required to produce the values that are fetched (i.e. the arguments to sess.run()). Once the graph has been pruned, however, the runtime uses strict execution, whereby all of the inputs to an operation (such as tf.select()) must have been computed before that operation can execute.

    There is experimental support for conditional execution in the tf.control_flow_ops module, using the tf.control_flow_ops.cond() function, but this is sparsely documented at present.

    0 讨论(0)
提交回复
热议问题