"git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "00337e9687abd7bd3ff55609dc87f92fc4443aac"
Commit baf66d14 authored by lukovnikov's avatar lukovnikov
Browse files

restart cosine lr schedule

parent 51efde54
...@@ -69,7 +69,23 @@ class WarmupCosineSchedule(LRSchedule): ...@@ -69,7 +69,23 @@ class WarmupCosineSchedule(LRSchedule):
return progress / self.warmup return progress / self.warmup
else: else:
progress = (progress - self.warmup) / (1 - self.warmup) # progress after warmup progress = (progress - self.warmup) / (1 - self.warmup) # progress after warmup
return 0.5 * (1. + math.cos(math.pi * self.cycles * 2 * progress)) return 0.5 * (1. + math.cos(math.pi * ((self.cycles * 2 * progress) % 1))
class WarmupCosineWithRestartsSchedule(WarmupCosineSchedule):
warn_t_total = True
def __init__(self, warmup=0.002, t_total=-1, cycles=1., **kw):
super(WarmupCosineWithRestartsSchedule, self).__init__(warmup=warmup, t_total=t_total, cycles=cycles, **kw)
def get_lr_(self, progress):
if self.t_total <= 0:
return 1.
if progress < self.warmup:
return progress / self.warmup
else:
progress = (progress - self.warmup) / (1 - self.warmup) # progress after warmup
ret = 0.5 * (1. + math.cos(math.pi * self.cycles * 2 * progress))
return ret
class WarmupConstantSchedule(LRSchedule): class WarmupConstantSchedule(LRSchedule):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment