InnovArul:

I am not sure what do you mean by this


If I call .backward() I will get the gradient for all the leafs (the input as well as all the weights in the net) then I can optimize the net for all the leafs.
Moreover, I need the gradient w.r.t input data which I get it by data.grad.