Solved by albanD in post #2 
              
              
                Hi, 

You need to use retain_graph because .backward() goes through the whole graph (both encode/decoder here). And so if you want to be able to backward in the decoder again you need to retain_graph.
You can use retain_graph if you don’t change any value required by the backward. In particular here…