I think so. You should definitely try to remove the retain_graph=True usage unless you have a very specific reason to use it. In a lot of cases this attribute is used as a workaround and creates other issues unfortunately, as it’s not fitting into the actual use case.