okami.mom/strata

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

Niko1221tuning tests: a Python stub engine (READY/PP/T/DONE) started as [sys.executable, stub.py] replaces the .sh stubs on every OSf7e12d23c

main
1.8 KiB52 linesraw
1#!/usr/bin/env python3
2"""A stub engine for exercising `strata tune run` end to end, on every OS.
3
4Run it as ``[sys.executable, "stub_engine.py", "--serve", ...]`` (``strata_control.tuning.engine_command``
5does that for any ``.py`` engine). It speaks the real serve protocol (READY / PP / T / DONE) and
6makes its decode speed depend on one flag, so a sweep has something real to find. It is NOT a model
7and its numbers mean nothing about any hardware -- it exists so the *sweep machinery* can be tested
8without weights.
9
10    --kv int8   decodes at 200 tok/s
11    anything else (including --kv fp16) decodes at 100 tok/s
12
13The prompt's length comes from the GEN line's token list, so the workload is genuinely the one the
14caller asked for.
15"""
16import sys
17
18
19def main(argv):
20    kv = "unknown"
21    for index, arg in enumerate(argv):
22        if arg == "--kv" and index + 1 < len(argv):
23            kv = argv[index + 1]
24    if "--help" in argv:
25        sys.stderr.write("usage:\n  --kv KV\n  --ple-io MODE\n")
26        return 0
27    out = sys.stdout
28    out.write("READY 32768 stop\n")
29    out.flush()
30    for raw in sys.stdin:
31        line = raw.strip()
32        if line == "QUIT" or not line:
33            return 0
34        if not line.startswith("GEN"):
35            continue
36        fields = line.split()
37        count = len(fields[-1].split(","))
38        try:
39            max_new = int(fields[1])
40        except (IndexError, ValueError):
41            max_new = 8
42        decode_ms = 50.0 if kv == "int8" else 100.0
43        out.write(f"PP {count} {count} 200.0 2560.0\n")
44        for i in range(max_new):          # one T per token: the harness cross-checks the stream against DONE
45            out.write(f"T {i}\n")
46        out.write(f"DONE {max_new} {count} 200.0 {decode_ms} stop 0 0\n")
47        out.flush()
48    return 0
49
50
51if __name__ == "__main__":
52    sys.exit(main(sys.argv[1:]))