Gradient calculation not disabled in no_grad() PyTorch
Why is the gradient calculation of y not disabled in the following piece of code?

x = torch.randn(3, requires_grad=True)
print(x.requires_grad)
print((x ** 2).requires_grad)
y = x**2
print(y.requires_grad)
with torch.no_grad():
    print((x ** 2).requires_grad)
    print(y.requires_grad)


Which gives the following output:

True
True
True
False
True


Going through the official documentation says that the results would have require_grad=False even though the inputs have required_grad=True


  Disabling gradient calculation is useful for inference, when you are sure
      that you will not call :meth:Tensor.backward(). It will reduce memory
      consumption for computations that would otherwise have requires_grad=True.
      In this mode, the result of every computation will have
      requires_grad=False, even when the inputs have requires_grad=True.

