omega-principia
This project has not described itself yet.
Brought by drakestapleton
omega-principia / scripts / replay_adaptive_samples.py
| 1 | """Reproduce raw specialist outputs and measure sampler RSS, CPU and wall time.""" |
| 2 | import argparse |
| 3 | import json |
| 4 | import resource |
| 5 | import sys |
| 6 | import time |
| 7 | from pathlib import Path |
| 8 | sys.path.insert(0,str(Path(__file__).resolve().parent/"adaptive_collider")) |
| 9 | from council import sample |
| 10 | |
| 11 | def main(): |
| 12 | parser=argparse.ArgumentParser() |
| 13 | parser.add_argument("archive",type=Path) |
| 14 | args=parser.parse_args() |
| 15 | rows=[] |
| 16 | for frozen in sorted(args.archive.glob("live-*/frozen.json")): |
| 17 | pair=json.loads(frozen.read_text()) |
| 18 | for i,record in enumerate(pair["trace"]): |
| 19 | start=time.monotonic() |
| 20 | observed=[] |
| 21 | sample(record["role"],bytes.fromhex(record["prompt_hex"]),observed) |
| 22 | check=observed[0] |
| 23 | for key in ("sampler","base","strand","tokens","top_k","temperature_milli","output_hex"): |
| 24 | if check.get(key)!=record.get(key) or key not in check: |
| 25 | raise ValueError(f"{frozen.parent.name} {record['role']} differs at {key}") |
| 26 | rows.append({"pair":frozen.parent.name,"sample":i,"role":record["role"], |
| 27 | "cpu_s":check["cpu_s"],"wall_s":time.monotonic()-start}) |
| 28 | print(json.dumps({"replayed":len(rows),"rows":rows, |
| 29 | "max_sampler_rss_kib":resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss})) |
| 30 | |
| 31 | if __name__=="__main__": |
| 32 | main() |