File size: 4,185 Bytes
d92bcf7 | 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 | """VRAM-aware job scheduler: runs pending baseline jobs side by side while GPU memory allows; logs every event.
python scripts/jobqueue.py (loops until every job in JOBS has a result.json)
Job = (dataset, model, lr). A job counts as 'running' if ANY process on the machine has its command line (so jobs started by older sweep scripts are respected).
Start rule: free VRAM >= need(model)+margin and our concurrent baseline jobs < MAX_CONC. A job that exits without result.json is retried (max 2 retries)."""
import json, os, subprocess, subprocess as sp, sys, time
ROOT = "/home/ubuntu/pro/baselines"; LOG = f"{ROOT}/logs/jobqueue.jsonl"
NEED_GB = {"utae": 4, "unet3d": 3, "bunetconvlstm": 3, "batrousconvlstm": 5, "bclstm": 4, "stcln_wp": 10, "stcln": 10} # stcln*: measured 9.2 GB allocated at batch 2; others conservative
MARGIN_GB, MAX_CONC, POLL = 1.0, 6, 30
NEED_P = {"utae": 3, "unet3d": 3.5, "bunetconvlstm": 2.5, "batrousconvlstm": 8, "bclstm": 6.5, "stcln": 4} # PLANTEUR (128x128, T=12): measured peaks + headroom
EXTRA_P = {"stcln": ["--train_crop", "32", "--crops", "2", "--eval_batch", "1"]} # STCLN: 32x32 random crops (full-patch batch 2 does not fit), batch-1 full-patch evaluation
GRID = {"utae": ["1e-3", "3e-4", "1e-4"], "unet3d": ["1e-3", "3e-4", "1e-4"], "bunetconvlstm": ["1e-3", "3e-4", "1e-4"], "batrousconvlstm": ["1e-3", "3e-4", "1e-4"],
"bclstm": ["1e-2", "1e-3", "3e-4", "1e-4"], "stcln_wp": ["1e-3", "3e-4", "1e-4"], "stcln": ["1e-3", "3e-4", "1e-4"]}
PJOBS = [("planteur", m, lr) for m, lr in [("bclstm", "3e-4"), ("batrousconvlstm", "1e-4"), ("utae", "1e-3"), ("utae", "3e-4"), ("stcln", "3e-4"), ("stcln", "1e-4"), ("unet3d", "1e-4"), ("bunetconvlstm", "3e-4")]]
JOBS = [("mtlcc", m, lr) for m in ["stcln_wp", "stcln", "batrousconvlstm", "bclstm", "bunetconvlstm", "unet3d", "utae"] for lr in GRID[m]]
JOBS = JOBS + PJOBS
def ev(**k):
k["t"] = time.strftime("%Y-%m-%d %H:%M:%S"); open(LOG, "a").write(json.dumps(k) + "\n"); print(k, flush=True)
def free_gb():
o = sp.run(["nvidia-smi", "--query-gpu=memory.total,memory.used", "--format=csv,noheader,nounits"], capture_output=True, text=True).stdout.split(",")
return (float(o[0]) - float(o[1])) / 1024
def done(j): return os.path.exists(f"{ROOT}/results/{j[0]}/{j[1]}/{j[1]}_lr{float(j[2]):g}_s3407/result.json")
def cmd(j): return ["python3", "scripts/run_supervised.py", "--dataset", j[0], "--model", j[1], "--lr", j[2], "--seed", "3407"] + (EXTRA_P.get(j[1], []) if j[0] == "planteur" else [])
def running_elsewhere(j):
key = f"--dataset {j[0]} --model {j[1]} --lr {j[2]} --seed 3407"
for p in os.listdir("/proc"):
if p.isdigit():
try:
c = open(f"/proc/{p}/cmdline").read().replace("\0", " ")
if "run_supervised.py" in c and key in c: return True
except Exception: pass
return False
procs, retries = {}, {}
ev(event="start", jobs=len(JOBS), pending=sum(not done(j) for j in JOBS))
while True:
for j, p in list(procs.items()):
rc = p.poll()
if rc is not None:
del procs[j]
if done(j): ev(event="finished", job=j)
else:
retries[j] = retries.get(j, 0) + 1; ev(event="failed", job=j, rc=rc, retry=retries[j])
pending = [j for j in JOBS if not done(j) and j not in procs and not running_elsewhere(j) and retries.get(j, 0) <= 2]
if not pending and not procs and not any(running_elsewhere(j) for j in JOBS if not done(j)): ev(event="all_done"); break
for j in pending:
if len(procs) >= MAX_CONC: break
need = (NEED_P if j[0] == "planteur" else NEED_GB)[j[1]] + MARGIN_GB
if free_gb() >= need:
lf = open(f"{ROOT}/logs/{j[0]}_{j[1]}.log", "a"); procs[j] = subprocess.Popen(cmd(j), cwd=ROOT, stdout=lf, stderr=subprocess.STDOUT)
ev(event="started", job=j, free_gb=round(free_gb(), 1), need_gb=need, concurrent=len(procs)); time.sleep(45) # let it allocate before the next decision
else: break # head-of-line blocking: keep the memory for this job instead of letting smaller jobs overtake it
time.sleep(POLL)
|