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

jcreinhold picture jcreinhold  路  3Comments

Vichoko picture Vichoko  路  3Comments

srush picture srush  路  3Comments

williamFalcon picture williamFalcon  路  3Comments

DavidRuhe picture DavidRuhe  路  3Comments