# What is the function decorator doing?

Hi,

I was going through Course 4 Week 4 Assignment 2. I came accross this line in Cell 4:

Can I know what is the role of that decorator?
What really perplexes me is why only here? Why not for all other functions we have been asked to implement as part of various programming exercises this function decorator was not there?
Thanks

The decorator makes graphs of those functions, this helps with performance increase as well portability, Why that function only? Perhaps that function bears most of other functions inside it or lifts the heavy loadâ€¦

2 Likes

Can you please elaborate more on it? I didnâ€™t get the phrase â€śgraphs of those functionsâ€ť. I suppose the GradientTape was doing that right?

It converts a Python function (Eager mode) to a TensorFlow function (Graph mode). One simple example of how graph execution optimizes operations is:
Suppose we have the below equation:
y = \frac{16}{2} + 2 + 2 - 5*10 .

So, in Python, it will be done sequentially but in TF (Graph mode) it will do independent operations in parallel (at the same time). For example, TF will do 16/2 and 2+2 at the same time and then add the results while Python will first do 16/2 and then 2+2 and then add the results.

To conclude, Eager execution has to wait for the other operations to complete while Graph execution can do independent calculations in parallel.

1 Like

Oh I see. So the tf decorator utilizes graph in the sense of parallel computation while the gradient tape utilizes graph in the sense of recording the nodes required for computing backpropagation right?

Toy understanding:

the graph is like a fixed mapped predetermined process, like a circuit lets say frozen.

I am not sure if tf gradient includes the tf decorator but maybe it does, its function is compute gradients forward and back propagation!

Ok thanks. But can you also tell if my last reply is correct?

This is my understanding of it!

Ok thanks a lot

1 Like