Solved by albanD in post #2 
              
              
                Hi, 
Here is an example: 
a = torch.rand(10, requires_grad=True)
b = torch.rand(10, requires_grad=True)

output = (2 * a).sum()

torch.autograd.grad(output, (a, b))