torch.autograd.grad
torch.autograd.grad(outputs, inputs, grad_outputs=None, retain_graph=None, create_graph=False, only_inputs=True, allow_unused=False, is_grads_batched=False)
Computes and returns the sum of gradients of outputs with respect
   to the inputs.
"grad_outputs" should be a sequence of length matching "output"
   containing the "vector" in vector-Jacobian product, usually the
   pre-computed gradients w.r.t. each of the outputs. If an output
   doesn't require_grad, then the gradient can be "None").
Note:
 If you run any forward ops, create "grad_outputs", and/or call
 "grad" in a user-specified CUDA stream context, see Stream
 semantics of backward passes.

Note:
 "only_inputs" argument is deprecated and is ignored now (defaults
 to "True"). To accumulate gradient for other parts of the graph,
 please use "torch.autograd.backward".

Parameters:
      * outputs (sequence of Tensor) -- outputs of the