Skip to content

[python] Export LeRobot v2/v3 datasets to Object Tables - #11299

Open
XiaoHongbo-Hope wants to merge 26 commits into
apache:masterfrom
XiaoHongbo-Hope:python-lerobot-export-v2-v3
Open

XiaoHongbo-Hope wants to merge 26 commits into
apache:masterfrom
XiaoHongbo-Hope:python-lerobot-export-v2-v3

Conversation

@XiaoHongbo-Hope

@XiaoHongbo-Hope XiaoHongbo-Hope commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Export one Dataset from a Paimon LeRobot table group to an Object Table as v2.0, v2.1, or v3.0. Output uses <Object Table>/<dataset_id>/ and publishes meta/info.json last. Failed single-writer uploads can be retried. Concurrent exports to the same Dataset ID remain unsupported.

Validation: 55 export tests passed, 3 skipped; LeRobot 0.3.3 read v2.1 image, video, and partial Episode statistics; flake8 passed. Live DLF export was not tested.

@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as draft November 20, 2026 08:56
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review November 21, 2026 07:52
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as draft November 21, 2026 08:08
@XiaoHongbo-Hope XiaoHongbo-Hope changed the title [python] Export LeRobot v2 and v3 datasets from Paimon [python] Export LeRobot v2/v3 datasets locally or to Object Tables Nov 21, 2026
@XiaoHongbo-Hope XiaoHongbo-Hope changed the title [python] Export LeRobot v2/v3 datasets locally or to Object Tables [python] Export LeRobot v2/v3 datasets to Object Tables Nov 21, 2026
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review November 22, 2026 03:21
@JingsongLi

Copy link
Copy Markdown
Contributor

Do we really need to support 2.0 and 2.1?

@XiaoHongbo-Hope

Copy link
Copy Markdown
Contributor Author

Do we really need to support 2.0 and 2.1?

Yes, some users still use version 2.x

@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 found two issues that can affect normal use. Concurrent exports can mix file layouts under the same Dataset ID, and the v2.1 reader fails when sampling exported image columns. The inline comments include the triggering cases and suggested fixes.



def _upload_to_object_table(stage, prefix, file_io):
if _prefix_has_files(file_io, prefix):

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] Reserve the Dataset prefix atomically before publishing

Two exports of the same Dataset can both pass the prefix and per-file existence checks before either write is visible. Running the upload step concurrently on the FUSE path with v2.1 and v3.0 Parquet layouts reproduced the race. Both uploads returned successfully and left both layouts under the same prefix. If v3 metadata wins, the v3 reader can load duplicate frame rows because it scans all Parquet files under data/. Please acquire an exclusive reservation for the destination prefix before uploading any files.

LeRobot v3 Parquet discovery

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[P1] Reserve the Dataset prefix atomically before publishing

Two exports of the same Dataset can both pass the prefix and per-file existence checks before either write is visible. Running the upload step concurrently on the FUSE path with v2.1 and v3.0 Parquet layouts reproduced the race. Both uploads returned successfully and left both layouts under the same prefix. If v3 metadata wins, the v3 reader can load duplicate frame rows because it scans all Parquet files under data/. Please acquire an exclusive reservation for the destination prefix before uploading any files.

LeRobot v3 Parquet discovery

Thanks, the race is real. I intended this PR to support one writer per Dataset ID. Cross-process exclusion needs a FileIO contract across OSS, FUSE, and REST, which would substantially widen this PR. I'm torn between keeping this PR focused and making the export API safe. What is your suggestion for this ?

frame_columns = list(info["features"])
columns = ["dataset_id"] + frame_columns
physical_schema = _target_schema(reader._table)
frame_schema = pa.schema([

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 the Hugging Face Image feature in v2 Parquet

The exported image column is an Arrow struct without Hugging Face Image metadata. I loaded both v2.0 and v2.1 exports through datasets.load_dataset("parquet", ...) and got a {bytes, path} dict for each image. LeRobot's v2.1 reader infers features from Parquet and passes the dict to torch.tensor when fetching a sample, which raises an error. Please emit the Image metadata and test fetching an image sample with the legacy reader.

Legacy dataset loading · Sample transform

episode_schema, version, batch_size)
reader.close()
reader = None
_upload_to_object_table(stage, target_uri, table.file_io)

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] Make an interrupted upload retryable

I injected a transient I/O error immediately before uploading meta/info.json. The files already uploaded remained in the target prefix, and a retry with healthy I/O immediately raised FileExistsError. Once the exporter owns the prefix, please clean up its partial upload on failure or provide a way to resume it.

prefix = "videos/%s/" % key
episode[prefix + "chunk_index"] = chunk_index
episode[prefix + "file_index"] = file_index
if reader._table.options.options.get(

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] Use the stored clip's timeline for v3 video metadata

