Repository navigation
[python] Separate LeRobot dataset loading and episode appends #11614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1144446
2ab45f4
e0a973a
ff85727
399e1da
0a44b66
ffa3def
588d776
38324e9
2ff3af9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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())) | ||
|
|
@@ -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) | ||
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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.") | ||
|
|
@@ -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) | ||
|
|
@@ -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 | ||
| 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) | ||
|
|
@@ -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 = [ | ||
|
|
@@ -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"])) | ||
|
|
@@ -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( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| 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) | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 itsappend_to_lerobot(table, source)call for adding a new Dataset withincomplete datasets data, even after recovery returns successfully. Reproduced with the writer atmasterc4986e04. This also affects rollback to the previous writer. Please document the writer upgrade order and the rollback limit, or land thetotal_record_countpreflight as a compatible prerequisite.