You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You need to move the count_up_to op inside the conditional branch you want it to be executed.
a = tf.Variable(0)
def todo_if_true():
incr = a.count_up_to(1)
with tf.control_dependencies([incr]):
return tf.identity(a)
def todo_if_false():
return tf.identity(a)
g = tf.cond(tf.constant(False), todo_if_true, todo_if_false)
I have added the following paragraph to the doc:
Note that the conditional execution applies only to the operations defined in
fn1 and fn2. Consider the following simple program:
z=tf.mul(a, b)
result=tf.cond(x<y, lambda: tf.add(x, z), lambda: tf.square(y))
If x < y, the tf.add operation will be executed and tf.square
operation will not be executed. Since z is needed for at least one
branch of the cond, the tf.mul operation is always executed, unconditionally.
Although this behavior is consistent with the dataflow model of TensorFlow,
it has occasionally surprised some users who expected a lazier semantics.
tf.cond seems to have a bug if one of the condition have a dependency. (Dependencies are run, whatever tf.cond arg is True or False).
To illustrate:
Output:
The text was updated successfully, but these errors were encountered: