Skip to content
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

Adding the option to use a learning rate schedule during training. #223

Open
dreivmeister opened this issue Aug 2, 2024 · 0 comments
Open

Comments

@dreivmeister
Copy link

dreivmeister commented Aug 2, 2024

I was thinking that adding the option to use a PyTorch learning rate scheduler could improve results and wont be hard to implement.

I guess one could do it like that:

parameters = [p for net in nets for p in net.parameters()]  # list of paramters of all networks
MY_LEARNING_RATE = 5e-3
optimizer = torch.optim.Adam(parameters, lr=MY_LEARNING_RATE, ...)
scheduler = ExponentialLR(optimizer, gamma=0.9)
solver = Solver1D(..., nets=nets, optimizer=optimizer, lr_scheduler=scheduler)

And then do a scheduler step after one train and valid epoch like that:

for local_epoch in loop:
            self.run_train_epoch()
            self.run_valid_epoch()
            if self.lr_scheduler: 
                     self.lr_scheduler.step()

Is this needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant