okami.mom/strata

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

Niko1221Merge f-142b-serve into f-1426e1085c1d

main
3.1 KiB72 linesraw
1"""Repeat the mixed 30-minute soak after startup, retaining guard stops."""
2import argparse
3import json
4import socket
5import subprocess
6import sys
7import time
8
9from strata_bench_continue import Continuation, b
10
11
12def main():
13    parser = argparse.ArgumentParser()
14    parser.add_argument("--model", choices=("iq2_xs", "iq3_s"), required=True)
15    args = parser.parse_args()
16    with socket.socket() as sock:
17        if sock.connect_ex(("127.0.0.1", b.PORT)) == 0:
18            raise RuntimeError("Benchmark service is occupied; it was preserved")
19    runner = Continuation(["iq3_xxs", "iq3_s"])
20    (b.OUT / f"soak-retry-{args.model}.pid").write_text(str(b.os.getpid()))
21    supervisor = subprocess.Popen([sys.executable, str(b.SCRIPT), "--watchdog", str(b.os.getpid()),
22        str(runner.clock["measurement_stop_epoch"]+300)], stdout=subprocess.DEVNULL,
23        stderr=subprocess.DEVNULL, creationflags=b.FLAGS)
24    began, count, outcome, reason = None, 0, "not_started", None
25    try:
26        runner.budget("soak_retry_prepare", min(420, max(0, runner.hard-time.monotonic())))
27        runner.init_tokenizer()
28        runner.inventory()
29        if runner.hard-time.monotonic() < 1800+60:
30            raise b.CaseError("insufficient reserve for a complete 30-minute soak")
31        runner.start(args.model)
32        runner.budget("soak_retry", 1800)
33        began = time.monotonic()
34        outcome = "running"
35        while runner.left() > 5:
36            if count % 4 == 0:
37                runner.perform(f"soak-retry-check-{count}",
38                    "Calculate 17 multiplied by 19. Reply only with the integer result.",
39                    group="soak_retry", max_tokens=16, expected="323")
40            else:
41                target = (512, 32768, 128000)[(count-1) % 3]
42                runner.perform(f"soak-retry-{count}", runner.make(target, rep=1000+count), target,
43                    group="soak_retry", max_tokens=512)
44            count += 1
45        time.sleep(min(5, runner.left()))
46        outcome = "duration_completed"
47    except b.CaseError as exc:
48        reason = str(exc)
49        outcome = "duration_completed" if began and reason == "deadline" and time.monotonic()-began >= 1795 else "stopped"
50    except Exception as exc:
51        outcome, reason = "unexpected_error", f"{type(exc).__name__}: {exc}"
52        raise
53    finally:
54        result = {"model": args.model, "outcome": outcome, "reason": reason,
55            "observed_request_window_seconds": time.monotonic()-began if began else 0,
56            "completed_requests": count, "weights_mode": runner.weights_mode,
57            "engine_environment": getattr(runner, "engine_environment", {}), "target_seconds": 1800,
58            "startup_included_in_duration": False}
59        b.write(b.OUT / f"soak-retry-{args.model}.json", result)
60        runner.event("soak_retry_finish", **result)
61        if runner.active_worker and runner.active_worker.poll() is None:
62            b.kill_tree(runner.active_worker)
63        for job in runner.child_jobs:
64            b.kill_tree(job)
65        runner.stop()
66        runner.monitor.done.set()
67        if supervisor.poll() is None:
68            supervisor.terminate()
69
70
71if __name__ == "__main__":
72    main()