|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Post-run script: reads 3 seed logs, fills in README.md and submission.json. |
| 4 | +Run locally after scp-ing logs from RunPod. |
| 5 | +
|
| 6 | +Usage: |
| 7 | + python3 finalize_submission.py [submission_dir] |
| 8 | + # defaults to the directory containing this script |
| 9 | +""" |
| 10 | +import json |
| 11 | +import os |
| 12 | +import re |
| 13 | +import sys |
| 14 | +from pathlib import Path |
| 15 | + |
| 16 | +def extract_metrics(log_path: str) -> dict: |
| 17 | + """Extract key metrics from a training log.""" |
| 18 | + text = Path(log_path).read_text() |
| 19 | + metrics = {} |
| 20 | + |
| 21 | + # Pre-TTT BPB (int6 roundtrip before TTT) |
| 22 | + m = re.findall(r"final_int6_roundtrip_exact.*?val_bpb:([\d.]+)", text) |
| 23 | + if m: |
| 24 | + metrics["pre_ttt_bpb"] = float(m[-1]) |
| 25 | + |
| 26 | + # BPB from sliding window eval (the submission score — post-TTT) |
| 27 | + m = re.findall(r"final_int6_sliding_window_exact.*?val_bpb:([\d.]+)", text) |
| 28 | + if m: |
| 29 | + metrics["bpb"] = float(m[-1]) |
| 30 | + |
| 31 | + # Artifact size |
| 32 | + m = re.findall(r"Total submission size.*?(\d+)\s*bytes", text) |
| 33 | + if m: |
| 34 | + metrics["artifact"] = int(m[-1]) |
| 35 | + |
| 36 | + # Steps |
| 37 | + m = re.findall(r"stopping_early.*?step[: ]*(\d+)", text) |
| 38 | + if not m: |
| 39 | + m = re.findall(r"step[: ]*(\d+)", text) |
| 40 | + if m: |
| 41 | + metrics["steps"] = int(m[-1]) |
| 42 | + |
| 43 | + return metrics |
| 44 | + |
| 45 | + |
| 46 | +def main(): |
| 47 | + sub_dir = Path(sys.argv[1]) if len(sys.argv) > 1 else Path(__file__).parent |
| 48 | + seeds = [42, 1337, 2024] |
| 49 | + results = {} |
| 50 | + |
| 51 | + print("Extracting metrics from logs...") |
| 52 | + for seed in seeds: |
| 53 | + log = sub_dir / f"train_seed{seed}.log" |
| 54 | + if not log.exists(): |
| 55 | + print(f" WARNING: {log} not found") |
| 56 | + continue |
| 57 | + m = extract_metrics(str(log)) |
| 58 | + results[seed] = m |
| 59 | + print(f" Seed {seed}: bpb={m.get('bpb', '?')}, artifact={m.get('artifact', '?')}, steps={m.get('steps', '?')}") |
| 60 | + |
| 61 | + if len(results) < 3: |
| 62 | + print(f"\nERROR: Only found {len(results)}/3 seed logs. Cannot finalize.") |
| 63 | + sys.exit(1) |
| 64 | + |
| 65 | + bpbs = [results[s]["bpb"] for s in seeds] |
| 66 | + mean_bpb = sum(bpbs) / len(bpbs) |
| 67 | + std_bpb = (sum((x - mean_bpb) ** 2 for x in bpbs) / len(bpbs)) ** 0.5 |
| 68 | + max_artifact = max(results[s]["artifact"] for s in seeds) |
| 69 | + mean_artifact_mb = sum(results[s]["artifact"] for s in seeds) / 3 / 1_000_000 |
| 70 | + |
| 71 | + print(f"\n Mean BPB: {mean_bpb:.4f} (std {std_bpb:.4f})") |
| 72 | + print(f" Max artifact: {max_artifact} bytes ({max_artifact/1_000_000:.2f} MB)") |
| 73 | + |
| 74 | + # Validation checks |
| 75 | + sota = 1.1194 |
| 76 | + delta = mean_bpb - sota |
| 77 | + print(f"\n vs SOTA ({sota}): {delta:+.4f} nats") |
| 78 | + if delta < -0.005: |
| 79 | + print(f" PASS: Beats SOTA by {abs(delta):.4f} nats") |
| 80 | + elif delta < 0: |
| 81 | + print(f" CLOSE: Improves by {abs(delta):.4f} nats but < 0.005 threshold") |
| 82 | + print(f" Consider submitting as non-record if techniques are novel.") |
| 83 | + else: |
| 84 | + print(f" DOES NOT BEAT SOTA. Consider as non-record submission.") |
| 85 | + |
| 86 | + if max_artifact > 16_000_000: |
| 87 | + print(f" FAIL: Artifact exceeds 16MB ({max_artifact} bytes)") |
| 88 | + else: |
| 89 | + print(f" PASS: All artifacts under 16MB") |
| 90 | + |
| 91 | + # Update submission.json |
| 92 | + json_path = sub_dir / "submission.json" |
| 93 | + sj = json.loads(json_path.read_text()) |
| 94 | + sj["val_bpb"] = round(mean_bpb, 4) |
| 95 | + sj["bytes_total"] = max_artifact |
| 96 | + sj["blurb"] = ( |
| 97 | + f"LeakyReLU(0.5)^2 activation + XSA on last 4 layers + Partial RoPE + LN Scale " |
| 98 | + f"+ VE128 + EMA/SWA + GPTQ-lite int6 + zstd-22. " |
| 99 | + f"Built on PR #549 stack. 3-seed mean: {mean_bpb:.4f} (std {std_bpb:.4f}). " |
| 100 | + f"All artifacts under 16MB." |
| 101 | + ) |
| 102 | + json_path.write_text(json.dumps(sj, indent=2) + "\n") |
| 103 | + print(f"\n Updated {json_path}") |
| 104 | + |
| 105 | + # Update README.md |
| 106 | + readme_path = sub_dir / "README.md" |
| 107 | + readme = readme_path.read_text() |
| 108 | + |
| 109 | + # Fill header |
| 110 | + readme = readme.replace("FILL_BPB", f"{mean_bpb:.4f}") |
| 111 | + readme = readme.replace("FILL_MB", f"{mean_artifact_mb:.2f}") |
| 112 | + |
| 113 | + # Fill results table |
| 114 | + for seed in seeds: |
| 115 | + r = results[seed] |
| 116 | + old_line = f"| {seed} | FILL | FILL | FILL |" |
| 117 | + new_line = ( |
| 118 | + f"| {seed} | {r.get('steps', '?')} | {r['bpb']:.4f} " |
| 119 | + f"| {r['artifact']/1_000_000:.2f} MB |" |
| 120 | + ) |
| 121 | + readme = readme.replace(old_line, new_line) |
| 122 | + |
| 123 | + # Fill mean/std |
| 124 | + readme = readme.replace("**Mean: FILL | Std: FILL**", f"**Mean: {mean_bpb:.4f} | Std: {std_bpb:.4f}**") |
| 125 | + |
| 126 | + readme_path.write_text(readme) |
| 127 | + print(f" Updated {readme_path}") |
| 128 | + |
| 129 | + print(f"\n{'='*50}") |
| 130 | + print("SUBMISSION READY. Next steps:") |
| 131 | + print(f" 1. Review README.md and submission.json") |
| 132 | + print(f" 2. git checkout -b submission/sunnypatneedi-leakyrelu-xsa") |
| 133 | + print(f" 3. git add {sub_dir.relative_to(sub_dir.parent.parent.parent)}/") |
| 134 | + print(f" 4. git commit -m 'Add submission: LeakyReLU + XSA'") |
| 135 | + print(f" 5. git push origin submission/sunnypatneedi-leakyrelu-xsa") |
| 136 | + print(f" 6. Open PR at: https://github.com/openai/parameter-golf/compare") |
| 137 | + |
| 138 | + |
| 139 | +if __name__ == "__main__": |
| 140 | + main() |
0 commit comments