tf.config.run_functions_eagerly
Включает/выключает жадное выполнение tf.function.
tf.config.run_functions_eagerly(
run_eagerly
)
Использование в блокнотах
| Используется в руководстве |
|---|
Вызов tf.config.run_functions_eagerly(True) заставит все вызовы tf.function выполняться жадно вместо выполнения как отслеживаемой функции графика. Это может быть полезно для отладки. Поскольку код теперь выполняется построчно, вы можете добавлять произвольные 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 никогда не выполняются жадно и всегда выполняются как скомпилированный график Tensorflow.
| Аргументы | |
|---|---|
run_eagerly | Булево значение. Нужно ли выполнять функции жадно. |
© 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