okami.mom/strata

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

Niko1221Merge f-clean-3 (321794636): docs and history (cleanup step 3, items 3.0-3.10); release manifest and capability table with checks, history/ with pointers, link check, tools/ split, bench index; owner OK'd the wording 11-082b36e8a02

main
4.7 KiB90 linesraw
1#!/usr/bin/env python3
2"""b.py (ARC-W): one engine load on the Arc B65 box, a list of solo requests over the engine's line protocol.
3
4  b.py --engine E --tag T --plan "short:128:2,p1k:8:3,p4k:8:2,p16k:8:2" [--env K=V ...] [--extra "--spec 2 ..."]
5
6plan item = case:max_new:repeat (cases are the token-id files in /mnt/models/strata-test/prompts).  Output: out/<tag>.json
7with per-request prompt tok/s, decode tok/s and the tokens; one summary line per request on stderr.  A new first token per
8repeat keeps the prompt from being served out of the conversation cache (the case then differs by 1 token, same for every arm).
9"""
10import argparse, json, os, queue, shlex, subprocess, sys, threading, time
11
12ROOT = "/mnt/models/strata-test"
13W = f"{ROOT}/arc037"
14M = "/mnt/models/llama/Qwen3.8-Flash-Next-GSQ-RCO-ISTA-DASLab"
15S1 = f"{M}/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf"
16S2 = f"{M}/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf"
17
18
19def main():
20    ap = argparse.ArgumentParser()
21    ap.add_argument("--engine", required=True)
22    ap.add_argument("--tag", required=True)
23    ap.add_argument("--plan", default="short:128:2,p1k:8:3,p4k:8:2,p16k:8:2")
24    ap.add_argument("--env", action="append", default=[])
25    ap.add_argument("--extra", default="--spec 2 --spec-min-p 0.5 --pipeline-windows 2 --mtp-draft-vocab " + f"{W}/src/data/draft_vocab_en.bin")
26    ap.add_argument("--layer-split", default="auto")
27    ap.add_argument("--gpus", default="")
28    ap.add_argument("--max-context", type=int, default=32768)
29    ap.add_argument("--timeout", type=float, default=1800)
30    a = ap.parse_args()
31    os.makedirs(f"{W}/out", exist_ok=True)
32    env = dict(os.environ)
33    env.update({"ONEAPI_DEVICE_SELECTOR": "level_zero:*", "SYCL_CACHE_PERSISTENT": "0", "ZES_ENABLE_SYSMAN": "1",
34                "STRATA_VERIFY_NO_HOST": "1"})
35    if a.gpus:
36        env["ONEAPI_DEVICE_SELECTOR"] = "level_zero:" + a.gpus
37    for kv in a.env:
38        k, _, v = kv.partition("=")
39        env[k] = v
40    args = ["--serve", "--pack", f"{ROOT}/data/packs/iq3_s", "--native", S1, "--ple-gguf", S2,
41            "--expert-profile", f"{W}/src/data/expert-profile-sycl.bin", "--expert-cache", "auto", "--prefill", "auto",
42            "--mtp", f"{ROOT}/data/mtp/rt", "--max-context", str(a.max_context), "--kv", "int8", "--ple-io", "ram",
43            "--stream-experts", "--vram-reserve-mib", "1024", "--layer-split", a.layer_split] + shlex.split(a.extra)
44    cmdline = "source /opt/intel/oneapi/setvars.sh >/dev/null 2>&1; exec " + " ".join(shlex.quote(x) for x in [a.engine] + args)
45    log = open(f"{W}/out/{a.tag}.err", "w")
46    p = subprocess.Popen(["bash", "-c", cmdline], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=log, env=env, text=True, bufsize=1)
47    q = queue.Queue()
48    threading.Thread(target=lambda: ([q.put(l.rstrip("\n")) for l in p.stdout], q.put("__EOF__")), daemon=True).start()
49
50    def prompt(case):
51        return [int(x) for x in open(f"{ROOT}/prompts/{case}.txt").read().split()]
52
53    def gen(ids, n):
54        p.stdin.write(f"GEN {n} " + ",".join(map(str, ids)) + "\n"); p.stdin.flush()
55        toks, t0 = [], time.time()
56        while True:
57            try:
58                l = q.get(timeout=1.0)
59            except queue.Empty:
60                if p.poll() is not None: raise RuntimeError("engine exited %s" % p.returncode)
61                if time.time() - t0 > a.timeout: raise TimeoutError("request")
62                continue
63            if l == "__EOF__": raise RuntimeError("engine closed stdout")
64            if l.startswith("T "): toks.append(int(l.split()[1]))
65            elif l.startswith("DONE"): return l.split(), toks
66            elif l.startswith("ERR"): raise RuntimeError(l)
67
68    res = []
69    try:
70        d, _ = gen(prompt("short"), 8)   # warm-up
71        for item in a.plan.split(","):
72            case, n, rep = item.split(":")
73            for r in range(int(rep)):
74                ids = [1000 + r] + prompt(case)
75                d, toks = gen(ids, int(n))
76                g, pt, pms, dms = int(d[1]), int(d[2]), float(d[3]), float(d[4])
77                rec = {"case": case, "rep": r, "prompt_tokens": pt, "prompt_ms": pms, "pp": pt / pms * 1000 if pms else 0,
78                       "generated": g, "decode_ms": dms, "tg": g / dms * 1000 if dms else 0, "tokens": toks}
79                res.append(rec)
80                print(f"[{a.tag}] {case}#{r} pt={pt} pp={rec['pp']:.1f} gen={g} tg={rec['tg']:.1f}", file=sys.stderr, flush=True)
81    finally:
82        try: p.stdin.write("QUIT\n"); p.stdin.flush()
83        except Exception: pass
84        try: p.wait(timeout=60)
85        except subprocess.TimeoutExpired: p.kill()
86        log.close()
87        json.dump({"tag": a.tag, "engine": a.engine, "env": a.env, "extra": a.extra, "results": res}, open(f"{W}/out/{a.tag}.json", "w"))
88
89
90main()