mk100000:

params2 = network(x,fc_weights)
params2.retain_grad() # keep intermediate grads
print(params2.is_leaf) # prints False
params3 = network(params2,fc_weights)
params3.retain_grad() # keep intermdiate grads
print(params3.is_leaf) # prints False
print()



You are re-defining (or re-assigning) params2 and params3 again in these lines.
They are not holding the variables that you defined initially.