View source on GitHub
|
Enables / disables eager execution of tf.functions.
tf.config.run_functions_eagerly(
run_eagerly
)
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.
def my_func(a):print("Python side effect")return a + aa_fn = tf.function(my_func)
# A side effect the first time the function is traceda_fn(tf.constant(1))Python side effect<tf.Tensor: shape=(), dtype=int32, numpy=2>
# No further side effect, 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)# Side effect, as the function is called directlya_fn(tf.constant(2))Python side effect<tf.Tensor: shape=(), dtype=int32, numpy=4>
# Turn this back offtf.config.run_functions_eagerly(False)
Args | |
|---|---|
run_eagerly
|
Boolean. Whether to run functions eagerly. |
View source on GitHub