"""Verify overlapping recorded trajectories across two attempts of the same training run.""" import argparse import gzip import json from pathlib import Path from novel_tokens.runtime import RESULTS, save_json def recorded_outputs(path, stop=None): """Read through the last required update so a continuing gzip stream can be audited.""" updates = {} with gzip.open(path, "rt", encoding="utf-8") as stream: for line in stream: row = json.loads(line) if row["kind"] == "training_outputs": updates[row["step"]] = row["outputs"] if row["step"] == stop: break return updates def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("interrupted", type=Path) parser.add_argument("resumed", type=Path) parser.add_argument("--output",type=Path,default=RESULTS / "restart-audit.json", help="Use a distinct evidence file for each independent restart.") args = parser.parse_args() before = recorded_outputs(args.interrupted) after = recorded_outputs(args.resumed, max(before)) overlap = sorted(before.keys() & after.keys()) report = { "interrupted": args.interrupted.name, "resumed": args.resumed.name, "overlapping_updates": overlap, "rollouts": sum(len(before[i]) for i in overlap), "mismatched_updates": [i for i in overlap if before[i] != after[i]], } save_json(args.output,report) print(json.dumps(report, indent=2)) if not overlap or report["mismatched_updates"]: raise SystemExit(1) if __name__ == "__main__": main()