-
Notifications
You must be signed in to change notification settings - Fork 2
/
scheduler_builder.py
36 lines (27 loc) · 1.03 KB
/
scheduler_builder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import torch
import config
class EmptyScheduler:
def __init__(self):
pass
def step(self):
# do nothing
pass
def buildScheduler(optimizer,
optimize_params: config.OptimizeConfig = None):
if optimize_params is None:
optimize_params = config.optimize
if optimize_params.Scheduler['type'] is None:
return EmptyScheduler()
return SchedulerSwitch.get(optimize_params.Scheduler['type'],
_empty_scheduler)(optimizer, optimize_params)
def _step_scheduler(optimizer,
optimize_params: config.OptimizeConfig):
return torch.optim.lr_scheduler.StepLR(optimizer,
step_size=optimize_params.Scheduler['lr_decay_iters'],
gamma=optimize_params.Scheduler['lr_decay_gamma'])
def _empty_scheduler(optimizer,
optimize_params: config.OptimizeConfig):
return EmptyScheduler()
SchedulerSwitch = {
'step': _step_scheduler
}