Hi,
I do not understand the concept of eager tensor and eager execution. ChatGPT gave me this explanation but, still, I am not clear:
In the traditional graph-based execution model, TensorFlow operations are first defined within a graph, and then the graph is executed within a session. The graph represents the flow of data and operations, and computations are performed by executing the graph in a session. This model provides benefits such as optimization and the ability to distribute computations across multiple devices or machines. However, it can be less intuitive and interactive for certain tasks, such as debugging or working with small-scale models.
With eager execution, TensorFlow operations are executed immediately and the results are returned directly. This allows for a more intuitive and interactive development experience, similar to how you would write regular Python code. It enables you to use Python control flow statements (e.g., loops and conditionals) to dynamically control the execution of operations, and it simplifies the process of inspecting intermediate results and debugging TensorFlow code.
And example is:
import tensorflow as tf
# Graph-based execution
tf.compat.v1.disable_eager_execution()
a = tf.constant(2)
b = tf.constant(3)
c = tf.add(a, b)
print(c)
Output: Tensor("Add:0", shape=(), dtype=int32)
# Eager execution
tf.compat.v1.enable_eager_execution()
d = tf.constant(2)
e = tf.constant(3)
f = tf.add(d, e)
print(f)
Output: tf.Tensor(5, shape=(), dtype=int32)
Best,
Saif.
PS: This query does not belong to any of the course assignments but a few months ago, I saw some error of eager tensor in DLS 4.