| """Run Robometer on one episode and publish only derived artifacts. |
| |
| This script is intended for a bounded Hugging Face Job. The source dataset is |
| never opened for writing; all uploads target the duplicated dataset repository. |
| """ |
|
|
| from __future__ import annotations |
|
|
| import logging |
| import os |
| import subprocess |
| import sys |
| from pathlib import Path |
|
|
| from huggingface_hub import HfApi |
|
|
| import lerobot.rewards.robometer.compute_rabc_weights as robometer_compute |
|
|
|
|
| DATASET_REPO_ID = os.getenv( |
| "ROBOMETER_DATASET_REPO_ID", |
| "justintiensmith/Ordering_Constrained_Black_Bin_Sequencing_Robometer", |
| ) |
| REWARD_MODEL_ID = os.getenv("ROBOMETER_MODEL_ID", "lerobot/Robometer-4B") |
| EPISODE = int(os.getenv("ROBOMETER_EPISODE", "0")) |
| CAMERA_KEY = os.getenv("ROBOMETER_CAMERA_KEY", "observation.images.middle") |
| BATCH_SIZE = int(os.getenv("ROBOMETER_BATCH_SIZE", "4")) |
| OUTPUT_ROOT = Path( |
| os.getenv( |
| "ROBOMETER_OUTPUT_DIR", |
| "/vol/dissolve/justin/outputs/robometer_black_bin_episode_000", |
| ) |
| ) |
| PROGRESS_PATH = OUTPUT_ROOT / "robometer_progress.parquet" |
| VIDEO_DIR = OUTPUT_ROOT / "videos" |
|
|
|
|
| def main() -> None: |
| logging.basicConfig( |
| level=logging.INFO, |
| format="%(asctime)s %(levelname)s %(message)s", |
| ) |
|
|
| if EPISODE != 0: |
| raise ValueError( |
| "This optimized runner currently supports episode 0 only because the in-tree " |
| "Robometer helper uses global dataset indices." |
| ) |
|
|
| OUTPUT_ROOT.mkdir(parents=True, exist_ok=True) |
| VIDEO_DIR.mkdir(parents=True, exist_ok=True) |
|
|
| |
| |
| |
| |
| original_dataset_class = robometer_compute.LeRobotDataset |
|
|
| def episode_dataset(repo_id: str, download_videos: bool = True): |
| return original_dataset_class( |
| repo_id, |
| episodes=[EPISODE], |
| download_videos=download_videos, |
| ) |
|
|
| robometer_compute.LeRobotDataset = episode_dataset |
| try: |
| progress_path = robometer_compute.compute_robometer_progress( |
| dataset_repo_id=DATASET_REPO_ID, |
| reward_model_path=REWARD_MODEL_ID, |
| output_path=str(PROGRESS_PATH), |
| device="cuda", |
| batch_size=BATCH_SIZE, |
| num_subsampled_frames=4, |
| episodes=[EPISODE], |
| image_key=CAMERA_KEY, |
| ) |
| finally: |
| robometer_compute.LeRobotDataset = original_dataset_class |
|
|
| api = HfApi() |
| api.upload_file( |
| path_or_fileobj=str(progress_path), |
| path_in_repo="robometer/episode_000/progress.parquet", |
| repo_id=DATASET_REPO_ID, |
| repo_type="dataset", |
| commit_message="Add Robometer progress for episode 0", |
| ) |
|
|
| lerobot_repo = Path( |
| os.getenv( |
| "LEROBOT_REPO", |
| str(Path(robometer_compute.__file__).resolve().parents[4]), |
| ) |
| ) |
| overlay_script = lerobot_repo / "examples/dataset/create_progress_videos.py" |
| if not overlay_script.exists(): |
| raise FileNotFoundError( |
| f"Could not find the LeRobot overlay script at {overlay_script}. " |
| "Set LEROBOT_REPO to the LeRobot source checkout." |
| ) |
|
|
| subprocess.run( |
| [ |
| sys.executable, |
| str(overlay_script), |
| "--repo-id", |
| DATASET_REPO_ID, |
| "--episode", |
| str(EPISODE), |
| "--camera-key", |
| CAMERA_KEY, |
| "--progress-file", |
| str(progress_path), |
| "--output-dir", |
| str(VIDEO_DIR), |
| ], |
| check=True, |
| ) |
|
|
| video_path = VIDEO_DIR / ( |
| "justintiensmith_Ordering_Constrained_Black_Bin_Sequencing_Robometer_" |
| "ep0_progress.mp4" |
| ) |
| if not video_path.exists(): |
| raise FileNotFoundError(f"Expected rendered video was not created: {video_path}") |
|
|
| api.upload_file( |
| path_or_fileobj=str(video_path), |
| path_in_repo="robometer/episode_000/middle_progress.mp4", |
| repo_id=DATASET_REPO_ID, |
| repo_type="dataset", |
| commit_message="Add Robometer visualization for episode 0", |
| ) |
| print(f"PROGRESS_ARTIFACT={progress_path}") |
| print(f"VIDEO_ARTIFACT={video_path}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|