Tensor.backward, as per documentation, frees the computation graph after the call to backward unless retain_graph is set to True. This is the exactly the behaviour I observed for the following example.

x = torch.ones(1., requires_grad=True)
y = torch.ones(1., requires_grad = True)
w = x+y
u=2*w
u.backward()
u.backward()

2nd backward call results error which matches with what docs say.
But for the following example, I don’t find any error.

x = torch.ones(1., requires_grad=True)
y = torch.ones(1., requires_grad = True)
w = x+y
w.backward()
w.backward()

Kindly clarify. This post is similar to https://discuss.pytorch.org/t/inconsistent-behavior-for-running-backward-twice-without-retain-graph-true/39917 4