The modules in TensorFlow are developed to assist its core principle \u2014 make tensors flow through a graph \u2014 just as the name suggests. From the numbers that are used to represent the models to the operations themselves, everything is a part of a graph. And this creates some hurdles for those who are starting out with machine learning.\r\n\r\nThis graph-based functioning creates problems when one has to debug their code written with TensorFlow. Writing a perfect machine learning model that behaves well is a hyperbole. And, any developer would like to sneak in on to the code in between and monitor it with the help of partial results.\r\n\r\nThat is why the team at TensorFlow came up with an Eager mode.\u00a0\r\nWhat Is Eager Mode?\r\nIn this mode, a practitioner has to run a single line of code to enable the eager execution module on TensorFlow and keep a track of their code. This makes it easy to get started with TensorFlow and debug models. In Tensorflow 2.0, eager execution is enabled by default.\r\n\r\nTensorFlow eagerly executes the operations thus allowing the developer to see the results on the go rather than wait for the whole model to be executed.\u00a0\r\n\r\n<code>tf.executing_eagerly()<\/code>\r\n\r\nEnabling eager execution changes how TensorFlow operations behave \u2014 now they immediately evaluate and return their values to Python.\u00a0\r\n\r\nFor example, performing a simple matrix multiplication would require the following:\r\n\r\nimport tensorflow as tf\r\n\r\nx = [ [1,2],\r\n\r\n [3,4] ]\r\n\r\nm = tf.matmul(x,x)\r\n\r\nprint(m)\r\n\r\nThis would print an output which is not so insightful:\r\n\r\nTensor(\u201cMatMul:0\u201d, shape = (2,2), dtype = int32); which is not so insightful.\r\n\r\nTo make any sense of what a certain chunk of the model is undergoing, one would need to run a session:\r\n\r\nwith tf.Session() as sess:\r\n\r\n print(sess.run(m))\r\n\r\n[ [7 10]\r\n\r\n[15 22] ]\r\n\r\nSo, to pull out the values one has to wrap the operation in a session. This becomes tedious with complicated tasks.\r\n\r\nHowever, when eager mode is enabled:\r\n\r\ntf.enable_eager_execution() \r\n\r\ntf.executing_eagerly()\r\n\r\nThe above lines followed by\r\n\r\nprint(m) \r\n\r\nWould give the following output:\r\n\r\ntf.Tensor( [ [ 7 10] [ 15 22] ], shape= (2,2), dtype = int32)\r\nWhy Eager Mode Matters\r\nThe fundamental operations in a typical neural network can be reduced to a bunch of addition and multiplication operations. Whether it is a convolutional neural network to recognise images or a language model to perform sentiment analysis, these basic arithmetic operations play a huge role. As shown above, if a 2x2 matrix needs a session wrapper to pull out numbers, imagine a large model running on high dimensional data. The whole process becomes exhaustive and inefficient.\u00a0\r\n\r\nEager execution works nicely with NumPy. NumPy operations accept tf.Tensor arguments. TensorFlow math operations convert Python objects and NumPy arrays to tf.Tensor objects. The tf.Tensor.numpy method returns the object's value as a NumPy ndarray.\r\n\r\nLet\u2019s take a look at two examples where eager execution helps the developer:\r\n\r\nTensor Operations\r\n\r\nWhen Eager Execution is disabled, the tensor manipulation is limited. For example, tensor operations will yield a tensor object and not the result of the operations. Refer to the code example below.\r\n\r\n \r\n\r\n\r\n\r\nModel Output Before Training\r\n\r\nEven without training, call the model and inspect the output in eager execution. A TensorFlow model needs to be compiled and trained before it can produce an output but with Eager Execution the training can be by-passed and the output can be inspected for a given input.\u00a0\r\n\r\n \r\n\r\n\r\n\r\nAlong with the advantages discussed above, the eager mode can also help the developers to call the model without training and inspect the output in eager execution.\r\n\r\nThe benefits of Eager execution, as told by the developers at TensorFlow, can be summarised as follows:\u00a0\r\n\r\n \tQuickly iterate on small models and small data.\r\n \tEasier debugging.\r\n \tSupport for dynamic models using easy-to-use Python control flow\r\n \tStrong support for custom and higher-order gradients\r\n \tAlmost all of the available TensorFlow operations.\r\n\r\nDebugging lies at the core of any programming task. Write, check for errors, debug and repeat. The sooner the errors are identified, the sooner the chances of a model getting deployed. The eager mode in TensorFlow is one such option to make use of this widely opted framework in a more efficient way.