The write option can change after a clip has been stored. If an Episode was imported with remuxing enabled and the option is later disabled, export copies the remuxed clip while retaining the original video's Episode offset. A reproduction using an FFmpeg-remuxed clip started at 0.0s while the exported metadata pointed to 0.2s. Re-import failed when looking up frames. Please derive the offset from the copied payload and its frame descriptors.


preserved = {field.name: field for field in source_schema or []
if field.name in names}
inferred_names = [name for name in names if name not in preserved]

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 uint64 Episode extension fields on export

The existing test_episode_variant_preserves_uint64 fixture imports meta/large_id = 2**64 - 1 and stores it in the VARIANT as a Decimal. With the inferred export schema, the field becomes decimal128(20, 0) and load_from_lerobot rejects the exported dataset because the Episode field must use a JSON-native Arrow type. Please preserve the uint64 Arrow type when reconstructing the grouped field and cover this import/export/re-import case.

Existing uint64 test

video_frames = {key: [] for key in video_keys}
for offset in range(begin, end, batch_size):
indices = list(range(offset, min(offset + batch_size, end)))
table = reader.read_keys(

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] Apply the full frame predicate when the Python index lookup is inexact

In a multi-Dataset group using the Python reader, I dropped the dataset_id BTree and kept the index BTree. The lookup then returned rows from both Datasets for the same source-local frame index, causing LeRobot source Frame range is incomplete for a valid Dataset. _FrameLocator skips the residual filter when index coverage is complete, even when evaluation.result.is_exact() is false. Keep applying the full (dataset_id, index) predicate for inexact lookup results.

parsed = urlparse(object_location)
if parsed.scheme != "oss" or not parsed.netloc:
raise ValueError("Object Table output must use OSS storage.")
try:

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] Resolve the group prefix when an unrelated table has the same name

An existing multimodal table named robot can coexist with a LeRobot group imported as robot_frames and its companion tables. In that setup the documented export_to_lerobot("robot", ...) resolves the unrelated table and fails on missing group metadata. Please accept the exact name only if it resolves to a managed Frames table, then try <prefix>_frames otherwise.

raise ValueError(
"LeRobot v2 export supports RGB video without audio; "
"%s has depth or audio." % key)
output_info.update(

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] Supply robot_type for v2 exports from the direct writer

PaimonLeRobotWriter can produce info without a robot_type key, and the default is added only in the v3 branch. The v2.1 reader indexes that key directly, so accessing dataset.meta.robot_type raises KeyError for a direct-writer export. Please move the robot_type=None default before the version split.

Legacy metadata getter

@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 rechecked cec7a7fdf7. Image decoding now works in all three output formats. I reproduced data loss during rollback and several format compatibility issues, and the merge build still fails on the new tests.

except Exception as error:
# No info.json was published, so this attempt cannot be consumed yet.
# The destination is owned by one exporter at a time.
_clean_failed_upload(prefix, file_io, error)

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] Guard rollback with exclusive ownership

I paused export A after its prefix check, let export B finish, and then resumed A using FuseLocalFileIO. A hit FileExistsError on B's data file, and this cleanup deleted B's entire published dataset, including meta/info.json. Please acquire the destination prefix atomically before uploading and limit cleanup to objects owned by the failed attempt.

output_info.setdefault("chunks_size", 1000)
output_info.setdefault("data_files_size_in_mb", 100)
output_info.setdefault("video_files_size_in_mb", 200)
output_info.setdefault("data_path", _V3_DATA_PATH)

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] Generate canonical paths for v3 output

I imported a source with data_path under frames/. The export succeeded. The LeRobot reader only discovers frame Parquet under data/. I also reproduced a collision with a literal video_path and Episode remuxing enabled. Two Episode mappings pointed to the same filename, and the second clip overwrote the first. Please generate canonical v3 output paths and update the Episode mappings to match.

LeRobot v3 reader

if frame_index >= len(v3_video_times[identity]):
raise ValueError(
"LeRobot video descriptor points beyond the MP4 frames.")
start = v3_video_times[identity][frame_index]

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] Validate the video offset against every frame in the Episode

At 10 fps, I imported an Episode with from_timestamp=0.2 and frame PTS values of 0.200075 and 0.299925. Both meet the importer's 100 µs tolerance. Export moves the offset to 0.200075, so the second frame is 150 µs from its lookup time and re-import fails. Please preserve the original offset when it matches the copied clip, and validate every frame descriptor when selecting an offset for a remuxed clip.

episode[prefix + "to_timestamp"] = start + len(descriptors) / info["fps"]
if version.startswith("v2."):
episode_stats.append({"episode_index": episode_index,
"stats": _episode_stats(episode)})

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 normalization stats in v2.1 exports

The existing source fixture has Dataset-level stats for action and observation.state. Its Episode stats omit both features. The v2.1 reader builds meta.stats by aggregating episodes_stats.jsonl, so the exported dataset loses the normalization stats for those features. Please compute the missing Episode stats from the selected frames and verify them with the v2.1 reader.

Legacy metadata loader

