Can autograd be used when the final tensor has more than a single value in it?
I tried the following.
x = torch.tensor([4.0, 5.0], requires_grad=True)
y = x ** 2
print(y)
y.backward()
Throws an error
RuntimeError: grad can be implicitly created only for scalar outputs
The following however works.
x = torch.tensor([4.0, 5.0], requires_grad=True)
y = x ** 2
y = torch.sum(y)
print(y)
y.backward()
print(x.grad)
The output is as
tensor(41., grad_fn=<SumBackward0>)
tensor([ 8., 10.])
Am I missing something here or can I proceed with the assumption that autograd only works when the final tensor has a single value in it?