Add gradient wrt to input in loss function

Hello, I am trying to add the gradient w.r.t. the input in the loss function but I am not sure how to do it. Can anyone help?