gpu-head-to-head
aien-dev/gpu-head-to-head
Brought by drakestapleton
gpu-head-to-head / bench / agree.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Output agreement (PROTOCOL.md M6): token counts only, no rates. |
| 3 | |
| 4 | Run inside the pinned vLLM container (needs `tokenizers`): |
| 5 | agree.py <model_dir> <repo> > results/agree-counts.json |
| 6 | For each pair of (arm, round) agreement runs and each prompt id, tokenizes both outputs with the |
| 7 | checkpoint's tokenizer.json and records len_a, len_b, common-prefix length and byte identity. |
| 8 | Rates are computed from these integers in Wolfram. |
| 9 | """ |
| 10 | import glob |
| 11 | import itertools |
| 12 | import json |
| 13 | import sys |
| 14 | |
| 15 | from tokenizers import Tokenizer |
| 16 | |
| 17 | tok = Tokenizer.from_file(sys.argv[1] + "/tokenizer.json") |
| 18 | runs = {} |
| 19 | for path in sorted(glob.glob(sys.argv[2] + "/results/raw/*.jsonl")): |
| 20 | for line in open(path): |
| 21 | r = json.loads(line) |
| 22 | if r["metric"] != "agree" or r["warmup"] or r["arm"] == "STUB": |
| 23 | continue |
| 24 | if r["error"] is None and r["http_status"] == 200: |
| 25 | runs.setdefault("%s-%s" % (r["arm"], r["round"]), {})[r["prompt_id"]] = r["text"] |
| 26 | |
| 27 | out = [] |
| 28 | for a, b in itertools.combinations(sorted(runs), 2): |
| 29 | for pid in sorted(set(runs[a]) & set(runs[b])): |
| 30 | ta = tok.encode(runs[a][pid], add_special_tokens=False).ids |
| 31 | tb = tok.encode(runs[b][pid], add_special_tokens=False).ids |
| 32 | m = 0 |
| 33 | for x, y in zip(ta, tb): |
| 34 | if x != y: |
| 35 | break |
| 36 | m += 1 |
| 37 | out.append({"a": a, "b": b, "prompt": pid, "len_a": len(ta), "len_b": len(tb), |
| 38 | "common_prefix": m, "identical": runs[a][pid] == runs[b][pid]}) |
| 39 | json.dump({"runs": {k: sorted(v) for k, v in runs.items()}, "pairs": out}, sys.stdout, indent=1) |