Training when encoder-decoder model

This is my simplified model structure

class Encoder(nn.Module):
    def __init__(self, ...):

encoder = Encoder()

class Decoder(nn.Module):
    def __init__(self, encoder, ...):

Decoder net has encode model in it.
Then when i train this model, should I optimize both models like

encoder_optimizer = optim.SGD(encoder.parameters(), lr=learning_rate)
decoder_optimizer = optim.SGD(decoder.parameters(), lr=learning_rate)

or just decoder?

Print decoder.parameters() shapes to see what parameters, the Decoder contains. If it contains Encoder parameters as well, you may only optimize the Decoder.

1 Like

if you call the encoder in the decoder’s forward function, one optim is enough.