Thanks again for the explanation
I have the following after output.backward() statement
inpt2_grad = grad(output, inp2, torch.ones(inp2.size()[0], 1, device=dev), create_graph=True, retain_graph=True)
inpt2_grad       = inpt2_grad.cpu().numpy()
I get the following error at the line where I have: inpt2_grad = grad(output, inp2, torch…
Mismatch in shape: grad_output[0] has a shape of torch.Size([15625, 1]) and output[0] has a shape of torch.Size([]).