Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ jobs:
python -m pytest -q \
pypaimon/tests/multimodal_lerobot_test.py \
pypaimon/tests/lerobot_aggregate_test.py \
pypaimon/tests/lerobot_episode_append_test.py \
pypaimon/tests/multimodal_lerobot_writer_test.py::PaimonLeRobotWriterTest::test_multiframe_boolean_statistics_preserve_extrema \
pypaimon/tests/multimodal_lerobot_writer_test.py::PaimonLeRobotWriterTest::test_multiframe_int64_statistics_preserve_extrema

Expand All @@ -358,7 +359,7 @@ jobs:
run: |
python -m pip install 'ray==2.53.0'
python -c 'import ray'
python -m pytest -q pypaimon/tests/lerobot_aggregate_test.py pypaimon/tests/multimodal_lerobot_ray_test.py
python -m pytest -q pypaimon/tests/lerobot_aggregate_test.py pypaimon/tests/lerobot_episode_append_test.py pypaimon/tests/multimodal_lerobot_ray_test.py

- name: Test indexed TorchCodec (no skips)
working-directory: paimon-python
Expand Down
34 changes: 17 additions & 17 deletions docs/docs/pypaimon/lerobot.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ In Python, decode a scanned VARIANT value with

These data/video locations describe the original LeRobot files. Paimon reads
the imported media through the frame table's BLOB values.
Episode append assigns new file coordinates; `meta["pypaimon/source"]` retains
the source path, original Episode index, path templates, and original
`meta`, `data`, and `videos` values.
Episode append rejects incoming metadata containing the reserved `meta/pypaimon/source` key.

### Frame fields

Expand Down Expand Up @@ -299,28 +303,24 @@ removing suffixes, and names that overwrite standard `_datasets` columns are
rejected before creating target tables. Training readers project only required
source metadata and skip extra text columns.

Append another Dataset to an existing source-local group with `append_to_lerobot`.
Use `load_from_lerobot` for new Datasets and `append_to_lerobot` for new Episodes:

```python
conn.load_from_lerobot("robot_merged", ["/data/source_a", "/data/source_b"])
conn.append_to_lerobot("robot_merged", "/data/source_c", tag_name="after-append")
conn.load_from_lerobot("robot_merged", "/data/source_c", append=True)
conn.append_to_lerobot("robot_merged", "/data/new_episodes", dataset_id=dataset_id)
```

The target must be a complete LeRobot table group. Table options are set during
creation. Serialize imports to the same table group because its three component
tables commit separately. Pass a source list to prepare multiple sources in a
single call with Ray.

If source C adds `humidity`, the append adds that column to `_frames`, keeps A
and B, and reads their humidity values as null. New `extra_dataset_fields` columns
are added to `_datasets` in the same way; omitted extra fields receive nulls.
Pass `schema_evolution=False` to `append_to_lerobot` to reject new columns.

If the sole writer stops between component commits, call
`conn.recover_lerobot_append("robot_merged")` before retrying. This rolls
unfinished Frame and Episode commits back to the Dataset metadata boundary.
Nullable columns added before a failed append remain in the schema and are
reused on retry. This recovery is not a repair mechanism for concurrent appends.
`dataset_id` is the destination `_datasets.id`. Episode appends keep its UUID
and name, continue local indices, and update labels and statistics. FPS, robot
type, and feature contracts must match; only full train splits are supported.
Repeating a successful call adds the Episodes again.

Serialize writes per group: the three tables commit separately. After an error,
check the target Dataset's `info.total_episodes` and `info.total_frames` before
retrying: a lost response can follow a successful commit. For an unpublished
append, run `conn.recover_lerobot_append("robot_merged")` before retrying.
Recovery retains added columns; it does not undo published appends or repair concurrent writes.

For FileIO URIs, pass credentials through `source_options`:

