tf.config.run_functions_eagerly
Включает или отключает eager-выполнение функций tf.function.
tf.config.run_functions_eagerly(
run_eagerly
)
Используется в блокнотах
| Используется в руководстве |
|---|
Вызов tf.config.run_functions_eagerly(True) приведет к тому, что все вызовы tf.function будут выполняться в eager-режиме, а не как трассируемая графовая функция. Это может быть полезно для отладки. Поскольку теперь код выполняется построчно, можно добавлять произвольные print сообщения или точки останова pdb, чтобы отслеживать входные и выходные данные каждой операции TensorFlow. Однако не следует использовать этот режим в рабочей среде, поскольку он значительно замедляет выполнение.
def my_func(a):
print(f'a: {a}')
return a + a
a_fn = tf.function(my_func)# A side effect the first time the function is traced
# In tracing time, `a` is printed with shape and dtype only
a_fn(tf.constant(1))
a: Tensor("a:0", shape=(), dtype=int32)
<tf.Tensor: shape=(), dtype=int32, numpy=2># `print` is a python side effect, it won't execute 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) # The code now runs eagerly and the actual value of `a` is printed a_fn(tf.constant(2)) a: 2 <tf.Tensor: shape=(), dtype=int32, numpy=4>
# Turn this back off tf.config.run_functions_eagerly(False)
Примечание: Этот флаг не влияет на функции, передаваемые в преобразования tf.data в качестве аргументов. Функции tf.data никогда не выполняются в eager-режиме и всегда выполняются как скомпилированный граф TensorFlow.
| Аргументы | |
|---|---|
run_eagerly | Логическое значение. Определяет, следует ли выполнять функции в eager-режиме. |
© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/config/run_functions_eagerly