tf.inside_function

Indicates whether the caller code is executing inside a tf.function.

Example:

tf.inside_function()
False
@tf.function
def f():
  print(tf.inside_function())
f()
True