Skip to content

[python] Separate LeRobot dataset loading and episode appends - #11614

Open
XiaoHongbo-Hope wants to merge 10 commits into
apache:masterfrom
XiaoHongbo-Hope:python-lerobot-append-episodes
Open

XiaoHongbo-Hope wants to merge 10 commits into
apache:masterfrom
XiaoHongbo-Hope:python-lerobot-append-episodes

Conversation

@XiaoHongbo-Hope

@XiaoHongbo-Hope XiaoHongbo-Hope commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Use load_from_lerobot(..., append=True) for new Datasets and append_to_lerobot(..., dataset_id=...) for new Episodes in an existing Dataset.

Tests: 56 append cases passed on Python/Ray and Native read/write; flake8 passed.

@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as draft December 2, 2026 03:01
@XiaoHongbo-Hope XiaoHongbo-Hope changed the title [python] Append episodes to an existing LeRobot dataset [python] Separate LeRobot dataset loading and episode appends Dec 2, 2026
@XiaoHongbo-Hope
XiaoHongbo-Hope force-pushed the python-lerobot-append-episodes branch from aaca235 to 0a44b66 Compare December 2, 2026 06:00
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review December 2, 2026 07:49
@jerry-024

Copy link
Copy Markdown
Contributor

+1

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reproduced these six cases on 588d776927.

for singular, vocabulary in vocabularies.items():
entries = [{singular + "_index": index, singular: text}
for text, index in sorted(vocabulary.items(), key=lambda item: item[1])]
target[singular + "s"] = entries or None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve an empty subtask vocabulary. A valid LeRobot source can declare subtask_index with an empty meta/subtasks.parquet and null subtask indices in every frame. I reproduced a Dataset that reads successfully after import but fails to open with PaimonLeRobotDataset after appending another such source. entries or None changes _datasets.subtasks from [] to None while the feature is still declared. Keep [] and set total_subtasks to zero when the feature is present.

if plan["metadata"]["stats_table"] is not None]
if parts:
names = dict.fromkeys(name for part in parts for name in part if name not in _CONTROLS)
stats = {name: _merge_stats([part[name] for part in parts if name in part]) for name in names}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve quantile normalization after an Episode append. With a single Dataset UUID and q01 and q99 in both inputs, I reproduced those stats disappearing from meta.stats["action"] after a successful append. _merge_stats drops the quantiles before the updated Dataset row is written. LeRobot's default PI0.5 configuration then fails during normalization. Please recompute the quantiles over the combined frames or aggregate them using the supported LeRobot version's policy, and add a single-Dataset regression test. PI0.5 configuration · LeRobot normalizer

for group, coordinates in files.items():
column, prefix = group
values = groups[column]
if prefix + "chunk_index" in values and prefix + "file_index" in values:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Skip incomplete file coordinates. An existing Dataset can contain (0, 0) and (null, null) in the optional meta/episodes/{chunk_index,file_index} fields. Initial import accepts both rows, but this scan adds both pairs and max() raises TypeError during the next append. Check for a complete integer pair both here and when remapping incoming coordinates so missing coordinates remain missing.

mapping[source] = coordinate
coordinates.add(coordinate)
values.update(zip(keys, mapping[source]))
row[column] = _variant_value(values)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve large unsigned values when rewriting VARIANT. An Episode with data/vendor_id = 2**64 - 1 in a uint64 Arrow column imports successfully on its own. Appending that Episode fails because decoding the VARIANT yields a Decimal, which _variant_value rejects on the second encode. Apply the coordinate changes before the first encode or use a re-encoding path that preserves Decimal values.

for key in ("info", "video_info"):
if isinstance(feature.get(key), dict):
feature[key] = {name: value for name, value in feature[key].items()
if (other.get(key) or {}).get(name) == value}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Normalize optional video feature metadata. A target camera with info={"video.fps": 10} and an incoming camera with info="producer" have matching feature contracts and can be imported together. Episode append raises AttributeError here because the truthy string reaches .get(name). Reuse the import path's dictionary normalization for info and video_info.

plan["next_chunks"][group] += 1
mapping[source] = coordinate
coordinates.add(coordinate)
values.update(zip(keys, mapping[source]))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve the original file coordinates. I reproduced an append that stored (1, 0) in _episodes.data for an incoming source whose file was at (0, 0). The documented data_path template then points to a file that does not exist in that source. Keep the original coordinate pair and source provenance alongside any coordinates assigned within the combined Dataset. Episode field documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants