Download code/experiments/lerobot/eval_variant.py from herooooooooo/repro-generative-control-as-optimization: direct link, hf CLI and curl.
- Browser
- Download file 4.31 kB
-
https://huggingface.co/spaces/herooooooooo/repro-generative-control-as-optimization/resolve/main/code/experiments/lerobot/eval_variant.py
- Command line
-
hf download hf://spaces/herooooooooo/repro-generative-control-as-optimization/code/experiments/lerobot/eval_variant.py
-
curl -L -o eval_variant.py https://huggingface.co/spaces/herooooooooo/repro-generative-control-as-optimization/resolve/main/code/experiments/lerobot/eval_variant.py
4.31 kB
| #!/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("--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) 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() | |