Hi,
I think the option you want to use is create_graph not retain_graph. Doc is here 20. I guess output is part of the graph you go through and so it messes things up as it’s not creating a higher order graph, just keeping the existing one.