Thanks @albanD, it works now but I get different output for x.grad if I use
Output 1: (out.backward(torch.tensor([2.0])) in pytorch version 1.2)
A 2x2 square matrix where each values is 6
Output 2: (out.backward(torch.tensor(2.0)) in pytorch version 1.3)
A 2x2 square matrix where each values is 9
May you please explain the difference in results?
Values of x,y and z are as follows:
x = torch.ones(2, 2)
x.requires_grad_(True)
y = x+2
z = y * y * 3
out = z.mean()
out.backward(torch.tensor(2.0))
print(x.grad)
OUTPUT - tensor([[9., 9.],
[9., 9.]])
or
tensor([[6., 6.],
[6., 6.]])