I’m trying to normalize an array(tensor) so that they sum to 1.
I did the following computation, however, the output gradient seems to be wrong. ( why are they all the same?? they should be different with respect to each element in  a
code:
a = torch.rand(10, requires_grad=True)
print(a)
x = torch.sum(a)
y = a / x
y.backward(torch.ones_like(a))
pp(a.grad)

output:
tensor([0.6022, 0.6065, 0.0329, 0.3639, 0.2053, 0.1006, 0.6993, 0.1843, 0.0400,
        0.2939], requires_grad=True)
tensor([-5.9605e-08, -5.9605e-08, -5.9605e-08, -5.9605e-08, -5.9605e-08,
        -5.9605e-08, -5.9605e-08, -5.9605e-08, -5.9605e-08, -5.9605e-08])