As from tutorial , I was using b.backward() function, it throws same err when printing b.grad
My code is:
a = torch.randn(2,2)
a = ((a*3)/ (a-1))
a.requires_grad_(True)
b = (a * a).sum()
b.backward()
print(b.grad)

Throws error
None
/usr/local/lib/python3.6/dist-packages/torch/tensor.py:746: UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward(). If you indeed want the gradient for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor. If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more informations.
  warnings.warn("The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad "

help, Thank you for response  .