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

support to specify priority about steps and epochs in LinearWarmup #8540

Merged
merged 1 commit into from
Aug 23, 2023
Merged
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
9 changes: 6 additions & 3 deletions ppdet/optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,20 @@ class LinearWarmup(object):
of `epochs` is higher than `steps`. Default: None.
"""

def __init__(self, steps=500, start_factor=1. / 3, epochs=None):
def __init__(self, steps=500, start_factor=1. / 3, epochs=None, epochs_first=True):
super(LinearWarmup, self).__init__()
self.steps = steps
self.start_factor = start_factor
self.epochs = epochs
self.epochs_first = epochs_first

def __call__(self, base_lr, step_per_epoch):
boundary = []
value = []
warmup_steps = self.epochs * step_per_epoch \
if self.epochs is not None else self.steps
if self.epochs_first and self.epochs is not None:
warmup_steps = self.epochs * step_per_epoch
else:
warmup_steps = self.steps
warmup_steps = max(warmup_steps, 1)
for i in range(warmup_steps + 1):
if warmup_steps > 0:
Expand Down