x = torch.tensor([[1., -1.], [1., 1.]], requires_grad=True)
out = x.pow(2).sum()
out.backward()
x.grad

this is a example on torch.Tensor — PyTorch 1.10.1 documentation
the output is tensor([[ 2.0000, -2.0000], [ 2.0000, 2.0000]])
but my pytorch also have the same error
element 0 of tensors does not require grad and does not have a grad_fn