Download rsm_rise/scripts/appendix_sweeps.py from rli14/rsm_rise_code: direct link, hf CLI and curl.
- Browser
- Download file 6.97 kB
-
https://huggingface.co/rli14/rsm_rise_code/resolve/main/rsm_rise/scripts/appendix_sweeps.py
- Command line
-
hf download hf://rli14/rsm_rise_code/rsm_rise/scripts/appendix_sweeps.py
-
curl -L -o appendix_sweeps.py https://huggingface.co/rli14/rsm_rise_code/resolve/main/rsm_rise/scripts/appendix_sweeps.py
6.97 kB
| #!/usr/bin/env python3 | |
| """Appendix section: the hyper-parameter search, per method, with every count measured. | |
| Emits docs/tex/_appendix_sweeps.tex. Grids and selection rules are statements about the CODE and are | |
| written here; every arm count and discount count is COUNTED from the evaluation archive by the same | |
| routine sweep_census.py uses, so the prose cannot drift from the table beside it. | |
| """ | |
| import glob, json, os, re, collections | |
| ROOT = "/proj/dmfexp/zwhong/rsm_rise" | |
| TASKS = [("square_sub_20100","Sq-S"),("square_expert_play","Sq-C"), | |
| ("two_piece_expert_suboptimal","Pc-S"),("two_piece_expert_play","Pc-C"), | |
| ("mug_expert_suboptimal","Mug"),("threading_expert_play","Thr"), | |
| ("two_piece_expert_play_tipping","Pc-tip")] | |
| PATS = {"RSM": r"^(?!TDF)(M[a-z0-9]*|L40b)", "TD-Flow": r"^TDF", "DINO-WM": r"^DINOWM", | |
| "LeWM": r"^LEWM", "TD-MPC2": r"^TDMPC2", "DF": r"^DF[ABC]?-"} | |
| def arms(task, pat): | |
| rx = re.compile(pat); out = set() | |
| for f in (glob.glob(f"{ROOT}/runs/{task}/eval_onactor/*.json") | |
| + glob.glob(f"{ROOT}/runs/{task}/eval_onactor/*/*.json")): | |
| if "diag" in f: continue | |
| b = os.path.basename(f) | |
| if not b.startswith("E1-"): continue | |
| lab = re.sub(r"-es\d+-s.*$", "", b[3:]) | |
| if rx.search(lab): out.add(lab) | |
| return out | |
| # SINGLE SOURCE OF TRUTH. My first version parsed the arm label and, for fold arms, read BETA where it | |
| # meant gamma -- so it reported 3 discounts for RSM everywhere while sweep_census reported 1 on Mug/Thr. | |
| # Two counting methods disagreeing is exactly what must not reach a paper. sweep_census.gammas() reads | |
| # `planner.plan_gamma` out of each eval JSON, i.e. the discount the cell was ACTUALLY evaluated at, and | |
| # falls back to the arm label only for the two families whose planner block is boilerplate. Reuse it. | |
| import importlib.util as _ilu | |
| _spec = _ilu.spec_from_file_location("sweep_census", f"{ROOT}/scripts/sweep_census.py") | |
| _sc = _ilu.module_from_spec(_spec) | |
| try: | |
| _spec.loader.exec_module(_sc) # writes _sweeps.tex as a side effect; harmless and idempotent | |
| discounts = _sc.gammas | |
| except Exception as _e: # fail loudly rather than fall back to a wrong count | |
| raise SystemExit(f"cannot import sweep_census.gammas ({_e}); refusing to emit a discount column " | |
| "computed a second, different way") | |
| bs, nl = chr(92), chr(10) | |
| counts = {m: {lab: len(arms(t, p)) for t, lab in TASKS} for m, p in PATS.items()} | |
| disc = {m: {lab: len(discounts(t, p)) for t, lab in TASKS} for m, p in PATS.items()} | |
| BODY = [ | |
| ("RSM (ours)", | |
| r"$\beta \in \{0.90, 0.95, 0.98, 0.99\}$ $\times$ particles $M \in \{8, 16, 64\}$ $\times$ read-out " | |
| r"$\in\{\mathrm{prob}, \mathrm{logit}\}$ $\times$ flow steps $\in \{4, 8, 16\}$. The chain cap is NOT a " | |
| r"hyper-parameter: it is derived per arm as the depth at which the continuation coin leaves a $10^{-3}$ " | |
| r"tail. $\gamma$ is swept only where admissible, since $\gamma \le \beta$ makes the continuation " | |
| r"probability $(\gamma-\beta)/(\gamma(1-\beta))$ non-positive and collapses the chain to a single draw."), | |
| ("TD-Flow", | |
| r"The RSM chain settings transferred unchanged, plus its own $\beta$ grid. It therefore received a " | |
| r"SMALLER search than RSM by construction, which is stated in Table~\ref{tab:searchsize}."), | |
| ("DINO-WM", | |
| r"Rollout horizon $H \in \{10, 20, 50, 100, 200\}$ frames, set through the discount as $H = 1/(1-\gamma)$, " | |
| r"$\times$ read-out $\in\{$terminal latent, normalised discounted sum$\}$. The retired $\beta$-recursion " | |
| r"arms swept depth $L \in \{1,2,4,8\}$ instead and are reported in Table~\ref{tab:wm_readout}."), | |
| ("LeWM", r"Identical grid to DINO-WM."), | |
| ("IDQL / RISE", | |
| r"\textbf{None.} The critic trains at a single fixed discount $0.99$ " | |
| r"(\texttt{iql\_diffusion\_config.py:75}). Its discount is a TRAINING hyper-parameter, so sweeping it " | |
| r"requires retraining the critic per value, whereas the RSM successor is $\beta$-conditioned and its " | |
| r"sweep is evaluation-only. This asymmetry is the reason the baseline was left at one setting and it is " | |
| r"a limitation of this comparison, not a property of the method."), | |
| ("IFQL", r"None; run on its published schedule. Dropped from the search entirely."), | |
| ("TD-MPC2", | |
| r"$\gamma$/$H$ $\times$ configuration: (a) ranks the shared 128 candidates, (b) runs its own MPPI/CEM " | |
| r"with our actor as the prior at $S{=}512$ samples, $I{=}6$ iterations, $H_p{=}3$. Its discount is also " | |
| r"training-time."), | |
| ("Diffusion Forcing", | |
| r"Guidance scale $\in \{0, 1, 3, 5\}$ $\times$ plan count $\times$ horizon. Its reproduction gate " | |
| r"against the published maze2d guidance curve has not yet passed, so no DF number is reported."), | |
| ] | |
| rows = [] | |
| for name, _ in BODY: | |
| key = name.split(" (")[0].replace("Diffusion Forcing","DF") | |
| if key not in counts: rows.append(f"{name} & " + " & ".join("--" for _ in TASKS) + " " + bs+bs); continue | |
| rows.append(f"{name} & " + " & ".join( | |
| (f"{counts[key][lab]}" if counts[key][lab] else "--") + | |
| (f" ({disc[key][lab]})" if disc[key][lab] else "") for _, lab in TASKS) + " " + bs+bs) | |
| tex = (bs+"subsection{The hyper-parameter search}"+nl+nl | |
| + "Every planning column selects its reported arm the same way: the arm with the highest mean success " | |
| "rate on that task, each arm run at three training $"+bs+"times$ three evaluation seeds, 50 episodes per " | |
| "cell. Selection is therefore over the SAME quantity being reported, so every planning number in this " | |
| "paper is upward biased by selection; Table~"+bs+"ref{tab:flagship_all} gives the no-selection and " | |
| "random-candidate controls that bound it. The grids below are the code's; the counts in " | |
| "Table~"+bs+"ref{tab:appendix_sweeps} are counted from the evaluation archive."+nl+nl | |
| + bs+"begin{table}[h]"+nl+bs+"centering"+nl | |
| + bs+"caption{Distinct evaluated arms per method per task, with the number of distinct discount settings " | |
| "in parentheses. Counted, not asserted. Two asymmetries are visible and neither favours a single " | |
| "conclusion: RSM has the most arms on most rows, while on Mug, Thr and Pc-tip it evaluated only ONE " | |
| "discount against five for both world models -- and Thr is the row it loses.}"+nl | |
| + bs+"label{tab:appendix_sweeps}"+nl+bs+"scriptsize"+nl+bs+"setlength{"+bs+"tabcolsep}{4pt}"+nl | |
| + bs+"begin{tabular}{l"+"c"*len(TASKS)+"}"+nl+bs+"toprule"+nl | |
| + "Method & " + " & ".join(lab for _, lab in TASKS) + " " + bs+bs+nl+bs+"midrule"+nl | |
| + nl.join(rows)+nl+bs+"bottomrule"+nl+bs+"end{tabular}"+nl+bs+"end{table}"+nl+nl | |
| + nl.join(bs+"paragraph{"+n+"} "+d for n, d in BODY)+nl) | |
| open(f"{ROOT}/docs/tex/_appendix_sweeps.tex","w").write(tex) | |
| print(f"wrote {ROOT}/docs/tex/_appendix_sweeps.tex") | |
| print(f"{'method':<14}" + "".join(f"{lab:>10}" for _, lab in TASKS)) | |
| for m in PATS: | |
| print(f"{m:<14}" + "".join(f"{str(counts[m][lab])+'('+str(disc[m][lab])+')':>10}" for _, lab in TASKS)) | |