Self.parameters() or self.model.parameters()

class Model(LightningModule):
    def __init__(self):
        self.model = model  # Large nn.Module
...
    def configure_optimizers(self):
        # return Adam(self.parameters(), lr=0.1)
        return Adam(self.model.parameters(), lr=0.1)

For the above code example, is the optimizer getting the same parameters, right?

class ModelExtra(LightningModule):
    def __init__(self):
        self.model = model  # Large nn.Module
        self.classifier = nn.Linear(1000, 10)
...
    def configure_optimizers(self):
        # return Adam(self.parameters(), lr=0.1)
        return Adam(self.model.parameters(), lr=0.1)

For that above code example, the optimizer only gets model parameters not classifier parameters, right?

Correct. It will use only model parameters.

1 Like