forked from openvinotoolkit/hyper_parameter_optimization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toy_test_parallel.py
56 lines (43 loc) · 1.46 KB
/
toy_test_parallel.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
# Copyright (C) 2018-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
#
# Parallel version of toy test example with skopt.benchmarks.branin
# https://scikit-optimize.github.io/stable/modules/generated/skopt.benchmarks.branin.html
#
# Three minima points
# (9.42478, 2.475)
# (3.141592, 2.275)
# (-3.141592, 12.275)
#
import hpopt
import numpy as np
from skopt.benchmarks import branin, hart6
from multiprocessing import Process
def my_model(a, b):
return -branin((a, b))
def my_trainer(config):
for iteration_num in range(config["iterations"]):
score = my_model(**config["params"])
if hpopt.report(config=config, score=score) == hpopt.Status.STOP:
break
hp_configs = {"a": hpopt.search_space("uniform", [-5, 10]),
"b": hpopt.search_space("uniform", [0, 15])}
my_hpo = hpopt.create(save_path='./tmp/my_hpo_branin',
search_alg="bayes_opt",
search_space=hp_configs,
ealry_stop="median_stop",
num_init_trials=5, num_trials=50, max_iterations=2,
num_full_iterations=2, full_dataset_size=1)
while True:
configs = my_hpo.get_next_samples()
if len(configs) == 0:
break
proc_list = []
for config in configs:
p = Process(target=my_trainer, args=(config, ))
proc_list.append(p)
p.start()
for p in proc_list:
p.join()
print("best hp: ", my_hpo.get_best_config())