Skip to content

Commit

Permalink
Examples: expose learning rate (Lightning-AI#17513)
Browse files Browse the repository at this point in the history
Co-authored-by: thomas <thomas@thomass-MacBook-Pro.local>
  • Loading branch information
tchaton and thomas committed Apr 28, 2023
1 parent 3867045 commit cafdc6d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/pytorch/basics/autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ class LitAutoEncoder(LightningModule):
)
"""

def __init__(self, hidden_dim: int = 64):
def __init__(self, hidden_dim: int = 64, learning_rate=10e-3):
super().__init__()
self.save_hyperparameters()
self.encoder = nn.Sequential(nn.Linear(28 * 28, hidden_dim), nn.ReLU(), nn.Linear(hidden_dim, 3))
self.decoder = nn.Sequential(nn.Linear(3, hidden_dim), nn.ReLU(), nn.Linear(hidden_dim, 28 * 28))

Expand All @@ -138,7 +139,7 @@ def predict_step(self, batch, batch_idx, dataloader_idx=None):
return self(x)

def configure_optimizers(self):
optimizer = torch.optim.Adam(self.parameters(), lr=1e-3)
optimizer = torch.optim.Adam(self.parameters(), lr=self.hparams.learning_rate)
return optimizer

def _prepare_batch(self, batch):
Expand Down

0 comments on commit cafdc6d

Please sign in to comment.