-
Notifications
You must be signed in to change notification settings - Fork 19
/
__init__.py
62 lines (57 loc) · 1.73 KB
/
__init__.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# coding: utf-8
from lrs import vanillalr, noamlr, scorelr, gnmtplr, epochlr, cosinelr
def get_lr(params):
strategy = params.lrate_strategy.lower()
if strategy == "noam":
return noamlr.NoamDecayLr(
params.lrate,
params.min_lrate,
params.max_lrate,
params.warmup_steps,
params.hidden_size
)
elif strategy == "gnmt+":
return gnmtplr.GNMTPDecayLr(
params.lrate,
params.min_lrate,
params.max_lrate,
params.warmup_steps,
params.nstable,
params.lrdecay_start,
params.lrdecay_end
)
elif strategy == "epoch":
return epochlr.EpochDecayLr(
params.lrate,
params.min_lrate,
params.max_lrate,
params.lrate_decay,
)
elif strategy == "score":
return scorelr.ScoreDecayLr(
params.lrate,
params.min_lrate,
params.max_lrate,
history_scores=[v[1] for v in params.recorder.valid_script_scores],
decay=params.lrate_decay,
patience=params.lrate_patience,
)
elif strategy == "vanilla":
return vanillalr.VanillaLR(
params.lrate,
params.min_lrate,
params.max_lrate,
)
elif strategy == "cosine":
return cosinelr.CosineDecayLr(
params.lrate,
params.min_lrate,
params.max_lrate,
params.warmup_steps,
params.lrate_decay,
t_mult=params.cosine_factor,
update_period=params.cosine_period
)
else:
raise NotImplementedError(
"{} is not supported".format(strategy))