okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-023-int into f-023-guifcb0c2d0e

main
2.7 KiB67 linesraw
1"""Runs the engine side of the DFlash2 experiment for one prompt on strix (foreground; one engine at a time)."""
2import json, re, subprocess, sys, time
3from pathlib import Path
4
5W = Path(r"C:\dflash2-work")
6RW = "C:\\strata-test\\dflash2"
7
8
9def ssh(cmd, timeout=1500):
10    r = subprocess.run(["ssh", "-o", "ServerAliveInterval=30", "strix", cmd], capture_output=True, text=True, timeout=timeout)
11    out = "\n".join(l for l in (r.stdout + r.stderr).splitlines() if not l.startswith("**"))
12    return out
13
14
15def scp_up(local, remote):
16    subprocess.run(["scp", "-q", str(local), "strix:" + remote.replace("\\", "/")], check=True, capture_output=True)
17
18
19def scp_down(remote, local):
20    subprocess.run(["scp", "-q", "strix:" + remote.replace("\\", "/"), str(local)], check=True, capture_output=True)
21
22
23def run_mode(mode, name, extra=""):
24    t = time.time()
25    out = ssh('powershell -NoProfile -ExecutionPolicy Bypass -File %s\\run_one.ps1 -Mode %s -Name %s %s' % (RW, mode, name, extra))
26    print("[%s %s] %.0f s" % (mode, name, time.time() - t))
27    print(out)
28    (W / "logs").mkdir(exist_ok=True)
29    (W / "logs" / ("%s_%s.log" % (mode, name))).write_text(out)
30    scp_down("%s\\out\\%s_%s.txt" % (RW, mode, name), W / "logs" / ("%s_%s.txt" % (mode, name)))
31    scp_down("%s\\out\\%s_%s.err" % (RW, mode, name), W / "logs" / ("%s_%s.err" % (mode, name)))
32    return out
33
34
35def produced_ids(path):
36    txt = Path(path).read_text()
37    m = re.search(r"^output  :(.*)$", txt, re.M)
38    return [int(x) for x in m.group(1).split()] if m else []
39
40
41def main(name, max_new, steps):
42    prompts = json.load(open(W / "prompts.json"))
43    pids = prompts[name]["ids"]
44    if "gen" in steps:
45        run_mode("gen", name, "-MaxNew %d" % max_new)
46    out = produced_ids(W / "logs" / ("gen_%s.txt" % name))
47    print(name, "prompt", len(pids), "generated", len(out), "tail", out[-3:])
48    seq = pids + out
49    (W / "p" / ("%s.out.ids" % name)).write_text(",".join(map(str, out)))
50    (W / "p" / ("%s.first.ids" % name)).write_text(",".join(map(str, seq[:2])))
51    (W / "p" / ("%s.rest.ids" % name)).write_text(",".join(map(str, seq[2:])))
52    json.dump({"prompt": pids, "out": out}, open(W / "p" / ("%s.seq.json" % name), "w"))
53    for k in ("out", "first", "rest"):
54        scp_up(W / "p" / ("%s.%s.ids" % (name, k)), "%s\\p\\%s.%s.ids" % (RW, name, k))
55    for mode in ("genf", "genfm", "tap"):
56        if mode in steps:
57            run_mode(mode, name)
58    if "tap" in steps:
59        (W / "taps").mkdir(exist_ok=True)
60        scp_down("%s\\out\\tap_%s.bin" % (RW, name), W / "taps" / ("%s.bin" % name))
61
62
63if __name__ == "__main__":
64    name = sys.argv[1]
65    max_new = int(sys.argv[2])
66    steps = sys.argv[3].split(",") if len(sys.argv) > 3 else ["gen", "genf", "genfm", "tap"]
67    main(name, max_new, steps)