herooooooooo's picture
GeCO (arXiv 2603.17834) Table 5 reproduction on SmolVLA: report, code, results, logs
b26bdfa
Raw History Blame Contribute Delete
3.19 kB
#!/usr/bin/env python3
"""Build the data-derived assets the PiBehavior-lite variants need (CPU only, ~1 min).
assets/libero_chunk_L.pt B1: Cholesky of the shrunk (β=0.5) correlation of NORMALISED 50-step action chunks
assets/libero_task_ids.json B2: instruction -> "task <id>" (ids from the dataset's tasks table)
assets/libero_chunk_corr.npy the unshrunk correlation (for figures)
Usage: envs/lerobot/.venv/bin/python experiments/lerobot/prepare_assets.py [--horizon 50] [--n 20000]
"""
import argparse
import json
from pathlib import Path
import numpy as np
import pyarrow.parquet as pq
HERE = Path(__file__).resolve().parent
def dataset_root():
"""The copy LeRobot itself reads (its hub cache), so no second 33 GB copy is needed."""
from lerobot.datasets.lerobot_dataset import LeRobotDatasetMetadata
return Path(LeRobotDatasetMetadata("HuggingFaceVLA/libero").root)
import importlib.util # noqa: E402
spec = importlib.util.spec_from_file_location("variants", HERE / "variants.py")
V = importlib.util.module_from_spec(spec)
spec.loader.exec_module(V)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--horizon", type=int, default=50, help="SmolVLA chunk_size")
ap.add_argument("--n", type=int, default=20000)
ap.add_argument("--beta", type=float, default=0.5)
a = ap.parse_args()
out = HERE / "assets"
out.mkdir(exist_ok=True)
DS = dataset_root()
stats = json.loads((dataset_root() / "meta/stats.json").read_text())["action"]
mean, std = np.asarray(stats["mean"]), np.asarray(stats["std"])
acts, eps = [], []
for f in sorted((DS / "data").rglob("*.parquet")):
t = pq.read_table(f, columns=["action", "episode_index"])
acts.append(np.stack(t.column("action").to_numpy(zero_copy_only=False)))
eps.append(t.column("episode_index").to_numpy())
A, E = np.concatenate(acts), np.concatenate(eps)
A = (A - mean) / std # SmolVLA normalises actions with MEAN_STD
episodes = [A[E == e] for e in np.unique(E)]
rng = np.random.default_rng(0)
C = V.chunk_correlation(V.chunk_windows(episodes, a.horizon, a.n, rng))
L = V.shrunk_cholesky(C, a.beta)
import torch
torch.save({"L": torch.tensor(L, dtype=torch.float32), "horizon": a.horizon, "real_dims": A.shape[1],
"beta": a.beta, "n_chunks": a.n, "layout": "time-major [t*D+d]"}, out / "libero_chunk_L.pt")
np.save(out / "libero_chunk_corr.npy", C.astype(np.float32))
tasks = pq.read_table(DS / "meta/tasks.parquet").to_pandas()
col = "task" if "task" in tasks.columns else tasks.index.name
names = tasks["task"] if "task" in tasks.columns else tasks.index.to_series()
ids = tasks["task_index"] if "task_index" in tasks.columns else range(len(tasks))
mapping = {str(n).strip(): f"task {int(i)}" for n, i in zip(names, ids)}
(out / "libero_task_ids.json").write_text(json.dumps(mapping, indent=1))
print(f"episodes={len(episodes)} frames={len(A)} corr={C.shape} tasks={len(mapping)} (column {col})")
D = A.shape[1]
print("adjacent-time corr per dim:", [round(float(C[d, D + d]), 3) for d in range(D)])
if __name__ == "__main__":
main()