Add parity_check.py
Browse files- parity_check.py +58 -0
parity_check.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Parity: the released fp16 package must reproduce the frozen pointer_v2 strict outcomes on AndroidControl test steps.
|
| 2 |
+
Streams the dataset and keeps only the steps it checks (the 8 GB Mac cannot hold the whole file next to the model).
|
| 3 |
+
Usage (repo root): .venv/bin/python release/milo-pointer/parity_check.py [n]"""
|
| 4 |
+
|
| 5 |
+
import gzip, json, sys, time
|
| 6 |
+
from collections import Counter
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
ROOT = Path(__file__).resolve().parents[2]
|
| 10 |
+
sys.path[:0] = [str(ROOT / "bench"), str(Path(__file__).parent)]
|
| 11 |
+
from ac_frontier import DATA, strict_ok
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def wanted_test_rows(want): # same history/consequence string as ac_frontier.test_rows
|
| 15 |
+
def sig(r):
|
| 16 |
+
return Counter((e["text"] or e["desc"] or e["rid"], e["cls"]) for e in r["els"])
|
| 17 |
+
|
| 18 |
+
out, prev, t = {}, None, -1
|
| 19 |
+
for l in gzip.open(DATA, "rt"):
|
| 20 |
+
r = json.loads(l)
|
| 21 |
+
s = sig(r)
|
| 22 |
+
if prev and prev[0] == r["ep"] and prev[1] == r["instr"].strip():
|
| 23 |
+
j = sum((s & prev[3]).values()) / max(sum((s | prev[3]).values()), 1)
|
| 24 |
+
r["hist"] = (
|
| 25 |
+
f"repeat of last step (last action {prev[2]}), screen {int(round(j * 10)) * 10}% unchanged"
|
| 26 |
+
)
|
| 27 |
+
else:
|
| 28 |
+
r["hist"] = "new step" + (f" (last action {prev[2]})" if prev and prev[0] == r["ep"] else "")
|
| 29 |
+
prev = (r["ep"], r["instr"].strip(), r["action"]["action_type"], s)
|
| 30 |
+
if r["split"] == "test":
|
| 31 |
+
t += 1
|
| 32 |
+
if t in want:
|
| 33 |
+
out[t] = r
|
| 34 |
+
return out
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
n = int(sys.argv[1]) if len(sys.argv) > 1 else 200
|
| 39 |
+
ref = [r["strict"] for r in json.load(open(ROOT / "training/ac/pointer_v2/local_eval.json"))]
|
| 40 |
+
idx = json.load(open(ROOT / "bench/ac_sample1000.json"))[:n]
|
| 41 |
+
T = wanted_test_rows(set(idx))
|
| 42 |
+
from milo_pointer import MiloPointer
|
| 43 |
+
|
| 44 |
+
m = MiloPointer.load(Path(__file__).parent)
|
| 45 |
+
same = ok = 0
|
| 46 |
+
ts = []
|
| 47 |
+
for i in idx:
|
| 48 |
+
r = T[i]
|
| 49 |
+
t0 = time.time()
|
| 50 |
+
p = m.predict(r["goal"], r["instr"], r["els"], r["w"], r["h"], r["hist"])
|
| 51 |
+
ts.append(time.time() - t0)
|
| 52 |
+
s = strict_ok(r, p)
|
| 53 |
+
ok += s
|
| 54 |
+
same += s == bool(ref[i])
|
| 55 |
+
ts.sort()
|
| 56 |
+
print(
|
| 57 |
+
f"n={n} released {ok} vs frozen {sum(ref[i] for i in idx)}; same outcome {same}/{n}; median {1000*ts[n//2]:.0f} ms"
|
| 58 |
+
)
|