latent_backtrack / scripts /bt_summary.sh
Avra98's picture
Add training code (same as GitHub reasoning-by-superposition-latent)
8f46582 verified
Raw
History Blame Contribute Delete
2.13 kB
#!/usr/bin/env bash
# Summarize backtrack frequency by frontier stage for the W=1 tight-gate runs.
cd /egr/research-slim/ghoshavr/reasoning-by-superposition-main
python3 - <<'PY'
import re, sys
from collections import defaultdict
runs = [
"L15_w1_prom098_bt098",
"L15_w1_prom099_bt099",
"L15_w2_prom095_bt095",
"L15_w5_prom095_bt095",
"L15_push_2L_ce95_100k_w1", # baseline W=1 prom/bt 0.95
]
for name in runs:
path = f"logs/{name}.log"
try:
lines = open(path, errors="ignore")
except FileNotFoundError:
print(f"=== {name}: no log yet ===\n")
continue
frontier = 6
by = defaultdict(lambda: {"evals": 0, "bt": 0, "targets": defaultdict(int)})
prom = 0
ep = 0
for line in lines:
m = re.search(r"train epoch (\d+)/", line)
if m:
ep = int(m.group(1))
m = re.search(r"PROMOTE stage (\d+) -> (\d+)", line)
if m:
frontier = int(m.group(2)); prom += 1
m = re.search(r"HOLD at stage (\d+)", line)
if m:
frontier = int(m.group(1))
m = re.search(r"target_stage=(\d+|None)", line)
if m:
by[frontier]["evals"] += 1
if m.group(1) == "None":
continue
by[frontier]["bt"] += 1
by[frontier]["targets"][int(m.group(1))] += 1
total_e = sum(d["evals"] for d in by.values())
total_b = sum(d["bt"] for d in by.values())
hold = ""
for line in open(path, errors="ignore"):
if "[acc-stage]" in line:
hold = line.strip()
print(f"=== {name} ep={ep} promotes={prom} BT={total_b}/{total_e} ({(total_b/total_e if total_e else 0):.0%}) ===")
print(f" {hold}")
print(f" {'front':>5} {'evals':>5} {'BT':>4} {'rate':>5} repair targets")
for f in sorted(by):
d = by[f]
rate = d["bt"] / d["evals"] if d["evals"] else 0
tops = sorted(d["targets"].items(), key=lambda x: -x[1])[:4]
ts = ", ".join(f"s{t}x{c}" for t, c in tops) if tops else "-"
print(f" {f:>5} {d['evals']:>5} {d['bt']:>4} {rate:>4.0%} {ts}")
print()
PY