-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathsingle_lm_run.py
57 lines (42 loc) · 1.77 KB
/
single_lm_run.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
import argparse
import os
parser = argparse.ArgumentParser(description="Run commands")
parser.add_argument("--logdir", type=str)
parser.add_argument("--hpconfig", type=str, default=",")
parser.add_argument("--datadir", type=str)
def new_tmux_cmd(name, cmd):
if isinstance(cmd, (list, tuple)):
cmd = " ".join(str(v) for v in cmd)
return name, "tmux send-keys -t {} '{}' Enter".format(name, cmd)
def create_tmux_commands(session, gpus, logdir, hpconfig, datadir):
cmds_map = []
num_gpus = len(gpus)
base_cmd = "python single_lm_train.py --logdir {}".format(logdir)
gpus_str = ",".join(str(g) for g in gpus)
cmds_map += [new_tmux_cmd(
"worker", "CUDA_VISIBLE_DEVICES={} {} --num_gpus {} --hpconfig {} --datadir {}".format(
gpus_str, base_cmd, num_gpus, hpconfig, datadir))]
cmds_map += [new_tmux_cmd(
"eval_testave", "CUDA_VISIBLE_DEVICES= {} --mode eval_test_ave --hpconfig {} --datadir {}".format(
base_cmd, hpconfig, datadir))]
cmds_map += [new_tmux_cmd("tb", ["tensorboard --logdir {} --port 12012".format(logdir)])]
cmds_map += [new_tmux_cmd("htop", ["htop"])]
windows = [v[0] for v in cmds_map]
cmds = [
"mkdir -p {}".format(logdir),
"cd code/tf_dist",
"tmux kill-session",
"tmux new-session -s {} -n {} -d".format(session, windows[0])
]
for w in windows[1:]:
cmds += ["tmux new-window -t {} -n {}".format(session, w)]
for window, cmd in cmds_map:
cmds += [cmd]
return cmds
def run():
args = parser.parse_args()
cmds = create_tmux_commands("lm1b", gpus=range(8), logdir=args.logdir, hpconfig=args.hpconfig, datadir=args.datadir)
print("\n".join(cmds))
os.system("\n".join(cmds))
if __name__ == "__main__":
run()