-
Notifications
You must be signed in to change notification settings - Fork 1
/
init_bohb_noisy.py
68 lines (53 loc) · 1.53 KB
/
init_bohb_noisy.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
63
64
65
66
67
68
import os
import subprocess
import time
from sys import stdout
trials = 8
dataset = "cifar10" # cifar10, femnist, stackoverflow, reddit
FNULL = open(os.devnull, 'w')
def run_script(args_dict, gpu, blocking=False):
main_command = [
'python3',
'fedtrain_bohb.py',
]
args_dict.update({'device-number': str(gpu)})
whole_command = main_command
for k, v in args_dict.items():
whole_command.append('--' + k)
whole_command.append(v)
print(whole_command)
if blocking:
subprocess.call(args=whole_command, stdout=FNULL)
else:
subprocess.Popen(args=whole_command, stdout=FNULL)
import numpy as np
args_keys = [
'parent-dir',
'seed',
'dataset',
'batch',
'eps',
]
args_dicts = []
c_dict = {
'cifar10': (1, 100),
'femnist': (3, 360),
'stackoverflow': (36, 3678),
'reddit': (100, 10000)
}
# fedtrain_bohb.py uses uniform training objective
sub_c, max_c = c_dict[dataset]
for seed in range(8):
np.random.seed(seed)
# args_values = (f"runs_unif/runs_bohb/runs_{dataset}/seed_{seed}", str(seed), dataset, str(max_c), '-1')
args_values = (f"runs_unif/runs_bohb/runs_{dataset}_s_e=100/seed_{seed}", str(seed), dataset, str(sub_c), '100')
args_dict = dict(zip(args_keys, args_values))
args_dicts.append(args_dict)
# For a machine with multiple GPUs
# gpu = seed
# run_script(args_dict, gpu)
# For a machine with a single GPU
gpu = 0
run_script(args_dict, gpu, blocking=True)
time.sleep(5)
FNULL.close()