Hello! I want to get the Jacobian matrix using Pytorch automatic differentiation. I have this code so far:
x = np.arange(1,3,1)
x = torch.from_numpy(x).reshape(len(x),1)
x = x.float()
x.requires_grad = True

w1 = torch.randn((2,2), requires_grad = True)
y = w1@x

jac = torch.autograd.grad(y, x, grad_outputs=y.data.new(y.shape).fill_(1), create_graph=True)

So I want jac to recover w1. But in this form, jac has the same dimensions as y and I am not sure what to do. Can someone tell me how to fix that function such that I get what I need? Thank you!