-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (37 loc) · 1.25 KB
/
main.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
from sys import argv
from follower.training_config import Experiment
from follower.training_utils import run, create_sf_config
def recursive_update(experiment: dict, key, value):
if key in experiment:
experiment[key] = value
return True
else:
for k, v in experiment.items():
if isinstance(v, dict):
if recursive_update(v, key, value):
return True
return False
def update_dict(target_dict, keys, values):
for key, value in zip(keys, values):
if recursive_update(target_dict, key, value):
print(f'Updated {key} to {value}')
else:
raise KeyError(f'Could not find {key} in experiment')
def parse_args_to_items(argv_):
keys = []
values = []
for arg in argv_[1:]:
key, value = arg.split('=')
key = key.replace('--', '')
keys.append(key)
values.append(value)
return keys, values
def main():
experiment = Experiment()
experiment = create_sf_config(experiment).__dict__
keys, values = parse_args_to_items(list(argv))
# check all args and replace them in experiment recursively
update_dict(experiment, keys, values)
run(config=experiment)
if __name__ == '__main__':
main()