Pytorch-lightning: Expose lr_scheduler to pl.LightningModule as a property (self.scheduler)?

Created on 3 Nov 2020  Â·  6Comments  Â·  Source: PyTorchLightning/pytorch-lightning

What is your question?

Dear all,

Is lr_scheduler (or an array of them) exposed to pl.LightningModule as self.scheduler or something similar ? I only see self.trainer but self.scheduler would really complement the trainer!

What have you tried?

I tried looking for self.scheduler (and different variants) in the source / PDF manual but found nothing

What's your environment?

  • OS: CentOS 6
  • Packaging: conda
  • Version: 1.0.4
question

Most helpful comment

@seannz it's added here:
https://github.com/PyTorchLightning/pytorch-lightning/blob/a32bffcdea3c12fb369f2cb87cbcf8b7e91396e6/pytorch_lightning/accelerators/accelerator.py#L187-L194

Hey, I think you can access the scheduler by using trainer.lr_schedulers, therefore maybe you could access from your pl_module by using self.trainer.lr_schedulers

yes you can access it via self.trainer but I think it can be exposed to LightningModule as property just like optimizers

All 6 comments

Hi! thanks for your contribution!, great first issue!

Looks like we should be accessing it via self.trainer.schedulers (rather than directly via self.schedulers) for consistency with self.trainer.optimizers. I'll submit a PR soon.

Hey, I think you can access the scheduler by using trainer.lr_schedulers, therefore maybe you could access from your pl_module by using self.trainer.lr_schedulers

@MohammedAljahdali I don't see lr_schedulers anywhere in trainer.py. Would you mind pointing me to the right location where it is defined?

@seannz it's added here:
https://github.com/PyTorchLightning/pytorch-lightning/blob/a32bffcdea3c12fb369f2cb87cbcf8b7e91396e6/pytorch_lightning/accelerators/accelerator.py#L187-L194

Hey, I think you can access the scheduler by using trainer.lr_schedulers, therefore maybe you could access from your pl_module by using self.trainer.lr_schedulers

yes you can access it via self.trainer but I think it can be exposed to LightningModule as property just like optimizers

Was this page helpful?
0 / 5 - 0 ratings

Related issues

versatran01 picture versatran01  Â·  3Comments

srush picture srush  Â·  3Comments

as754770178 picture as754770178  Â·  3Comments

williamFalcon picture williamFalcon  Â·  3Comments

baeseongsu picture baeseongsu  Â·  3Comments