tf.config.run_functions_eagerly
Включает/выключает немедленное выполнение tf.function.
tf.config.run_functions_eagerly(
run_eagerly
)
Вызов tf.config.run_functions_eagerly(True) заставит все вызовы tf.function выполняться немедленно вместо выполнения как функции отслеживаемой графы.
Это может быть полезно для отладки.
def my_func(a):
print("Python side effect")
return a + a
a_fn = tf.function(my_func)
# A side effect the first time the function is traced a_fn(tf.constant(1)) Python side effect <tf.Tensor: shape=(), dtype=int32, numpy=2>
# No further side effect, as the traced function is called a_fn(tf.constant(2)) <tf.Tensor: shape=(), dtype=int32, numpy=4>
# Now, switch to eager running tf.config.run_functions_eagerly(True) # Side effect, as the function is called directly a_fn(tf.constant(2)) Python side effect <tf.Tensor: shape=(), dtype=int32, numpy=4>
# Turn this back off tf.config.run_functions_eagerly(False)
Примечание: Этот флаг не влияет на функции, переданные в преобразования tf.data в качестве аргументов. Функции tf.data никогда не выполняются немедленно и всегда выполняются как скомпилированная графа Tensorflow.
| Аргументы | |
|---|---|
run_eagerly | Булево значение. Необходимо ли выполнять функции немедленно. |
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.4/api_docs/python/tf/config/run_functions_eagerly