Calling tf.config.run_functions_eagerly(True) will make all
invocations of 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.
# A side effect the first time the function is traced# In tracing time, `a` is printed with shape and dtype onlya_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 calleda_fn(tf.constant(2))<tf.Tensor:shape=(),dtype=int32,numpy=4>
# Now, switch to eager runningtf.config.run_functions_eagerly(True)# The code now runs eagerly and the actual value of `a` is printeda_fn(tf.constant(2))a:2<tf.Tensor:shape=(),dtype=int32,numpy=4>
# Turn this back offtf.config.run_functions_eagerly(False)
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tf.config.run_functions_eagerly\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/eager/polymorphic_function/eager_function_run.py#L31-L76) |\n\nEnables / disables eager execution of [`tf.function`](../../tf/function)s.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.config.run_functions_eagerly`](https://www.tensorflow.org/api_docs/python/tf/config/run_functions_eagerly)\n\n\u003cbr /\u003e\n\n tf.config.run_functions_eagerly(\n run_eagerly\n )\n\nCalling [`tf.config.run_functions_eagerly(True)`](../../tf/config/run_functions_eagerly) will make all\ninvocations of [`tf.function`](../../tf/function) run eagerly instead of running as a traced graph\nfunction. This can be useful for debugging. As the code now runs line-by-line,\nyou can add arbitrary `print` messages or pdb breakpoints to monitor the\ninputs/outputs of each Tensorflow operation. However, you should avoid using\nthis for actual production because it significantly slows down execution. \n\n def my_func(a):\n print(f'a: {a}')\n return a + a\n a_fn = tf.function(my_func)\n\n # A side effect the first time the function is traced\n # In tracing time, `a` is printed with shape and dtype only\n a_fn(tf.constant(1))\n a: Tensor(\"a:0\", shape=(), dtype=int32)\n \u003ctf.Tensor: shape=(), dtype=int32, numpy=2\u003e\n\n # `print` is a python side effect, it won't execute as the traced function\n # is called\n a_fn(tf.constant(2))\n \u003ctf.Tensor: shape=(), dtype=int32, numpy=4\u003e\n\n # Now, switch to eager running\n tf.config.run_functions_eagerly(True)\n # The code now runs eagerly and the actual value of `a` is printed\n a_fn(tf.constant(2))\n a: 2\n \u003ctf.Tensor: shape=(), dtype=int32, numpy=4\u003e\n\n # Turn this back off\n tf.config.run_functions_eagerly(False)\n\n| **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.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|--------------------------------------------|\n| `run_eagerly` | Boolean. Whether to run functions eagerly. |\n\n\u003cbr /\u003e"]]