File size: 4,571 Bytes
b26bdfa c777571 b26bdfa c777571 b26bdfa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #!/usr/bin/env python3
"""lerobot-eval (LeRobot 0.7.0, unchanged) with the inference-side PiBehavior-lite patches.
--corr-noise PATH B1 (must match training) --task-ids PATH B2 (must match training)
--compress N_EXEC N_STEPS B8 action compression (e.g. 26 20 for chunk 50)
--kv-mix B6 (must match training) --inpaint PATH B7 correlated inpainting with Σ = L Lᵀ
--gripper-retry B9 reopen after a grasp that closed on nothing (LIBERO analogue)
--stage PATH B3 stage token + head + voting tracker (must match training)
--geco [--geco-kmax K] GeCO optimisation sampler; per-call residual norms -> <output_dir>/ood_scores.json
--fm-score standard SmolVLA + flow-matching-loss OOD score per call -> <output_dir>/ood_scores.json
Usage: envs/lerobot/.venv/bin/python experiments/lerobot/eval_variant.py [patches] -- <lerobot-eval args>
"""
import argparse
import importlib.util
import sys
from pathlib import Path
import numpy as np
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)
if __name__ == "__main__":
ap = argparse.ArgumentParser()
ap.add_argument("--corr-noise", default=None)
ap.add_argument("--task-ids", default=None)
ap.add_argument("--compress", type=int, nargs=2, default=None, metavar=("N_EXEC", "N_STEPS"))
ap.add_argument("--kv-mix", action="store_true")
ap.add_argument("--inpaint", default=None, help="B7: path to the L asset (Σ = L Lᵀ)")
ap.add_argument("--inpaint-keep", type=int, default=4)
ap.add_argument("--gripper-retry", action="store_true", help="B9 LIBERO analogue of the gripper correction rule")
ap.add_argument("--stage", default=None, help="B3: task-id mapping; stage token + head + voting tracker")
ap.add_argument("--geco", action="store_true")
ap.add_argument("--geco-kmax", type=int, default=10, help="App. D uses K_max = 10 for the OOD experiment")
ap.add_argument("--geco-zero-pad", action="store_true", help="must match training")
ap.add_argument("--geco-schedule", default="a3", help="step sizes: a3 (App. A.3), e (App. E), geom:F:L:N, const:V")
ap.add_argument("--fm-score", action="store_true")
a, rest = ap.parse_known_args()
rest = rest[1:] if rest and rest[0] == "--" else rest
spec = importlib.util.spec_from_file_location("variants", Path(__file__).with_name("variants.py"))
V = importlib.util.module_from_spec(spec)
spec.loader.exec_module(V)
if a.corr_noise:
V.patch_correlated_noise(a.corr_noise)
if a.task_ids:
V.patch_task_id_prompts(a.task_ids)
if a.compress:
V.patch_compression(a.compress[0], a.compress[1], dataset_root() / "meta/stats.json")
if a.kv_mix:
V.patch_kv_mix()
if a.inpaint:
import atexit
st = V.patch_inpainting(a.inpaint, keep=a.inpaint_keep)
atexit.register(lambda: print("[variants] B7 inpainting stats:", st, flush=True))
if a.stage:
import atexit
sst = V.patch_stage(a.stage)
atexit.register(lambda: print("[variants] B3 tracker stats:", {k: sst[k] for k in
("episodes", "replans", "events")}, "final stage histogram:",
np.bincount(sst["final_stages"], minlength=5).tolist() if sst["final_stages"] else [],
flush=True))
if a.geco or a.fm_score:
import atexit
import json
out = Path(next(r.split("=", 1)[1] for r in rest if r.startswith("--output_dir=")))
ost = V.patch_geco(k_max=a.geco_kmax, zero_pad=a.geco_zero_pad, schedule=a.geco_schedule) if a.geco else V.patch_fm_score()
def dump():
out.mkdir(parents=True, exist_ok=True)
(out / "ood_scores.json").write_text(json.dumps({"kind": "geco" if a.geco else "fm_loss", **ost}))
print(f"[variants] OOD scores: {len(ost['calls'])} planning calls -> {out / 'ood_scores.json'}", flush=True)
atexit.register(dump)
if a.gripper_retry: # last: wraps whichever select_action the patches above installed
import atexit
gst = V.patch_gripper_retry(dataset_root() / "meta/stats.json")
atexit.register(lambda: print("[variants] B9 gripper retry stats:", gst, flush=True))
from lerobot.scripts.lerobot_eval import main
sys.argv = ["lerobot-eval", *rest]
main()
|