Hi, I think that if a variable is being updated within the loop with a value, for which the computational graph was retained before, then the computational graph is expanding on each iterations. E.g. for some A, b and u = tensors which require grad:
def f(A, b, u):
    r = A@u - b
    return (r**2).sum()

for k in range(5):
    f_eval = f(A, input_b, y)
    grad = torch.autograd.grad(f_eval, y, create_graph=True)[0]
    y.grad = grad
    y = y - 0.001*y.grad
make_dot(grad)

See below for after 2 iterations:

test_depth415×1152 53.1 KB