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

Add option to chain multiple learning rate schedulers. #59

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions gluefactory/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ def filter_fn(x):
def get_lr_scheduler(optimizer, conf):
"""Get lr scheduler specified by conf.train.lr_schedule."""
if conf.type not in ["factor", "exp", None]:
if hasattr(conf.options, "schedulers"):
# Add option to chain multiple schedulers together
# This is useful for e.g. warmup, then cosine decay
schedulers = []
for scheduler_conf in conf.options.schedulers:
scheduler = get_lr_scheduler(optimizer, scheduler_conf)
schedulers.append(scheduler)

options = {k: v for k, v in conf.options.items() if k != "schedulers"}
return getattr(torch.optim.lr_scheduler, conf.type)(
optimizer, schedulers, **options
)

return getattr(torch.optim.lr_scheduler, conf.type)(optimizer, **conf.options)

# backward compatibility
Expand Down
Loading