tirthasheshpatel:

Shouldn’t the model train even if I have encoder and decoder as seperate modules and not shoved in nn.Module class? I may be wrong there as I have just started using torch.


You are right and it shouldn’t make a difference, as the computation graph will be the same.
It might be a typo or copy-paste issue, but your optimizer in the first approach takes the parameters from model, which is undefined. It should get the parameters of encoder and decoder so that it can update these parameters using their gradients.
Could you check this particular line of code?
If this is indeed a typo, could you try to rerun both approaches for a couple of epochs using different seeds and check how reproducible the effect is, that the second approach trains better than the first?