-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrain.py
72 lines (62 loc) · 2.58 KB
/
train.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
import json
import os
import numpy as np
from model.synthetic import set_slo
from model.rl import RL
import argparse
hp_file = "model/configs/hyperparams.json"
hp_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), hp_file)
hyperparams = json.load(open(hp_file, "r"))
parser = argparse.ArgumentParser()
parser.add_argument('-n',"--exp_name", help="exp name", type=str)
parser.add_argument('-e',"--epochs", help="epochs", type=int)
parser.add_argument('-c',"--clip_ratio", help="clip ratio (epsilon)", type=float)
parser.add_argument('-k', "--knob", help="knob", type=float)
parser.add_argument('-ncp', "--ncomp", help="NFV Components", type=int)
parser.add_argument('-ncf', "--nconf", help="VM Instances", type=int)
args = parser.parse_args()
if args.exp_name:
hyperparams["exp_name"] = args.exp_name
if args.clip_ratio:
hyperparams["clip_ratio"] = float(args.clip_ratio)
if args.knob:
hyperparams["knob"] = float(args.knob)
if args.ncomp:
hyperparams["ncomp"] = int(args.ncomp)
if args.nconf:
hyperparams["nconf"] = int(args.nconf)
if args.epochs:
hyperparams["epochs"] = int(args.epochs)
slo = int(np.exp(np.random.randint(240,840)/100))
freq = int(1e6 / np.random.randint(int(slo*0.8), int(slo*1.2)))
knob = hyperparams["knob"] # For over, under and near provisioning
print(f"SLO: {slo}, Freq: {freq}, Knob: {knob}")
set_slo(slo, freq, knob)
budget = hyperparams["budget"]
overrun_lim = hyperparams["budget_relax"]
mode = hyperparams["mode"]
threads = hyperparams["threads"]
nconf = hyperparams["nconf"]
ncomp = hyperparams["ncomp"]
algo = hyperparams["algo"]
roboconf = RL(slo=slo, budget=budget, overrun_lim=overrun_lim,
mode=mode, threads=threads,
nconf=nconf, ncomp=ncomp,
exp_name=hyperparams["exp_name"],
hidden_sizes=hyperparams["hidden_sizes"],
num_gnn_layer=hyperparams["num_gnn_layer"],
seed=hyperparams["seed"],
steps_per_epoch=hyperparams["steps_per_epoch"],
epochs=hyperparams["epochs"],
max_action=hyperparams["max_action"],
gamma=hyperparams["gamma"],
clip_ratio=hyperparams["clip_ratio"],
pi_lr=hyperparams["pi_lr"],
vf_lr=hyperparams["vf_lr"],
train_pi_iters=hyperparams["train_pi_iters"],
train_v_iters=hyperparams["train_v_iters"],
lam=hyperparams["lam"],
max_ep_len=hyperparams["max_ep_len"],
target_kl=hyperparams["target_kl"],
save_freq=hyperparams["save_freq"])
roboconf.train(algo)