How to set requires_grad

Hi,

requires_grad is a field on the whole Tensor, you cannot do it only on a subset of it.
You will need to do a.requires_grad=True and then extract the part of the gradient of interest after computing all of it: a.grad[0][0].

4 Likes