I recently study Pytorch and backward function of the package. I understood how to use it, but when I try
x = Variable(2*torch.ones(2, 2), requires_grad=True)
x.backward(x)
print(x.grad)
I expect
tensor([[1., 1.],
[1., 1.]])
because it is an identity function. However, it returns
tensor([[2., 2.],
[2., 2.]]).
Why this happens?