okami.mom/strata

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

Niko1221Merge f-own-3v (aec86299d) into f-own-int: our own Qwen vision tower (mtmd stays the default)0479b72e9

main
2.8 KiB64 linesraw
1#!/usr/bin/env python3
2"""Times one reader on one picture: image-to-embedding time (median of --repeat encodes after the first) and the reader's GPU memory.
3
4    python3 bench_enc.py --helper <strata-vision or strata-vision-own> --mmproj <mmproj.gguf> --model <text model or x> --image <picture> [--tower own]
5                         [--gpu] [--max-tokens 1024] [--repeat 8] [--out <file for the embeddings>] [--env NAME=VALUE ...]
6Prints one line: label, tokens, median ms, min ms, peak GPU MiB (nvidia-smi, by pid).  Used to compare settings of the GPU tower (STRATA_VIT_ROWS, STRATA_VIT_SCORES).
7"""
8import argparse
9import os
10import statistics
11import subprocess
12import sys
13
14
15def main():
16    ap = argparse.ArgumentParser()
17    ap.add_argument("--helper", required=True)
18    ap.add_argument("--mmproj", required=True)
19    ap.add_argument("--model", default="x")
20    ap.add_argument("--image", required=True)
21    ap.add_argument("--tower", default="own")
22    ap.add_argument("--gpu", action="store_true")
23    ap.add_argument("--max-tokens", type=int, default=1024)
24    ap.add_argument("--repeat", type=int, default=8)
25    ap.add_argument("--out", default="/tmp/bench_enc.sve")
26    ap.add_argument("--label", default="")
27    ap.add_argument("--env", action="append", default=[])
28    a = ap.parse_args()
29    args = [a.helper, "--mmproj", a.mmproj, "--model", a.model, "--tower", a.tower, "--max-tokens", str(a.max_tokens)]
30    if a.gpu:
31        args.append("--gpu")
32    env = dict(os.environ)
33    for kv in a.env:
34        k, _, v = kv.partition("=")
35        env[k] = v
36    p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, env=env)
37    if not p.stdout.readline().startswith("READY"):
38        raise SystemExit("reader did not start")
39    ms, tokens, peak = [], "?", 0
40    for i in range(a.repeat + 1):
41        p.stdin.write("ENC %s %s\n" % (os.path.abspath(a.image), a.out))
42        p.stdin.flush()
43        r = p.stdout.readline().split()
44        if not r or r[0] != "OK":
45            raise SystemExit("encode failed: %s" % " ".join(r))
46        tokens = r[1]
47        if i:
48            ms.append(float(r[4]))
49        try:
50            smi = subprocess.run(["nvidia-smi", "--query-compute-apps=pid,used_memory", "--format=csv,noheader,nounits"], capture_output=True, text=True, timeout=30).stdout
51            for line in smi.splitlines():
52                pid, _, mem = line.partition(",")
53                if pid.strip() == str(p.pid) and mem.strip().isdigit():
54                    peak = max(peak, int(mem.strip()))
55        except Exception:  # noqa: BLE001
56            pass
57    p.stdin.write("QUIT\n")
58    p.stdin.flush()
59    p.wait(timeout=30)
60    print("%-28s tokens %s  median %.0f ms  min %.0f ms  peak %d MiB" % (a.label or " ".join(a.env) or "default", tokens, statistics.median(ms), min(ms), peak))
61
62
63if __name__ == "__main__":
64    main()