okami.mom/strata

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

Niko1221Merge f-q36-vp (Qwen3.6 parallel requests and pictures)db4dd65e5

main
3.2 KiB79 linesraw
1"""q36_interleave_probe.py --exe E --args "..." [--long 3000] [--slots 3] : what the slots that are decoding see while a new
2request's long prompt is read: the tokens they produce during the read, and their longest pause between two tokens, against the
3same without a read.  The read goes chunk by chunk with one decode window of the other slots between two chunks.
4
5  python tools/qwen35/q36_interleave_probe.py --exe build/strata-q36 --args "--model M --max-context 8192 --batch 4" --long 3000
6"""
7import argparse, shlex, sys, time
8from pathlib import Path
9sys.path.insert(0, str(Path(__file__).resolve().parent))
10from q36_harness import Eng, load_prompts
11
12ap = argparse.ArgumentParser()
13ap.add_argument("--exe", required=True)
14ap.add_argument("--args", default="")
15ap.add_argument("--long", type=int, default=3000)
16ap.add_argument("--slots", type=int, default=3, help="slots decoding while the long prompt is read")
17ap.add_argument("--n", type=int, default=600)
18ap.add_argument("--log", default=None)
19a = ap.parse_args()
20eng = Eng(a.exe, shlex.split(a.args), log=a.log)
21P = load_prompts(str(Path(__file__).resolve().parent / "parity_prompts.ids"))
22filler = []
23while len(filler) < a.long:
24    for p in P:
25        filler += p[3:-8]
26longids = filler[:a.long] + P[1][-8:]
27stamps = {s: [] for s in range(a.slots)}
28for s in range(a.slots):   # admit the decoding slots
29    ids = P[[0, 1, 2, 3, 5, 8][s % 6]]
30    eng.send("BGEN %d %d %s" % (s, a.n, ",".join(map(str, ids))))
31    while True:
32        l = eng.line()
33        if l.startswith("BADM"):
34            break
35        if l.startswith("BT "):
36            stamps[int(l.split()[1])].append(time.time())
37# 1. a stretch of decoding with no read
38t_end = time.time() + 1.0
39while time.time() < t_end:
40    l = eng.line()
41    if l.startswith("BT "):
42        stamps[int(l.split()[1])].append(time.time())
43base = {s: v[:] for s, v in stamps.items()}
44# 2. the long request
45t0 = time.time()
46eng.send("BGEN %d 8 %s" % (a.slots, ",".join(map(str, longids))))
47pp = []
48t_adm = None
49while True:
50    l = eng.line()
51    now = time.time()
52    if l.startswith("BT "):
53        stamps[int(l.split()[1])].append(now)
54    elif l.startswith("PP "):
55        pp.append(now)
56    elif l.startswith("BADM"):
57        t_adm = now
58        break
59read_s = t_adm - t0
60during = {s: [t for t in v if t0 <= t <= t_adm] for s, v in stamps.items()}
61
62
63def gaps(v):
64    return [b - a_ for a_, b in zip(v, v[1:])]
65
66
67rate0 = sum(len(v) for s, v in base.items()) / max(1e-9, 1.0) if False else None
68n_during = sum(len(v) for v in during.values())
69mx = max((max(gaps(v)) for v in during.values() if len(v) > 1), default=0.0)
70mx0 = max((max(gaps(v[-60:])) for v in base.values() if len(v) > 2), default=0.0)
71print("a prompt of %d tokens read in %.2f s (%d chunks, %.0f tok/s) beside %d decoding slots" % (len(longids), read_s, len(pp),
72                                                                                          len(longids) / read_s, a.slots))
73print("the %d decoding slots produced %d tokens during the read (%.1f tok/s together); longest pause between two tokens of a slot %.0f ms"
74      " (while only decoding: %.0f ms)" % (a.slots, n_during, n_during / read_s, 1000 * mx, 1000 * mx0))
75for s in range(a.slots):
76    eng.send("BSTOP %d" % s)
77eng.send("BSTOP %d" % a.slots)
78time.sleep(1.0)
79eng.close()