Expand Down
32 changes: 12 additions & 20 deletions paimon-python/pypaimon/multimodal/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,9 @@ def load_from_lerobot(
dataset_name=None,
extra_dataset_fields=None,
schema_evolution=True,
append=False,
max_parallelism=None) -> None:
"""Import LeRobot v3 sources using table_name as the group prefix.

Creates <table_name>_frames, <table_name>_episodes, and
<table_name>_datasets. Use append_to_lerobot for an existing group.

parallelism="auto" sizes Ray tasks from the source data.
max_parallelism limits the number of outstanding tasks in auto mode.
"""
"""Import new Datasets; append=True adds them to an existing table group."""
from pypaimon.multimodal.lerobot import load_from_lerobot
load_from_lerobot(
self,
Expand All @@ -167,6 +161,7 @@ def load_from_lerobot(
dataset_name=dataset_name,
extra_dataset_fields=extra_dataset_fields,
schema_evolution=schema_evolution,
append=append,
max_parallelism=max_parallelism,
)

Expand All @@ -175,27 +170,24 @@ def append_to_lerobot(
table_name: str,
source,
*,
dataset_id,
batch_size: int = 1024,
source_options=None,
tag_name=None,
parallelism=1,
dataset_name=None,
extra_dataset_fields=None,
schema_evolution=True) -> None:
"""Append LeRobot v3 datasets to a source-local three-table group.

Pass multiple sources in one call for Ray-parallel preparation. Only
one append call may commit to a given group at a time; its three tables
do not share a transaction.
"""
from pypaimon.multimodal.lerobot import load_from_lerobot
load_from_lerobot(
schema_evolution=True,
max_parallelism=None) -> None:
"""Append Episodes to an existing Dataset, keeping its UUID and name."""
from pypaimon.multimodal.lerobot import append_to_lerobot
append_to_lerobot(
self, table_name, source, batch_size=batch_size,
source_options=source_options, tag_name=tag_name,
parallelism=parallelism, dataset_name=dataset_name,
parallelism=parallelism,
dataset_id=dataset_id,
extra_dataset_fields=extra_dataset_fields,
schema_evolution=schema_evolution,
append=True,
max_parallelism=max_parallelism,
)

def recover_lerobot_append(self, table_name: str):
Expand Down
3 changes: 2 additions & 1 deletion paimon-python/pypaimon/multimodal/lerobot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

"""LeRobot Dataset v3 integration for multimodal Paimon tables."""

from pypaimon.multimodal.lerobot.api import load_from_lerobot
from pypaimon.multimodal.lerobot.api import append_to_lerobot, load_from_lerobot
from pypaimon.multimodal.lerobot.dataset import (
PaimonDatasetReader,
PaimonLeRobotDataset,
Expand All @@ -29,4 +29,5 @@
"PaimonLeRobotDataset",
"PaimonLeRobotWriter",
"load_from_lerobot",
"append_to_lerobot",
]
42 changes: 31 additions & 11 deletions paimon-python/pypaimon/multimodal/lerobot/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ def _plan_merge(plans, extra_dataset_fields=None, schema_evolution=True,


def _transform_frames(plan, batch, episode):
if "stored_controls" in plan:
from pypaimon.multimodal.lerobot.episode_append import _transform_append_frames
batch = _transform_append_frames(plan, batch, episode)
batch = batch.append_column(
pa.field(_DATASET_ID_COLUMN, pa.string(), nullable=False),
pa.array([plan[_DATASET_ID_COLUMN]] * batch.num_rows, type=pa.string()))
Expand Down Expand Up @@ -584,6 +587,9 @@ def _merged_episodes(plans, schema):
stats.setdefault(feature, {})[statistic] = value
row[_DATASET_ID_COLUMN] = plan[_DATASET_ID_COLUMN]
row["stats"] = _variant_value(stats)
if "stored_controls" in plan:
from pypaimon.multimodal.lerobot.episode_append import _append_episode_row
row = _append_episode_row(plan, row, episode_offset)
records.append(row)
episode_offset += 1
yield pa.Table.from_pylist(records, schema=schema)
Expand Down Expand Up @@ -627,7 +633,7 @@ def _resolve_import_target(connection, table_name, append):
def _import_sources(connection, table_name, sources, batch_size, options,
source_options, tag_name, parallelism=1,
dataset_name=None, extra_dataset_fields=None,
schema_evolution=True, append=False, max_parallelism=None):
schema_evolution=True, append=False, dataset_id=None, max_parallelism=None):
from functools import partial
from pypaimon.multimodal.lerobot.api import _create_target_table, _validated_counts

Expand Down Expand Up @@ -666,6 +672,7 @@ def _import_sources(connection, table_name, sources, batch_size, options,
"extra_dataset_fields": _read_text_fields(resolved, extra_dataset_fields),
"metadata": _load_dataset_metadata(dataset, info, resolved)})
existing = None
episode_append = None
if table is not None:
if options:
raise ValueError("LeRobot append cannot change table options.")
Expand All @@ -692,9 +699,8 @@ def _import_sources(connection, table_name, sources, batch_size, options,
% (tag_name, component.identifier))
if _DATASET_ID_COLUMN not in _target_schema(tables["episodes"]).names:
raise ValueError("LeRobot append requires a source-local table group.")
source_rows = _read_arrow(tables["datasets"], [
"id", "info", "tasks", "subtasks", "stats",
]).sort_by("id").to_pylist()
columns = None if dataset_id is not None else ["id", "info", "tasks", "subtasks", "stats"]
source_rows = _read_arrow(tables["datasets"], columns).sort_by("id").to_pylist()
if not source_rows:
raise ValueError("LeRobot append requires an initialized table group.")
ranges = _source_dataset_ranges(source_rows)
Expand All @@ -705,15 +711,18 @@ def _import_sources(connection, table_name, sources, batch_size, options,
("episodes", tables["episodes"]),
("datasets", tables["datasets"])):
snapshot = component.snapshot_manager().get_latest_snapshot()
if snapshot is None or snapshot.next_row_id != expected_counts[name]:
count = (None if snapshot is None else snapshot.total_record_count

@JingsongLi JingsongLi Dec 2, 2026 •

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] Handle existing writers before publishing the first Episode append

