#!/usr/bin/env python """GAMMA_FAIR run 10 -- read the cache-mode control EARLY, at the epochs it has already reached. Why this exists. Run 1 deviated from the archived IDQL recipe on the four LARGE tasks: `all` caching needs ~240 GB per cell and four of them do not place (job 1884221 sat PEND 55 min at MEMLIMIT 300G), and run_train.sh's own note records a 224 GB `all` cell spending ~29 min of every ~39 min preemption cycle re-running "SequenceDataset: caching get_item calls" -- a livelock. So the large tasks train at `hdf5_cache_mode=low_dim`, and cell `S0Aidql_g0p99ctl` re-trains gamma=0.99 under low_dim on two_piece_expert_play so the deviation is VERIFIED rather than assumed. Until it reproduces, every large-task gamma=0.99 row is read from the archive under a footnote. The control was scoped as "must reproduce epoch-for-epoch" and is only at epoch ~500 of 5000, but that does not mean waiting: caching changes only WHICH BYTES ARE IN RAM, not the sampling order or the loss, so if it is going to diverge it diverges immediately. An early read at the epochs both runs have is therefore the informative one -- and if it already disagrees, four packs' worth of large-task cells are being spent on an unreportable recipe and should be stopped NOW rather than in 27 h. Reads the TensorBoard event files directly (no TB server); compares every scalar tag the two runs share. """ import glob, pathlib, sys, collections ROOT = pathlib.Path("/proj/dmfexp/zwhong/rsm_rise") TASK = "two_piece_expert_play" CTL = ROOT / f"runs/{TASK}/policy/S0Aidql_g0p99ctl_seed0" REF = ROOT / f"runs/{TASK}/policy/S0Aidql_seed0" from tensorboard.backend.event_processing import event_accumulator def series(cell_dir): """Merge every event file under a cell into {tag: {step: value}}, last writer wins per step. A cell has one subdirectory per RESUME (preemption restarts it), each with its own event file, and the steps overlap where a resume replayed from the last checkpoint. Keeping the last value per step is what the archived run's own curve is, so both sides are treated identically. """ out = collections.defaultdict(dict) files = sorted(glob.glob(str(cell_dir / "*/*/logs/tb/**/events.out.tfevents.*"), recursive=True)) for f in files: ea = event_accumulator.EventAccumulator(f, size_guidance={"scalars": 0}) try: ea.Reload() except Exception as e: print(f" [warn] unreadable {f}: {e}") continue for tag in ea.Tags().get("scalars", []): for ev in ea.Scalars(tag): out[tag][ev.step] = ev.value return out, len(files) print(f"[cachectl] control = {CTL}") print(f"[cachectl] archive = {REF}") c, nc = series(CTL) r, nr = series(REF) print(f"[cachectl] control: {nc} event files, {len(c)} scalar tags") print(f"[cachectl] archive: {nr} event files, {len(r)} scalar tags") if not c or not r: print("VERDICT: INCONCLUSIVE -- one side has no scalars yet") sys.exit(0) shared_tags = sorted(set(c) & set(r)) # The loss tags are the ones the control is about; report them first and in full. loss_tags = [t for t in shared_tags if "loss" in t.lower()] other = [t for t in shared_tags if t not in loss_tags] print(f"[cachectl] {len(shared_tags)} shared tags ({len(loss_tags)} loss tags)") worst = 0.0 worst_where = None for tag in loss_tags + other: steps = sorted(set(c[tag]) & set(r[tag])) if not steps: continue rows = [] for s in steps: a, b = c[tag][s], r[tag][s] den = max(abs(a), abs(b), 1e-12) rel = abs(a - b) / den rows.append((s, a, b, rel)) if rel > worst: worst, worst_where = rel, (tag, s, a, b) mx = max(x[3] for x in rows) flag = " <-- DIVERGES" if mx > 0.05 else "" print(f"\n{tag}: {len(steps)} shared steps, max rel diff {mx:.4f}{flag}") for s, a, b, rel in rows[:6]: print(f" step {s:>6} ctl={a:.6g} archive={b:.6g} rel={rel:.4f}") if len(rows) > 6: print(f" ... ({len(rows) - 6} more)") print() if worst_where is None: print("VERDICT: INCONCLUSIVE -- no shared steps between the two runs yet") elif worst <= 0.05: print(f"VERDICT: REPRODUCES so far. Worst relative disagreement {worst:.4f} at " f"{worst_where[0]} step {worst_where[1]} (ctl {worst_where[2]:.6g} vs archive {worst_where[3]:.6g}). " "low_dim caching is not changing the optimisation on this task at the epochs measured.") else: print(f"VERDICT: DIVERGES. Worst relative disagreement {worst:.4f} at {worst_where[0]} " f"step {worst_where[1]} (ctl {worst_where[2]:.6g} vs archive {worst_where[3]:.6g}). " "The large-task cells are NOT the archived recipe -- stop the wave and decide before spending more.")