This is not really what I need to do. I want the returned variable to be equal to the original w1 (this is by definition the Jacobian). For example the w1 is this:
tensor([[ 0.9947, -0.6104],
        [ 0.4867, -1.2023]], requires_grad=True)

If I call the function
l1 = torch.autograd.grad(y, x, grad_outputs=y.data.new(y.shape).fill_(1), create_graph=True)

I get this:
(tensor([[ 1.4815],
         [-1.8127]], grad_fn=<MmBackward>),)

This output gives, for some reason, the sum of the columns of the original matrix. Instead I want the actual original matrix i.e. the 2 by 2:
tensor([[ 0.9947, -0.6104],
        [ 0.4867, -1.2023]], requires_grad=True)