On a two-Dataset group, the first Episode append changes the Dataset table's (total_record_count, next_row_id) from (2, 2) to (2, 4). An existing writer then rejects its append_to_lerobot(table, source) call for adding a new Dataset with incomplete datasets data, even after recovery returns successfully. Reproduced with the writer at master c4986e04. This also affects rollback to the previous writer. Please document the writer upgrade order and the rollback limit, or land the total_record_count preflight as a compatible prerequisite.

if name == "datasets" else snapshot.next_row_id)
if count != expected_counts[name]:
raise ValueError(
"LeRobot group has incomplete %s data; call "
"recover_lerobot_append before appending." % name)
existing = (table, tables, source_rows, ranges)
previous = source_rows[-1]["id"] if existing is not None else None
for plan in plans:
previous = _next_dataset_uuid(previous)
plan[_DATASET_ID_COLUMN] = previous
if dataset_id is None:
previous = _next_dataset_uuid(previous)
plan[_DATASET_ID_COLUMN] = dataset_id if dataset_id is not None else previous
metadata, stats = _plan_merge(
plans, extra_dataset_fields, schema_evolution if existing is None else True,
source_rows if existing is not None else None)
Expand Down Expand Up @@ -762,6 +771,10 @@ def _import_sources(connection, table_name, sources, batch_size, options,
new_stats = metadata["datasets_table"]["stats"][0].as_py()
if (old_stats is None) != (new_stats is None):
raise ValueError("LeRobot append has incompatible statistics.")
if dataset_id is not None:
from pypaimon.multimodal.lerobot.episode_append import _plan_episode_append
episode_append = _plan_episode_append(
table.raw_table, tables["episodes"], source_rows, plans, dataset_id)
_validate_lerobot_schema(target_schema, _target_schema(table.raw_table), "append")
# Validate every component before making any catalog changes.
requests = [
Expand All @@ -786,8 +799,9 @@ def _import_sources(connection, table_name, sources, batch_size, options,
frame_offset = ranges[-1][4]
episode_offset = ranges[-1][2]
for plan in plans:
plan["frame_offset"] += frame_offset
plan["episode_offset"] += episode_offset
if dataset_id is None:
plan["frame_offset"] += frame_offset
plan["episode_offset"] += episode_offset
metadata["datasets_table"] = pa.Table.from_pylist(
metadata["datasets_table"].to_pylist(),
schema=_target_schema(tables["datasets"]))
Expand Down Expand Up @@ -853,8 +867,14 @@ def _import_sources(connection, table_name, sources, batch_size, options,
if table.raw_table.create_global_index(column, index_type="btree") <= 0:
raise RuntimeError("LeRobot append did not refresh %s index."
% column)
if _append_arrow(tables["datasets"], metadata["datasets_table"]) is None:
raise RuntimeError("LeRobot append did not commit Dataset metadata.")
if episode_append is None:
if _append_arrow(tables["datasets"], metadata["datasets_table"]) is None:
raise RuntimeError("LeRobot append did not commit Dataset metadata.")
else:
from pypaimon.multimodal.lerobot.episode_append import _finish_episode_append
from pypaimon.multimodal.lerobot.metadata import _overwrite_arrow
_overwrite_arrow(tables["datasets"], _finish_episode_append(

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] Resolve an ambiguous Dataset overwrite before rolling back Frames and Episodes

With one writer and a local REST catalog, I delayed this overwrite on the server until the client timed out. Automatic recovery saw the old Dataset metadata and rolled Frames and Episodes back to 5 and 2. The delayed overwrite then committed metadata declaring 10 frames and 4 Episodes. recover_lerobot_append refuses to repair a group with fewer physical rows than declared. The existing lost-response test covers an overwrite that is already visible. Please fence or resolve an outstanding metadata commit before rolling back the data it may publish.

episode_append, plans, _target_schema(tables["datasets"])))
if tag_name is not None:
from pypaimon.multimodal.lerobot.metadata import create_lerobot_tag
create_lerobot_tag(connection, table_name, tag_name)
44 changes: 29 additions & 15 deletions paimon-python/pypaimon/multimodal/lerobot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,32 @@ def load_from_lerobot(
append: bool = False,
max_parallelism: Optional[int] = None,
) -> None:
"""Import one or more LeRobot v3 sources into a new Paimon table group.

``table_name`` is the group prefix; frames are stored in ``<table_name>_frames``.
Schema evolution adds new columns by default; missing values become null.
Common fields must keep their types and feature definitions. Differing
source FPS is handled automatically. ``dataset_name`` is a label or an ordered
list of labels. ``extra_dataset_fields`` maps columns to relative UTF-8
text file paths or globs in each source. Globs produce maps keyed by paths
relative to their static directory prefix, without the final suffix.
``_datasets`` retains source metadata. ``tag_name`` pins component snapshots.
FileIO credentials come from ``source_options``. Use ``append=True`` to
append to an existing group. ``options`` applies when creating a group.
An integer parallelism above one or ``parallelism="auto"`` uses Ray.
In auto mode, ``max_parallelism`` limits how many Ray tasks are outstanding.
"""Import LeRobot v3 sources, creating one Dataset per source.

``table_name`` is the group prefix. Use ``append=True`` for an existing group.
``parallelism="auto"`` sizes Ray tasks; ``max_parallelism`` bounds concurrency.
"""
return _load_from_lerobot(
connection, table_name, source, batch_size, options, source_options,
tag_name, parallelism, dataset_name, extra_dataset_fields, schema_evolution, append,
max_parallelism=max_parallelism)


def append_to_lerobot(connection, table_name, source, *, dataset_id, batch_size=1024,
source_options=None, tag_name=None, parallelism=1,
extra_dataset_fields=None, schema_evolution=True, max_parallelism=None):
"""Append v3 Episodes to an existing Dataset UUID."""
if not isinstance(dataset_id, str) or not dataset_id.strip():
raise ValueError("dataset_id must be an existing Dataset UUID.")
return _load_from_lerobot(
connection, table_name, source, batch_size, None, source_options,
tag_name, parallelism, None, extra_dataset_fields, schema_evolution, True,
dataset_id=dataset_id, max_parallelism=max_parallelism)


def _load_from_lerobot(connection, table_name, source, batch_size, options, source_options,
tag_name, parallelism, dataset_name, extra_dataset_fields,
schema_evolution, append, dataset_id=None, max_parallelism=None):
if sys.version_info < (3, 10):
raise RuntimeError(
"load_from_lerobot requires Python 3.10 or newer; install and "
Expand All @@ -88,6 +99,8 @@ def load_from_lerobot(
raise ValueError('max_parallelism requires parallelism="auto".')
if not isinstance(schema_evolution, bool):
raise ValueError("schema_evolution must be a boolean.")
if not isinstance(append, bool):
raise ValueError("append must be a boolean.")
if dataset_name is not None:
if isinstance(dataset_name, str):
dataset_name = [dataset_name]
Expand All @@ -110,7 +123,8 @@ def load_from_lerobot(
return _import_sources(
connection, table_name, source, batch_size, options,
_validated_source_options(source_options), tag_name, parallelism,
dataset_name, extra_dataset_fields, schema_evolution, append, max_parallelism)
dataset_name, extra_dataset_fields, schema_evolution, append,
dataset_id=dataset_id, max_parallelism=max_parallelism)


def _validated_counts(info, source):
Expand Down
Loading
Loading