I’ve define a auto-encoder model as below.

class AE(nn.Module):
def init(self, img_c, z_dim):
super(AE, self).init()
self.enc = Encoder(img_c, z_dim)
self.gen = Generator(z_dim, img_c)
self.model = nn.Sequential(
self.enc,
self.gen
)
def forward(self, x):
return self.model(x)
Encoder and Generator are another class(nn.Module) I have designed.
First, I want to train the whole network which can be easily done with

ae = AE()
ae.zero_grad()
ae_loss.backward()
opt_ae.step()

Second, I want to only train Encoder not the whole network.
How can I specifically train only the Encoder part of the model?