well your loss is backpropagated in your network starting from the end.
Grad_input is the gradient entering the layer from behind and grad_output is the gradient exiting the layer from the front of it.