Hi Silviu,
torch.autograd.grad

computes the product of the jacobian with the vector given in ‘grad_outputs’. In ‘grad_outputs’ you give the vector [1., 1.].
grad_outputs=y.data.new(y.shape).fill_(1)

So what you see is the expected behaviour. To compute the jacobian, you have to multiply with [1., 0] to  extract the first column, then with [0., 1.] to extract the second column.
Here is the complete code:
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 = False)                                                                                         
y = w1@x                                                                                                                               
                                                                                                                                       
print(w1)                                                                                                                              
jacT = torch.zeros(2,2)                                                                                                                
for i in range(2):                                                                                                                     
    output = torch.zeros(2,1)                                                                                                          
    output[i] = 1.                                                                                                                     
    jacT[:,i:i+1] = torch.autograd.grad(y, x, grad_outputs=output, retain_graph=True)[0]

Does this help?