-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterator.py
77 lines (53 loc) · 1.89 KB
/
iterator.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
69
70
71
72
73
74
75
76
77
import subprocess
import json
from utils.util import read_config, get_logger
import numpy as np
import argparse
import torch.cuda as cutorch
def get_available_gpus(threshold=0.5):
"""
TODO: Implement
"""
avail_gpus = [0, 1, 2, 3, 4, 5, 6, 7]
return avail_gpus
def args_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
'--filename',
default=[], help='configuration filename',
action="append")
parser.add_argument('--dry-run', action='store_true', help='do not fire')
return parser.parse_args()
if __name__ == "__main__":
args = args_parser()
mylogger = get_logger("Iterator")
mylogger.debug(args)
# Loop over multiple files
gpus = get_available_gpus()
number_of_gpus = len(gpus)
mylogger.debug(f"gpus: {gpus}")
for filename in args.filename:
config = read_config(filename)
# for clusters in range(1, config["clusters"] + 1 )
pvals = np.linspace(.2, 1, 9)
mylogger.info(f"Starting experiment from {filename} with p={pvals}")
child_processes = []
dataset = config["dataset"]
model = config["model"]
# Make variable replacable
for n, p in enumerate(pvals):
config["p"] = np.round(p / .1) * .1
config["gpu"] = gpus[n % number_of_gpus]
mylogger.debug(f"Assigning p={p} to GPU {gpus[n % number_of_gpus]}")
config["filename"] = f"results_{dataset}_{model}_p_{p:.2f}"
command = ["python", "main_fed.py"]
for k, v in config.items():
command.extend([f"--{k}", str(v)])
# command.extend(["--overlap"])
mylogger.debug(command)
# Allow dry-runs
if not args.dry_run:
p = subprocess.Popen(command)
child_processes.append(p)
for cp in child_processes:
cp.wait()