File size: 3,523 Bytes
21e1acb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
"""Compare a pi0.5 Task-E eval directory against the current ACT/XSA evidence."""

from __future__ import annotations

import argparse
from pathlib import Path
import re
import statistics


RESULT_RE = re.compile(r"\[RESULT\].*?score=([0-9.]+).*?steps=([0-9]+).*?done=(True|False)")
BASKET_RE = re.compile(r"\[BASKET\].*?(object_[123]): .*?inside=(True|False)")

DEFAULT_BASELINE_LOGS = [
    Path("logs/eval_task_e_xsa_final_seed11_recheck.log"),
    Path("logs/eval_task_e_xsa_final_seed12_recheck.log"),
    Path("logs/eval_task_e_xsa_final_seed13_recheck.log"),
    Path("logs/eval_task_e_deployed_xsa_final_seed11_verify.log"),
]
CURRENT_POLICY_SHA = "c3eacae3f1b0ec8ccde9fdc05d680fff119cc2ca70e1f79e4ddd5610c4bbfa93"


def parse_log(path: Path) -> tuple[float | None, dict[str, bool]]:
    if not path.exists():
        return None, {}
    text = path.read_text(errors="replace")
    result = RESULT_RE.search(text)
    baskets = {obj: inside == "True" for obj, inside in BASKET_RE.findall(text)}
    return (float(result.group(1)) if result else None), baskets


def collect_pi05(eval_dir: Path) -> list[tuple[Path, float, dict[str, bool]]]:
    rows = []
    for log in sorted(eval_dir.glob("seed*.log")):
        score, baskets = parse_log(log)
        if score is not None:
            rows.append((log, score, baskets))
    return rows


def print_rows(title: str, rows: list[tuple[Path, float, dict[str, bool]]]) -> None:
    print(f"[{title}]")
    if not rows:
        print("  no complete result logs")
        return
    for path, score, baskets in rows:
        basket_text = ", ".join(f"{obj}={inside}" for obj, inside in sorted(baskets.items()))
        print(f"  {path}: score={score:.2f}; {basket_text or 'basket=unknown'}")
    scores = [score for _, score, _ in rows]
    print(
        f"  summary: n={len(scores)} mean={statistics.fmean(scores):.2f} "
        f"min={min(scores):.2f} max={max(scores):.2f}"
    )


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("eval_dir", type=Path)
    parser.add_argument("--repo", type=Path, default=Path.cwd())
    args = parser.parse_args()

    repo = args.repo.resolve()
    eval_dir = args.eval_dir if args.eval_dir.is_absolute() else repo / args.eval_dir
    baseline_rows = []
    for log in DEFAULT_BASELINE_LOGS:
        path = log if log.is_absolute() else repo / log
        score, baskets = parse_log(path)
        if score is not None:
            baseline_rows.append((path, score, baskets))

    pi05_rows = collect_pi05(eval_dir)
    print(f"[CURRENT_DEPLOYED_POLICY_SHA] {CURRENT_POLICY_SHA}")
    print_rows("ACT_XSA_BASELINE_EVIDENCE", baseline_rows)
    print_rows("PI05_CANDIDATE_EVIDENCE", pi05_rows)

    if len(pi05_rows) < 3:
        print("[DECISION] HOLD: pi0.5 does not yet have all seed11/12/13 results.")
        return 0

    pi05_scores = [score for _, score, _ in pi05_rows]
    baseline_independent = [score for path, score, _ in baseline_rows if "xsa_final_seed" in path.name]
    baseline_mean = statistics.fmean(baseline_independent) if baseline_independent else 0.0
    pi05_mean = statistics.fmean(pi05_scores)

    if min(pi05_scores) >= baseline_mean and pi05_mean > baseline_mean:
        print("[DECISION] REVIEW_FOR_DEPLOY: pi0.5 is clearly better on this evidence set.")
    else:
        print("[DECISION] HOLD_ACT_XSA: pi0.5 is not clearly better than the current ACT/XSA baseline.")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())