Yes, your code and idea look correct.



 Laura_Montalvo:

After that I froze the encoder parameter so the backprop does not actualize them. Is that correct too?


Yes, this looks also correct. You could verify it quickly by running a single update (e.g. using random inputs and targets) and check the gradients of all parameters.
The .grad attributes of all parameters of model.encoder should be None:
for param in model.encoder.parameters():
    print(param.grad)