rsm_rise_code / rsm_rise /scripts /all_tasks_table.py
rli14's picture
rsm_rise code snapshot (HF_PUSH_ALL) (part 11)
c6a8401 verified
Raw History Blame Contribute Delete
13.3 kB
"""One table of every task: our arms vs the RISE paper's Table I, with the RSM recipe spelled out."""
from __future__ import annotations
import glob, json, os, re
from collections import defaultdict
ROOT = "/proj/dmfexp/zwhong/rsm_rise"
PAPER = {
"square_expert_play": ("square-peg (Coverage)", dict(BC=18.7, IDQL=19.6, RISE=50.7)),
"square_expert_suboptimal": ("square-peg (Suboptimal)", dict(BC=8.0, IDQL=41.3, RISE=56.0)),
"square_sub_paper": ("square-peg (Suboptimal) Table IV", dict(BC=8.0, IDQL=41.3, RISE=56.0)),
"threading_expert_play": ("threading (Coverage)", dict(BC=17.3, IDQL=9.8, RISE=22.7)),
"threading_paper": ("threading (Coverage) Table IV", dict(BC=17.3, IDQL=9.8, RISE=22.7)),
"mug_expert_suboptimal": ("mug-cleanup (Suboptimal)", dict(BC=31.3, IDQL=36.7, RISE=40.7)),
"mug_paper": ("mug-cleanup (Suboptimal) Table IV", dict(BC=31.3, IDQL=36.7, RISE=40.7)),
"two_piece_expert_play": ("piece-assembly (Coverage)", dict(BC=14.7, IDQL=16.3, RISE=70.7)),
"two_piece_expert_play_tipping": ("piece-assembly tip (Coverage)", dict(BC=0.0, IDQL=8.0, RISE=51.3)),
"piecetip_paper": ("piece-assembly tip (Cov) Table IV", dict(BC=0.0, IDQL=8.0, RISE=51.3)),
"two_piece_expert_suboptimal": ("piece-assembly tip (Suboptimal)", dict(BC=20.0, IDQL=35.7, RISE=36.0)),
"piecesub_paper": ("piece-assembly tip (Sub) Table IV", dict(BC=20.0, IDQL=35.7, RISE=36.0)),
}
# NOTE: eval_horizon is excluded on purpose -- those cells run 600/800-step horizons and are not
# the reported protocol; eval_val is excluded because seed 100 is the checkpoint-selection set.
COUNTS = {"square_expert_suboptimal": (100, 100), "two_piece_expert_suboptimal": (20, 100),
"two_piece_expert_play": (200, 199), "threading_expert_play": (250, 200),
"mug_expert_suboptimal": (20, 100), "square_expert_play": (200, 224),
"two_piece_expert_play_tipping": (200, 504), "square_sub_paper": (20, 80), "piecesub_paper": (10, 100),
"piecetip_paper": (200, 303), "threading_paper": (200, 200), "mug_paper": (20, 85)}
def traj(t):
e, n = COUNTS.get(t, ("?", "?")); return f"{e} expert / {n} non-expert"
# --- ARM GUARD (owner, 2026-09-22 06:55Z "we should be using membership and no more progress";
# --- added by BETA_CHAIN run 47, 2026-09-25, after measuring that this loader had none).
# Cell names are "E1-<modelTag>-R<beta>-...". The classifier below used to bucket EVERY "E1-" cell
# as RSM on the prefix alone, so a TD-Flow / LeWM / DINO-WM / DF cell -- and, measurably, a retired
# oracle PROGRESS head -- could win the RSM column of this table. Measured on 2026-09-25: the
# published two_piece_expert_suboptimal RSM cell was E1-Mprog-R0.95-1-N128-argmax-PROGFINAL-es0-sS0As2,
# a progress head. Tags are matched on the model token only, never on a substring of the whole name.
_OTHER_SCORER = { # tag -> the arm it really is; excluded from the RSM column, never silently pooled
"TDF": "TD-Flow", "DWM": "DINO-WM", "DINOWM": "DINO-WM", "LEWM": "LeWM", "LeWM": "LeWM",
"DFVAL": "DF", "IDQL": "IDQL", "IFQL": "IFQL",
}
_PROGRESS_RE = re.compile(r"prog", re.I) # Mprog / Lprog / ...: the retired oracle progress head
def model_tag(name):
m = re.match(r"E1-([A-Za-z0-9_]+)-", name)
return m.group(1) if m else None
def rsm_arm_of(name):
"""Which arm an E1- cell really belongs to: 'RSM', another scorer's name, or None to drop it."""
tag = model_tag(name)
if tag is None: return "RSM" # unparseable tag: leave as before
if _PROGRESS_RE.search(tag): return None # owner: no progress head in any table
for pre, arm in _OTHER_SCORER.items():
if tag.startswith(pre): return arm
return "RSM"
DIRS = ["eval_final", "eval_final_e3000", "eval", "eval_v2", "eval_v1", "eval_v1b"]
MIN_N = 50
def epoch_of(name, path):
m = re.search(r"[-_]e(?:p)?(\d{3,4})[-_.]", name)
if m: return int(m.group(1))
if "eval_final_e3000" in path: return 3000
if "/eval_final/" in path: return 5000
m = re.search(r"_ep(\d{3,4})", name)
if m: return int(m.group(1))
# stage-0 cells written at the end of training carry no epoch marker (e.g. "S3H1_seed0_es0"):
# those are the final, epoch-5000 policies.
if re.match(r"(S0A|S0B|S3H1)_seed\d+(_es\d+)?$", name): return 5000
return 0
def recipe(name):
"""E1-<model>-R<beta>-<L>-N<n>-<rule>-... -> (model, beta, L, N, particles, score)"""
m = re.match(r"E1-([A-Za-z0-9_]+)-R([0-9.]+)-(\d+)-N(\d+)-([a-z0-9.]+)", name)
if not m: return None
p = re.search(r"-P(\d+)(?:r\d+)?-(prob|logit|conformal_lcb)", name)
return dict(model=m.group(1), beta=float(m.group(2)), L=int(m.group(3)), N=int(m.group(4)),
rule=m.group(5), particles=int(p.group(1)) if p else None, score=p.group(2) if p else None,
chain=is_chain(name))
# --- READ-OUT LABEL (BETA_CHAIN run 50, 2026-09-25). The third field of an "E1-<model>-R<beta>-<L>-"
# name means TWO different things: for a coin-terminated chain cell (tag "-ch-") it is the CAP derived
# from the 1e-3 truncation tail, for a pre-chain cell it is the fixed DEPTH of the retired deterministic
# fold. Printing a bare "L=1" lets a reader of the corrected flagship read a fold depth as a chain cap,
# which is the same class of defect as an unscoped audit: every number right, the label wrong.
# Measured 2026-09-25 over this loader's DIRS scope: 1102 E1 cells, 0 of them chain-tagged -- i.e. the
# RSM column of docs/ALL_TASKS.md is entirely the retired fold. The census below prints that split, and
# says so loudly if a chain cell ever enters the scope (the column would then mix two read-outs).
def is_chain(name):
return "-ch-" in name or bool(re.search(r"-ch\d*-", name))
def main():
rows = {}
readout_census = {"fold": 0, "chain": 0} # run 50: which read-out this table's RSM cells use
for task in PAPER:
arms = defaultdict(list) # arm -> [(epoch, sr, n, name)]
for d in DIRS:
for f in glob.glob(f"{ROOT}/runs/{task}/{d}/*.json"):
name = os.path.basename(f)[:-5]
if "-es100" in name: continue
try: j = json.load(open(f))
except Exception: continue
n, sr = j.get("num_episodes") or 0, j.get("success_rate")
if not n or sr is None or n < MIN_N: continue
ep = epoch_of(name, f)
if name.startswith("S3H4"): a = "RISE flagship (S0A + critic)"
elif "-random-" in name: a = "random-of-N"
elif "-permuted-" in name: a = "permuted"
elif name.startswith("BC-s0a"): a = "RISE policy, greedy (S0A)"
elif name.startswith("BC-"): a = "BC-unified (S0B)" # the FINAL BC control runs the S0B policy
elif name.startswith("E1-"):
a = rsm_arm_of(name)
if a is None: continue # progress head -- dropped, never pooled
if a == "RSM":
readout_census["chain" if is_chain(name) else "fold"] += 1
else:
m = re.match(r"(S0A|S0B|S3H1)_seed", name)
if not m: continue
a = {"S0A": "RISE policy, greedy (S0A)", "S0B": "BC-unified (S0B)", "S3H1": "BC-expert (S3H1)"}[m.group(1)]
arms[a].append((ep, sr, n, name))
out = {}
for a, v in arms.items():
eps = {e for e, _, _, _ in v}
# the paper trains every network for 5000 epochs; use that when we have it, else the highest we do
top_ep = 5000 if 5000 in eps else max(eps)
at = [x for x in v if x[0] == top_ep]
if a == "RSM": # best recipe at that epoch, pooled over its eval seeds
bestname = max(at, key=lambda x: x[1])[3]
if rsm_arm_of(bestname) != "RSM": # LOUD GUARD: must be unreachable
raise SystemExit(f"ARM GUARD: {task}: a non-RSM/progress cell reached the RSM "
f"column: {bestname!r} (model tag {model_tag(bestname)!r})")
r = recipe(bestname) or {}
key = re.sub(r"-es\d-", "-", bestname)
same = [x for x in at if re.sub(r"-es\d-", "-", x[3]) == key]
n = sum(x[2] for x in same); s = sum(x[1] * x[2] for x in same)
out[a] = (100 * s / n, n, top_ep, r)
else:
n = sum(x[2] for x in at); s = sum(x[1] * x[2] for x in at)
out[a] = (100 * s / n, n, top_ep, {})
rows[task] = out
L = ["# Results across every task", "",
"Our arms against the RISE paper's Table I. Each of our cells is the best available evaluation for that "
"arm at the highest policy epoch it has reached, pooled over the eval seeds run so far "
f"(cells with fewer than {MIN_N} episodes are ignored). `ep` is the policy training epoch; the paper "
"trains every network for 5000, so anything below that is not yet a like-for-like comparison.", "",
"`RISE flagship` is the paper's method as we run it. `RSM` is our successor-model read-out ON THE BC-UNIFIED (S0B) POLICY; its recipe is given as model / beta / read-out / particles.\n\n**Which read-out these RSM numbers use.** Every evaluation in this table comes from the six pre-chain evaluation directories, which hold **0** coin-chain cells (measured 2026-09-25: 1102 `E1-` cells in scope, none carrying the `-ch` tag). So the `L` of a recipe here is the fixed DEPTH of the retired deterministic fold, not the CAP of the coin-terminated beta chain -- the two are written out as `fold L=k` and `chain cap=k` so they cannot be confused. The corrected coin-chain numbers are the flagship table's (`tab:flagship`); the fold read-out is reported there as an ablation (`tab:ablation_betarec`).", "", "\n**Baseline labels, in the paper's terms (RISE Sec. V):**\n- **BC-expert** = the paper's *Behavior cloning*: diffusion policy trained on the expert demonstrations only (D_E). Our cell `S3H1`.\n- **BC-unified** = the paper's *Behavior cloning unified*: diffusion policy trained on expert + non-expert data (D_E ∪ D_NE). Our cell `S0B`. (Ours carries the RISE spectral-norm penalty, which the paper's BC baselines presumably do not; an ablation without it is training.)\n- **RISE policy, greedy** = RISE's own behaviour policy (trained on D_E ∪ D_NE with the critic jointly, Eq. 5) acting greedily with NO candidate selection. Not a paper row; shown because it is the policy the RISE flagship and our RSM both select from.\n- **RISE flagship** = RISE policy + RISE's IQL critic choosing among N candidates (Eq. 6). The paper's method.\n- **RSM** = our successor-model value choosing among N candidates from the stated policy.\n", "",
"| task | trajectories | paper row | BC-expert | BC-unified | RISE flagship | **RSM (on BC-unified policy)** | RSM recipe (model, beta, hops, particles) | ep | n | paper BC | paper IDQL | paper RISE |",
"|---|---|---|---|---|---|---|---|---|---|---|---|---|"]
def cell(o, a):
if a not in o: return "-"
sr, n, ep, _ = o[a]
return f"{sr:.0f}<sub>e{ep}</sub>" if ep else f"{sr:.0f}"
for task, (row, p) in PAPER.items():
o = rows.get(task, {})
if "RSM" in o:
sr, n, ep, r = o["RSM"]
ro = ("chain cap=%s" % r.get("L", "?")) if r.get("chain") else ("fold L=%s" % r.get("L", "?"))
rec = (f"{r.get('model','?')}, beta={r.get('beta','?')}, {ro}, "
f"P={r.get('particles','?')}, {r.get('score','?')}") if r else "-"
rsm, rep, rn = f"**{sr:.0f}**", str(ep), str(n)
else:
rec, rsm, rep, rn = "-", "-", "-", "-"
L.append(f"| {task} | {traj(task)} | {row} | {cell(o,'BC-expert (S3H1)')} | {cell(o,'BC-unified (S0B)')} | "
f"{cell(o,'RISE flagship (S0A + critic)')} | {rsm} | {rec} | {rep} | {rn} | "
f"{p['BC']:.1f} | {p['IDQL']:.1f} | {p['RISE']:.1f} |")
L += ["", "`-` means that arm has no evaluation with at least "
f"{MIN_N} episodes yet. Subscripts on our numbers are the policy epoch.", ""]
import sys
print("READ-OUT CENSUS (RSM cells in scope): fold=%d chain=%d"
% (readout_census["fold"], readout_census["chain"]), file=sys.stderr)
if readout_census["chain"]:
print("READ-OUT MIXTURE IN ALL_TASKS: %d coin-chain cells have entered this loader's DIRS scope, "
"which until now held only the retired deterministic fold. The RSM column now pools TWO "
"read-outs under one label -- split it (or scope DIRS) before publishing."
% readout_census["chain"], file=sys.stderr)
out = os.environ.get("RR_ALL_TASKS_OUT") or f"{ROOT}/docs/ALL_TASKS.md"
open(out, "w").write("\n".join(L))
print("[all_tasks_table] wrote %s" % out, file=sys.stderr)
print("\n".join(L))
if __name__ == "__main__":
main()