Tensorflow 在eager代码中并行执行TF-ops?

Tensorflow 在eager代码中并行执行TF-ops?,tensorflow,tensorflow2.0,Tensorflow,Tensorflow2.0,假设我有以下代码(): 据我所知(),该代码即使在disable\u eager\u execution时也能工作,而且f中的代码使用eager模式 在图形模式下,所有TF操作并行运行(当它们的输入或控制依赖项可用时) 急切模式下的TF操作是否始终按顺序运行?在这个代码示例中,tf.print(“hello”)可能独立执行。虽然我不知道是否存在任何隐式控件依赖项(循环的一部分;但它是否依赖于tf.print(x)?)。也许tf.print在这里也是个例外 有没有办法在急切模式下并行运行TF操作

假设我有以下代码():

据我所知(),该代码即使在
disable\u eager\u execution
时也能工作,而且
f
中的代码使用eager模式

在图形模式下,所有TF操作并行运行(当它们的输入或控制依赖项可用时)

急切模式下的TF操作是否始终按顺序运行?在这个代码示例中,
tf.print(“hello”)
可能独立执行。虽然我不知道是否存在任何隐式控件依赖项(循环的一部分;但它是否依赖于
tf.print(x)
?)。也许
tf.print
在这里也是个例外

有没有办法在急切模式下并行运行TF操作

tf.compat.v1.disable_eager_execution()

@tf.function
def f(x):
  while tf.reduce_sum(x) > 1:
    tf.print(x)
    tf.print("hello")
    x = tf.tanh(x)
  return x

with tf.compat.v1.Session() as session:
  session.run(f(tf.random.uniform([5])))