Based on your code it doesn’t seem that the output of the encoder is fed to the decoder, so the calculated loss of the decoder won’t create any gradients in the encoder.
If you are worries about best practices in PyTorch:

check, if you really need to use retain_graph since based on your code snippet it doesn’t seem as if it’s needed

Variables are deprecated so you can use tensors after PyTorch 0.4