unsigned = {
name: pa.field(name, pa.uint64()) for name in names
if name not in preserved and any(
isinstance(episode.get(name), Decimal)

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] Restore nested unsigned integers in Episode metadata

I imported a vendor/nested_ids column typed as list<uint64> with a value of 2**64 - 1. The scalar check misses the nested Decimal, so the export writes list<decimal128> and load_from_lerobot rejects it on re-import. Please preserve or reconstruct the unsigned Arrow types inside lists and structs, too.

raise
info_uri = prefix + "/meta/info.json"
try:
_upload_file(info, info_uri, file_io)

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] Publish the FUSE completion marker atomically

I paused a single FuseLocalFileIO writer immediately after it opened meta/info.json. A concurrent reader saw an empty file and raised JSONDecodeError. Please write the marker to a temporary file and atomically publish it on FUSE after all data uploads complete.

continue
uri = prefix + "/" + path.relative_to(stage).as_posix()
_upload_file(path, uri, file_io)
except Exception as error:

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] Keep an interrupted export retryable

I interrupted a single exporter with Ctrl+C after its first successful upload. KeyboardInterrupt bypasses this handler, leaving files in the target prefix. A retry then raises FileExistsError. Please include cancellation in rollback once the attempt has acquired ownership of the prefix.

if parsed.scheme != "oss" or not parsed.netloc:
raise ValueError("Object Table output must use OSS storage.")
try:
frames = connection.get_table(table_name)

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] Resolve the group prefix behind an ordinary table

I created an ordinary append table named robot through the catalog and loaded a LeRobot group into robot_frames. The documented export_to_lerobot("robot", ...) call fails in Data Evolution validation before reaching the fallback. The new regression test creates a Data Evolution table through conn.create_table, so it misses this case. Please inspect whether the exact candidate is a managed Frames table before applying multimodal validation.

locator = _FrameLocator.__new__(_FrameLocator)
locator._process_id = os.getpid()
locator._table = SimpleNamespace(options=SimpleNamespace(
scalar_index_search_mode=lambda: "ALL"))

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] Use real options in the frame locator regression test

Both parameterizations fail on the GitHub merge snapshot before the is_exact() assertion. The reader on master calls scalar_scan_search_mode(), and the mock only defines scalar_index_search_mode(). Please construct a real CoreOptions instance here so the test follows the production option contract.

Failing CI job

images = [value for path in data_files for value in
pq.read_table(path)["camera.image"].to_pylist()]
assert [value["bytes"] for value in images] == [payload] * 5
from datasets import load_dataset

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] Run the image decode assertions with the LeRobot dependencies

All three image cases fail at this import in the Python Execution shard. Pillow is installed in that shard, so the existing skip lets the tests reach an import of the absent datasets package. Please keep the Arrow assertions in the regular test suite and run the Hugging Face decoding checks in the LeRobot compatibility job.

Failing CI job

@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.

Reviewed 4496dae465e and ran the Python and native export paths. LeRobot 0.3.3 and 0.4.4 both read ordinary exported image and video samples, and the numeric normalization statistics survived. I reproduced three remaining cases affecting export retry or legacy dataset usability.

try:
if not file_io.try_to_write_atomic(
info_uri, info.read_text(encoding="utf-8")):
raise FileExistsError(info_uri)

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] Make a failed FUSE marker rename retryable

With one exporter, I injected a single EIO into Path.rename when publishing meta/info.json through FuseLocalFileIO. LocalFileIO.rename returned False, and this branch raised FileExistsError even though no marker existed. The Parquet and task metadata remained, so a healthy retry failed on the existing dataset prefix. Please distinguish an absent marker from a real collision and send the failed publication through owned-file cleanup. A regression test should inject the error at the FUSE rename.

missing_stats = {
name: _RunningStats() for name in source_stats
if name not in existing_stats and name in frame_schema.names
and info["features"][name]["dtype"].startswith(

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 image normalization statistics for v2.1 readers

I imported a v3 dataset with camera.image normalization in meta/stats.json and no per-episode image statistics. The v2.1 export retained the file and LeRobot 0.3.3 decoded all five image samples, but dataset.meta.stats["camera.image"] raised KeyError. The legacy reader aggregates episodes_stats.jsonl, and this fallback only supplies numeric features. Please emit per-episode image statistics for those features or explicitly reject conversions that lose the expected normalization. LeRobot v2.1 metadata loader

video = source.streams.video[0]
stream = target.add_stream("libx264", rate=fps)
stream.width, stream.height = video.width, video.height
stream.pix_fmt = "yuv420p"

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 supported RGB clip dimensions in v2 exports

A valid 17×15 H.264 yuv444p clip imported successfully and v3 exported the same MP4 byte for byte. Both v2.0 and v2.1 exports failed in libx264 with width not divisible by 2 (17x15) because the encoder always selects yuv420p. Please select a compatible pixel format for odd dimensions and record that format in the output metadata. Cover this with an import and export round trip.

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.

2 participants