In pytorch, the meaning of y.backward([0.1, 1.0, 0.0001])
In pytorch
what is the meaning of y.backward([0.1, 1.0, 0.0001])?

I understand that y.backward() means doing backpropagation.
But what is the meaning of [0.1, 1.0, 0.0001] in y.backward([0.1, 1.0, 0.0001])?

The expression y.backward([0.1, 1.0, 0.0001]) is actually wrong. It should be y.backward(torch.Tensor([0.1, 1.0, 0.0001])), where torch.Tensor([0.1, 1.0, 0.0001]) are the Variables of which the derivative will be computed. 





Example:

x = Variable(torch.ones(2, 2), requires_grad=True)
y = (x + 2).mean()
y.backward(torch.Tensor([1.0]))
print(x.grad)


Here, y = (x + 2)/4 and so, dy/dx_i = 0.25 since x_i = 1.0. Also note, y.backward(torch.Tensor([1.0])) and y.backward() are equivalent. 

If you do:

y.backward(torch.Tensor([0.1]))
print(x.grad)


it prints:

Variable containing:
1.00000e-02 *
  2.5000  2.5000
  2.5000  2.5000
[torch.FloatTensor of size 2x2]


It is simply 0.1 * 0.25 = 0.025. So, now if you compute:

y.backward(torch.Tensor([0.1, 0.01]))
print(x.grad)


Then it prints:

Variable containing:
1.00000e-02 *
  2.5000  0.2500
  2.5000  0.2500
[torch.FloatTensor of size 2x2]


Where, dy/dx_11 = dy/d_x21 = 0.025 and dy/dx_12 = dy/d_x22 = 0.0025.

See the function prototype of backward(). You may consider looking into this example.
