Skip to content

Commit

Permalink
support to specify priority about steps and epochs in LinearWarmup (#…
Browse files Browse the repository at this point in the history
…8540)

for uapi
  • Loading branch information
TingquanGao authored Aug 23, 2023
1 parent a3e9c92 commit 0e5de2a
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit 0e5de2a

Please sign in to comment.