#!/usr/bin/env python """Build the hf_path -> source map for the sim paper checkpoint set (HF_PUSH_ALL, 2026-11-22). Source of truth: status/disk/ct_keep_paper_ckpts.tsv. Adds small sidecars the loaders need: regular *.json/*.yaml next to each ckpt (and the robomimic run dir's config.json), and per task the small cache metadata (feat_stats.npz, meta.npz, goal*.npz, *.json) -- never the big *.npy feature arrays. Writes scratch/hf_push/sim_map.tsv: hf_path, source_path(realpath), bytes, n_cells, example_cell, kind.""" import os, sys, csv, glob ROOT = "/proj/dmfexp/zwhong/rsm_rise" SMALL = 50 * 2**20 rows, seen = [], {} def add(hf, src, n, ex, kind): real = os.path.realpath(src) if not os.path.isfile(real): print("MISSING", src, file=sys.stderr); return if hf in seen: if seen[hf] != real: sys.exit(f"COLLISION {hf}: {seen[hf]} vs {real}") return seen[hf] = real rows.append((hf, real, os.path.getsize(real), n, ex, kind)) def rel_runs(p): p = p.replace("/archive/dmfexp/zwhong/rsm_rise/", "").replace("/proj/dmfexp/archive/zwhong/rsm_rise/", "") if p.startswith(ROOT + "/"): p = p[len(ROOT) + 1:] assert p.startswith("runs/"), p return p[5:].split("/") tasks = set() with open(f"{ROOT}/status/disk/ct_keep_paper_ckpts.tsv") as f: for r in csv.DictReader(f, delimiter="\t"): p = r["ckpt_path"]; src = p if p.startswith("/") else f"{ROOT}/{p}" parts = rel_runs(p); task, fam, arm = parts[0], parts[1], parts[2] tasks.add(task) base = "/".join(parts[:-1]) add(f"{base}/{parts[-1]}", src, r["n_cells"], r["example_cell"], "ckpt") d = os.path.dirname(src) cands = [d] + ([os.path.dirname(d)] if os.path.basename(d) == "models" else []) for dd in cands: for g in sorted(os.listdir(dd)): q = os.path.join(dd, g) if g.endswith((".json", ".yaml", ".yml")) and os.path.isfile(q) and os.path.getsize(q) < SMALL: hb = base if dd == d else os.path.dirname(base) add(f"{hb}/{g}", q, "", "", "sidecar") for task in sorted(tasks): c = f"{ROOT}/cache/{task}" if not os.path.isdir(c): continue for g in sorted(os.listdir(c)): q = os.path.join(c, g) if os.path.isfile(q) and g.endswith((".json", ".npz")) and os.path.getsize(q) < SMALL: add(f"{task}/cache/{g}", q, "", "", "cache_meta") out = f"{ROOT}/scratch/hf_push/sim_map.tsv" with open(out, "w") as f: f.write("hf_path\tsource_path\tbytes\tn_cells\texample_cell\tkind\n") for r in rows: f.write("\t".join(map(str, r)) + "\n") from collections import Counter c = Counter(); b = Counter() for r in rows: c[r[0].split("/")[0]] += 1; b[r[0].split("/")[0]] += r[2] for t in sorted(c): print(f"{t}\t{c[t]}\t{b[t]/2**30:.1f} GiB") print("TOTAL", len(rows), f"{sum(b.values())/2**40:.3f} TiB", "ckpts", sum(1 for r in rows if r[5]=="ckpt"))