Because you re-use recon_loss and backward a second time over its graph. In your case, it seems to me that you can simply do as suggested and set retain_graph=True when calling backward the first times.