-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
configure_optimizers with OneCycleLR and Pretrain Freeze/Unfreeze #1120
Comments
Hi! thanks for your contribution!, great first issue! |
I'm pretty new to pytorch-lightning but I'm also struggling with this issue to use BERT's LR schedule, which as far as I understand is exactly OneCycleLR, but without freeze/unfreeeze. It seems to me that the freeze/unfreeze can be done with a custom Callback and |
Possibly related issues: #1038 #941. @fabiocapsouza thanks, taking your input, I'm setting up my code as below, where I pass in the epoch via Additionally, OneCycleLR needs to be updated on every batch and it appears the default is to step the lr scheduler every epoch, rather than batch. I believe the return needs to look something like this based on #941 but I am not sure - the documentation isn't clear on this.
|
@wxc-kumar your code is correct, to make lightning call |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
An important moment on setting OneCycleLR parameters: steps_per_epoch = (train_loader_len//self.batch_size)//self.trainer.accumulate_grad_batches |
It doesn't look like the documentation was ever updated to mention that "interval" must be set to "step". It is very hard for new users to figure this out by themselves. |
Hey @cowwoc, Mind making a contribution to improve the documentation. Best, |
You are right, my mistake. |
I know this is an old thread, but did you mean to say: steps_per_epoch = len(train_loader) // self.trainer.accumulate_grad_batches Not sure how batch size is relevant here since the update step is per batch anyway. |
Hello. Thanks for the work on this framework - it's something I've been looking for and I am currently working on transition all my own work from fast.ai to pytorch-lightining. I'm currently stuck on the
configure_optimizers
step.For those not familiar, the core workflow of fast.ai goes something like this:
fast.ai uses it's own system for implementing the OneCycleScheduler and it's not the most transparent system. PyTorch has an implementation of the OneCycleScheduler which their documentation illustrates as follows:
Note that
OneCycleLR
needs to know the total number of steps (or steps per epoch + epochs, from which it determines total steps) in order to generate the correct schedule.configure_optimizers
does not appear to offer a way of accessing the necessary values to initializeOneCycleLR
, as in my code below.Additionally, it's unclear how the fast.ai flow of freeze, train, unfreeze, train work with Lightning as it appears that
configure_optimizers
is called once internally by the trainer. It appears it may be possible to train frozen, checkpoint, load and unfreeze but this does add some extra code overhead.How can I arrange my code to use
OneCycleLR
with pretrained freezing/unfreezing? Any guidance on how to approach this would be appreciated.Thanks.
The text was updated successfully, but these errors were encountered: