"""Decode every mp4 of an arm's LeRobot dataset once -> /workspace/isr/cache///chunk-XXX_file-XXX.npy (uint8 [T,H,W,3]). Page cache (503 GB RAM) keeps them hot; training then reads frames by index with zero video decode. python cache_videos.py --arm raw --procs 40""" import argparse, glob, os, multiprocessing as mp import numpy as np def one(args): src, dst = args if os.path.exists(dst): return dst, 0 from torchcodec.decoders import VideoDecoder d = VideoDecoder(src); n = d.metadata.num_frames arr = d.get_frames_in_range(0, n).data.permute(0, 2, 3, 1).contiguous().numpy() os.makedirs(os.path.dirname(dst), exist_ok=True); np.save(dst + ".tmp.npy", arr); os.rename(dst + ".tmp.npy", dst) return dst, len(arr) if __name__ == "__main__": ap = argparse.ArgumentParser(); ap.add_argument("--arm", required=True); ap.add_argument("--procs", type=int, default=40); a = ap.parse_args() root = f"/workspace/isr/datasets/{a.arm}"; jobs = [] for src in sorted(glob.glob(f"{root}/videos/*/chunk-*/file-*.mp4")): rel = os.path.relpath(src, f"{root}/videos"); key, chunk, f = rel.split("/") jobs.append((src, f"/workspace/isr/cache/{a.arm}/{key}/{chunk}_{f[:-4]}.npy")) with mp.Pool(a.procs) as p: tot = sum(n for _, n in p.imap_unordered(one, jobs, chunksize=4)) print(f"CACHE_OK {a.arm} files={len(jobs)} frames={tot}", flush=True)