mattext-syn / scripts /run_all.py
zhilong777's picture
Add files using upload-large-folder tool
5237fbc verified
Raw History Blame Contribute Delete
2 kB
"""Run the fine-tuning grid on all GPUs. Each GPU runs PER_GPU jobs at a time.
Finished runs (json present) are skipped, so the script can be restarted."""
import os, sys, subprocess, threading, queue, itertools, time
H = os.path.expanduser("~/syn-multi"); OUT = os.environ.get("RUN_OUT", f"{H}/runs"); LOG = f"{OUT}/logs"; os.makedirs(LOG, exist_ok=True)
DATA = os.environ.get("RUN_DATA", f"{H}/reps.parquet")
REPS = sys.argv[1].split(",") if len(sys.argv) > 1 else ["composition", "slices", "cif_symmetrized", "cif_p1"]
LRS = [float(x) for x in sys.argv[2].split(",")] if len(sys.argv) > 2 else [2e-5, 5e-5, 1e-4, 2e-4]
SEEDS = [int(x) for x in sys.argv[3].split(",")] if len(sys.argv) > 3 else [0, 1, 2, 3, 4]
PER_GPU = int(sys.argv[4]) if len(sys.argv) > 4 else 2
EXTRA = sys.argv[5].split() if len(sys.argv) > 5 else []
q = queue.Queue()
for rep, lr, seed in itertools.product(REPS, LRS, SEEDS):
tag = f"{rep}{'_scratch' if '--from_scratch' in EXTRA else ''}_lr{lr:g}_s{seed}"
if not os.path.exists(f"{OUT}/{tag}.json"): q.put((rep, lr, seed, tag))
print("jobs", q.qsize(), flush=True)
def worker(gpu):
env = dict(os.environ, CUDA_VISIBLE_DEVICES=str(gpu), TOKENIZERS_PARALLELISM="false", OMP_NUM_THREADS="4")
while True:
try: rep, lr, seed, tag = q.get_nowait()
except queue.Empty: return
t0 = time.time()
with open(f"{LOG}/{tag}.log", "w") as f:
rc = subprocess.call([f"{H}/venv-ft/bin/python", f"{H}/mattext_ft/finetune.py", "--rep", rep, "--lr", str(lr), "--seed", str(seed),
"--data", DATA, "--out", OUT, "--xtal2txt", f"{H}/src/xtal2txt"] + EXTRA,
stdout=f, stderr=subprocess.STDOUT, env=env)
print(f"{tag} gpu{gpu} rc={rc} {time.time()-t0:.0f}s left={q.qsize()}", flush=True)
ths = [threading.Thread(target=worker, args=(g,)) for g in range(6) for _ in range(PER_GPU)]
[t.start() for t in ths]; [t.join() for t in ths]
print("=== ALL DONE", flush=True)