Hi, I read this blog here: https://blog.paperspace.com/pytorch-101-understanding-graphs-and-automatic-differentiation/ 8
What I got is:
1/ when you want a tensor to be part of the graph, you need to specify: requires_grad  =True
So, for your first  example, x,t,a, y and x_out (requires_grad being contagious) are all going to be in the dynamic computation graph once you do the forward pass (ie y = t @ a also x_out=t @ (x + y) and loss = measure())
If we define a leaf node as a tensor you create without the need of a function( say add, multiply etc) then t and a are leaf nodes
2/All the non-leafs nodes will be erased once you do the backward pass. So, y and x_out’s values will be erased from the graph as well as the other gradients say dy/dt , dy/da, dx_out/dt, dx_out/dy etc
3/For there to not be an error, one has to do forward() then backward(). But since you only recalculated x_out and loss but not y again in the loop, you didn’t do a complete forward(). Thus the error happened.
Hope this helps!