Hi,
First, make sure your inputs require gradients:

If they don’t, just call requires_grad_() on them before giving them to your net
If they do and are leaf (inp1.is_leaf()) then you’re good to go
If they do but are not leafs, you can do inp1.retain_grad() to make sure the .grad field will be populated properly.

Then if output is a scalar, you can simply .backward() on the output.
Otherwise, if you want the full jacobian, you can use the torch.autograd.functional package from pytorch 1.5.
If you want the sum of the gradients for each element in the output, you can do output.sum().backward().