Could you explain why retain_graph=True is used, as it’s often not needed and some users have added it to avoid a previous error (which could then result in your reported issue in case your workflow is similar to this one).