`_copy_and_reindex_episodes_metadata` is very inefficient
Author: pzalCreated May 13, 2026Updated Sep 30, 2026
Labelsenhancementdatasetexamples
Ticket Type
Feature Request / Improvement
Environment & System Info
- LeRobot version: 0.5.2
- Platform: Linux-6.17.0-23-generic-x86_64-with-glibc2.39
- Python version: 3.13.13
- Huggingface Hub version: 1.12.0
- Transformers version: 5.3.0
- Datasets version: 4.8.4
- Numpy version: 2.2.6
- FFmpeg version: 7.1.1
- PyTorch version: 2.10.0+cu128
- Is PyTorch built with CUDA support?: True
- Cuda version: 12.8
- GPU model: NVIDIA GeForce RTX 5090Description
_copy_and_reindex_episodes_metadata calls _load_episode_with_stats in a loop for every episode. _load_episode_with_stats loads a fresh metadata parquet file every time. In my case, for a dataset with ~10k episodes, this file is ~130 MB in size and as a result every loop iteration takes an unreasonable amount of time. A simple cache of loaded parquet files like below decreases the time it takes to reindex metadata from ~8 hours to a couple of seconds.
Example of caching:
STATS_CACHE = {}
def _load_episode_with_stats(src_dataset: LeRobotDataset, episode_idx: int) -> dict:
"""Load a single episode's metadata including stats from parquet file.
Args:
src_dataset: Source dataset
episode_idx: Episode index to load
Returns:
dict containing episode metadata and stats
"""
ep_meta = src_dataset.meta.episodes[episode_idx]
chunk_idx = ep_meta["meta/episodes/chunk_index"]
file_idx = ep_meta["meta/episodes/file_index"]
parquet_path = src_dataset.root / DEFAULT_EPISODES_PATH.format(chunk_index=chunk_idx, file_index=file_idx)
if str(parquet_path) not in STATS_CACHE:
STATS_CACHE[str(parquet_path)] = pd.read_parquet(parquet_path)
df = STATS_CACHE[str(parquet_path)]
episode_row = df[df["episode_index"] == episode_idx].iloc[0]
return episode_row.to_dict()Context & Reproduction
No response
Relevant logs or stack trace
Checklist
- I have searched existing tickets to ensure this isn't a duplicate.
- I am using the latest version of the
mainbranch. - I have verified this is not an environment-specific problem.
Additional Info / Workarounds
No response
Source: huggingface/lerobot