-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch_gpu0_queue.py
More file actions
156 lines (134 loc) · 4.7 KB
/
launch_gpu0_queue.py
File metadata and controls
156 lines (134 loc) · 4.7 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"""Sequential benchmark queue on GPU0 (RTX 3080 20GB).
Runs SSC first (resumed from 72.1%), then the smaller N3 benchmarks
sequentially. All on GPU0 via CUDA_VISIBLE_DEVICES=0.
Usage:
python launch_gpu0_queue.py
python launch_gpu0_queue.py --skip-ssc # Skip SSC, start from DVS
python launch_gpu0_queue.py --start-from 2 # Start from job index 2
"""
import os
import sys
import time
import subprocess
import argparse
BENCHMARKS_DIR = os.path.dirname(os.path.abspath(__file__))
PYTHON = sys.executable
# nvidia-smi GPU 0 = RTX 3080 20GB. NEVER use GPU 1.
GPU_ENV = {"CUDA_VISIBLE_DEVICES": "0"}
JOBS = [
{
"name": "SSC fine-tune (from 72.1%)",
"script": "ssc/train.py",
"args": [
"--epochs", "70", "--batch-size", "64", "--lr", "5e-4",
"--hidden1", "1024", "--hidden2", "512", "--dropout", "0.3",
"--amp", "--activity-lambda", "0", "--warmup-epochs", "0",
"--label-smoothing", "0.0",
"--resume-weights", "checkpoints/ssc_adlif_amp2.pt",
"--save", "checkpoints/ssc_n3_v3.pt",
"--device", "cuda:0",
],
"log": "logs/n3/ssc_n3_v3.log",
},
{
"name": "DVS Gesture WTA",
"script": "dvs_gesture/train.py",
"args": [
"--wta", "--epochs", "200", "--batch-size", "32",
"--lr", "1e-3", "--fc-hidden", "256",
"--wta-groups", "8", "--wta-k", "2",
"--dropout", "0.3", "--amp", "--event-drop",
"--save", "checkpoints/dvs_n3_wta.pt",
"--device", "cuda:0",
],
"log": "logs/n3/dvs_n3_wta.log",
},
{
"name": "N-MNIST Deep Conv",
"script": "nmnist/train.py",
"args": [
"--n3-deep", "--epochs", "50", "--batch-size", "128",
"--lr", "1e-3", "--fc-hidden", "256",
"--dropout", "0.2", "--amp", "--event-drop",
"--save", "checkpoints/nmnist_n3_deep.pt",
"--device", "cuda:0",
],
"log": "logs/n3/nmnist_n3_deep.log",
},
{
"name": "psMNIST TDM",
"script": "psmnist/train.py",
"args": [
"--tdm", "--tdm-banks", "4", "--epochs", "50",
"--batch-size", "128", "--lr", "1e-3", "--hidden", "256",
"--dropout", "0.2",
"--save", "checkpoints/psmnist_n3_tdm.pt",
"--device", "cuda:0",
],
"log": "logs/n3/psmnist_n3_tdm.log",
},
{
"name": "ECG Gated",
"script": "ecg_arrhythmia/train.py",
"args": [
"--gated", "--epochs", "100", "--batch-size", "64",
"--lr", "1e-3", "--hidden", "128", "--dropout", "0.2",
"--save", "checkpoints/ecg_n3_gated.pt",
"--device", "cuda:0",
],
"log": "logs/n3/ecg_n3_gated.log",
},
]
def run_job(job):
"""Run a training job, wait for completion."""
log_path = os.path.join(BENCHMARKS_DIR, job["log"])
os.makedirs(os.path.dirname(log_path), exist_ok=True)
cmd = [PYTHON, "-u", os.path.join(BENCHMARKS_DIR, job["script"])] + job["args"]
env = {**os.environ, **GPU_ENV, "PYTHONUNBUFFERED": "1"}
print(f"\n{'='*60}")
print(f"LAUNCHING: {job['name']}")
print(f"Log: {log_path}")
print(f"{'='*60}\n", flush=True)
log_file = open(log_path, 'w')
proc = subprocess.Popen(
cmd, stdout=log_file, stderr=subprocess.STDOUT,
env=env, cwd=BENCHMARKS_DIR
)
while proc.poll() is None:
time.sleep(60)
try:
with open(log_path, 'r') as f:
lines = f.readlines()
for line in reversed(lines):
line = line.strip()
if line and ("Epoch" in line or "acc=" in line):
print(f" [{job['name']}] {line}", flush=True)
break
except Exception:
pass
log_file.close()
rc = proc.returncode
status = "DONE" if rc == 0 else f"FAIL (exit {rc})"
print(f"\n [{status}] {job['name']}", flush=True)
return rc
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--skip-ssc", action="store_true")
parser.add_argument("--start-from", type=int, default=0)
args = parser.parse_args()
os.makedirs(os.path.join(BENCHMARKS_DIR, "logs/n3"), exist_ok=True)
start = args.start_from
if args.skip_ssc and start == 0:
start = 1
jobs = JOBS[start:]
print(f"GPU0 Queue: {len(jobs)} jobs")
for i, job in enumerate(jobs):
print(f" {i+start}. {job['name']}")
print(flush=True)
for job in jobs:
run_job(job)
print(f"\n{'='*60}")
print("ALL GPU0 JOBS COMPLETE")
print(f"{'='*60}")
if __name__ == "__main__":
main()