Skip to content

Commit

Permalink
Make use of learning rate scheduler optional (ashleve#449)
Browse files Browse the repository at this point in the history
* Made `trainer.configure_optimizers()` robust to unspecified learning rate schedulers
  • Loading branch information
amorehead authored Oct 5, 2022
1 parent 89f9f02 commit ad0f46c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/models/mnist_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,18 @@ def configure_optimizers(self):
https://pytorch-lightning.readthedocs.io/en/latest/common/lightning_module.html#configure-optimizers
"""
optimizer = self.hparams.optimizer(params=self.parameters())
scheduler = self.hparams.scheduler(optimizer=optimizer)

return {
"optimizer": optimizer,
"lr_scheduler": {
"scheduler": scheduler,
"monitor": "val/loss",
"interval": "epoch",
"frequency": 1,
},
}
if self.hparams.scheduler is not None:
scheduler = self.hparams.scheduler(optimizer=optimizer)
return {
"optimizer": optimizer,
"lr_scheduler": {
"scheduler": scheduler,
"monitor": "val/loss",
"interval": "epoch",
"frequency": 1,
},
}
return {"optimizer": optimizer}


if __name__ == "__main__":
Expand Down

0 comments on commit ad0f46c

Please sign in to comment.