Hi guys,
I am struggliing to understand the behaviour of non scalar Tensors when backward is called on them.

import torch
a = torch.Tensor([1,2,3])
a.requires_grad = True
b = 2*a
b.backward(gradient=torch.Tensor([1, 1, 1]))
a.grad
Out[100]: tensor([ 2.,  2.,  2.])
What is the value in a.grad?
Is it <db1/da1, db2/da2, db3/da3>? Then what is the purpose of the gradient argument.
If you leave the gradient argument with size 1 it gives a scalar in a.grad.

a = torch.Tensor([1,2,3])
a.requires_grad = True
b = 2*a
b.backward(gradient=torch.Tensor([1]))
a.grad
tensor([ 2.])
What is this scalar representing, as the gradient is a vector?
It would be great if someone can bring more light on this.
Regards,
Deyan