Download scripts/diagnose_recap_value_decode.py from myx160/rl-post-train-artifacts: direct link, hf CLI and curl.
- Browser
- Download file 3.04 kB
-
https://huggingface.co/datasets/myx160/rl-post-train-artifacts/resolve/main/scripts/diagnose_recap_value_decode.py
- Command line
-
hf download hf://datasets/myx160/rl-post-train-artifacts/scripts/diagnose_recap_value_decode.py
-
curl -L -o diagnose_recap_value_decode.py https://huggingface.co/datasets/myx160/rl-post-train-artifacts/resolve/main/scripts/diagnose_recap_value_decode.py
3.04 kB
| #!/usr/bin/env python | |
| """Locate torchcodec failures while reading the canonical RECAP Value dataset. | |
| This is a bounded diagnostic: it never writes dataset files and prints the | |
| video path supplied to the decoder when a sample fails. It intentionally | |
| uses the same ValueDataset implementation as the official Value worker. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import sys | |
| from pathlib import Path | |
| import torch | |
| from torch.utils.data import DataLoader | |
| SCRIPT_DIR = Path(__file__).resolve().parent | |
| PROJECT_ROOT = SCRIPT_DIR.parent | |
| if str(SCRIPT_DIR) not in sys.path: | |
| sys.path.insert(0, str(SCRIPT_DIR)) | |
| def parse_args() -> argparse.Namespace: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--dataset-path", type=Path, default=PROJECT_ROOT / "datasets/recap_libero10_task0/libero10_task0_train") | |
| parser.add_argument("--tag", default="recap_v1_fail300_g1") | |
| parser.add_argument("--samples-per-seed", type=int, default=100) | |
| parser.add_argument("--seeds", type=int, nargs="+", default=[0, 1, 2, 3, 4, 5, 6, 7]) | |
| return parser.parse_args() | |
| def main() -> int: | |
| args = parse_args() | |
| dataset_path = args.dataset_path.resolve() | |
| if PROJECT_ROOT not in dataset_path.parents: | |
| raise ValueError(f"dataset path must be inside {PROJECT_ROOT}: {dataset_path}") | |
| import lerobot.common.datasets.lerobot_dataset as lerobot_dataset | |
| original_decode = lerobot_dataset.decode_video_frames | |
| def traced_decode(video_path, timestamps, tolerance_s, backend=None): | |
| try: | |
| return original_decode(video_path, timestamps, tolerance_s, backend) | |
| except Exception as exc: | |
| print( | |
| f"DECODE_FAILURE\t{video_path}\t{type(exc).__name__}: {exc}", | |
| flush=True, | |
| ) | |
| raise | |
| lerobot_dataset.decode_video_frames = traced_decode | |
| from rlinf.data.datasets.recap.value_model import ValueDataset | |
| dataset = ValueDataset( | |
| dataset_path=dataset_path, | |
| robot_type="libero", | |
| model_type="pi05", | |
| action_horizon=10, | |
| gamma=1.0, | |
| return_min=-779.0, | |
| return_max=0.0, | |
| normalize_to_minus_one_zero=True, | |
| split="train", | |
| tag=args.tag, | |
| ) | |
| print(f"DATASET_LENGTH\t{len(dataset)}", flush=True) | |
| for seed in args.seeds: | |
| generator = torch.Generator() | |
| generator.manual_seed(seed) | |
| loader = DataLoader( | |
| dataset, | |
| batch_size=1, | |
| shuffle=True, | |
| generator=generator, | |
| num_workers=0, | |
| collate_fn=lambda batch: batch[0], | |
| ) | |
| try: | |
| for index, _sample in enumerate(loader): | |
| if index + 1 >= args.samples_per_seed: | |
| break | |
| print(f"SEED_PASS\t{seed}\t{args.samples_per_seed}", flush=True) | |
| except Exception as exc: | |
| print(f"SEED_STOP\t{seed}\t{index}\t{type(exc).__name__}: {exc}", flush=True) | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |