-
Notifications
You must be signed in to change notification settings - Fork 1
/
hpng
46 lines (38 loc) · 1.47 KB
/
hpng
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
#!/usr/bin/env python3
import argparse
from hpman import HyperParameterManager
from hpnevergrad import hpng
import nevergrad as ng
def main():
op = sorted(ng.optimizers.registry.keys())
parser = argparse.ArgumentParser()
parser.add_argument(dest="module", nargs=1)
parser.add_argument("--placeholder",
default="_",
help="placeholder of hpman used in given files")
parser.add_argument(
"--optimizer",
default="RandomSearch",
choices=[op],
help=
"optimizer used to search hyperparameter,you can find all optimizers in https://facebookresearch.github.io/nevergrad/optimizers_ref.html#optimizers "
)
parser.add_argument("--budget",
default=100,
help="number of allowed evaluations",
type=int)
args, remain_args = parser.parse_known_args()
module = args.module[0]
hp_mgr = HyperParameterManager(args.placeholder)
optim_type = args.optimizer
budget = args.budget
f, obj = hpng.split_module(module)
hp_mgr.parse_file(f)
train = hpng.import_func(f, obj)
parametrization = hpng.get_parametrization(hp_mgr)
objective_function = hpng.get_objective_function(train, hp_mgr)
optimizer = hpng.optimizer_warpper(optim_type, budget, parametrization)
recommendation = optimizer.minimize(objective_function)
print(recommendation.kwargs)
if __name__ == "__main__":
main()