Behavior of Graph Tracing for TF-Object Vs Python Object

Hi,
Please consider the following code snippet.

import tensorflow as tf
@tf.function
def f(n):
    while (n>0):
        print("Trace: ", n)
        tf.print("execution:" , n)
        n = n -1

Case 1: When we call the above function with TF-Objects arguments, the following is the output.

f(tf.constant(3))
print("next")
f(tf.constant(3))
Trace:  Tensor("while/Placeholder:0", shape=(), dtype=int32)
execution: 3
execution: 2
execution: 1
next
execution: 3
execution: 2
execution: 1

Case 2: When we call the above function with Python Object, the following is the output.

f(3)
print("next")
f(3)
Trace:  3
Trace:  2
Trace:  1
execution: 3
execution: 2
execution: 1
next
execution: 3
execution: 2
execution: 1

In case 2, behavior is almost similar to case 1. Why?
In case 2 with Python-Object call, There is no tracing print for the second call. Why is that?

Hi @Alok_Ranjan_Srivasta

The output behavior will be same in both the cases as the input argument is same except the extra tracing because Python arguments always trigger the creation of a new graph

Please refer to the link for more understanding on When is a tf.function tracing and Rule of tracing.