-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiterator_eps.py
91 lines (62 loc) · 2.46 KB
/
iterator_eps.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import subprocess
import json
from utils.util import read_config, get_logger
import numpy as np
import argparse
import torch.cuda as cutorch
from utils.gpuutils import get_available_gpus
import time
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)
experiment = config.get("experiment","default")
flags = config.pop("flags")
# for clusters in range(1, config["clusters"] + 1 )
epsvals = np.logspace(-2,np.log10(.5),10)
frac = config["frac"]
mylogger.info(f"Starting {experiment} from {filename} with eps={epsvals}")
dataset = config["dataset"]
model = config["model"]
cluster_list = range(1, 5 + 1)
# Make variable replacable
for clusters in cluster_list:
#config["frac"] = clusters * frac
mylogger.info(f"Cluster k={clusters}")
child_processes = []
for n, eps in enumerate(epsvals):
config["clusters"] = clusters
config["eps"] = eps
available_gpus = get_available_gpus()
if not available_gpus:
time.sleep(60)
config["gpu"] = np.random.choice(available_gpus, 1)[0]
mylogger.debug(f"Assigning eps={eps} to GPU {gpus[n % number_of_gpus]}")
config["filename"] = "results_clusters"
command = ["python", "main_fed.py"]
for k, v in config.items():
command.extend([f"--{k}", str(v)])
for k, v in flags.items():
if v:
command.append(f"--{k}")
mylogger.debug(" ".join(command))
# Allow dry-runs
if not args.dry_run:
p = subprocess.Popen(command, shell=False)
child_processes.append(p)
time.sleep(20)
for cp in child_processes:
cp.wait()