<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/eager/polymorphic_function/eager_function_run.py#L31-L76) |

Enables / disables eager execution of [`tf.function`](https://www.tensorflow.org/api_docs/python/tf/function)s.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.config.run_functions_eagerly`](https://www.tensorflow.org/api_docs/python/tf/config/run_functions_eagerly)

<br />

    tf.config.run_functions_eagerly(
        run_eagerly
    )

### Used in the notebooks

| Used in the guide |
|---|
| - [Introduction to graphs and tf.function](https://www.tensorflow.org/guide/intro_to_graphs) |

Calling [`tf.config.run_functions_eagerly(True)`](https://www.tensorflow.org/api_docs/python/tf/config/run_functions_eagerly) will make all
invocations of [`tf.function`](https://www.tensorflow.org/api_docs/python/tf/function) run eagerly instead of running as a traced graph
function. This can be useful for debugging. As the code now runs line-by-line,
you can add arbitrary `print` messages or pdb breakpoints to monitor the
inputs/outputs of each Tensorflow operation. However, you should avoid using
this for actual production because it significantly slows down execution.

    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)

> [!NOTE]
> **Note:** This flag has no effect on functions passed into tf.data transformations as arguments. tf.data functions are never executed eagerly and are always executed as a compiled Tensorflow Graph.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `run_eagerly` | Boolean. Whether to run functions eagerly. |

<br />