Repository navigation
[python] Merge stored LeRobot datasets into a new dataset - #11608
XiaoHongbo-Hope wants to merge 8 commits into
Conversation
JingsongLi
left a comment
There was a problem hiding this comment.
Reviewed 1a05134be8 and tested it with current master. A joint build with #11622 fails to import pypaimon.multimodal even though the Git merge succeeds.
| from pypaimon.data.generic_variant import GenericVariant | ||
| from pypaimon.multimodal.lerobot.aggregate import ( | ||
| _CONTROLS, _READ_CONTROL_STATS_COLUMN, _READ_CONTROL_STATS_DESCRIPTION, | ||
| _batch_stats, _feature_contract, |
There was a problem hiding this comment.
[P1] Keep the LeRobot merge API importable when #11622 lands
I merged both heads into master locally. Git found no conflicts, but import pypaimon.multimodal fails because #11622 removes _feature_contract, which this module imports at package initialization. #11622 also adds a required frame schema argument to _merged_source_info. Please reconcile both helpers before the two PRs land together and run a package import plus a stored-Dataset merge on the combined tree.
| stack.callback(reader.close) | ||
| for selected_source in selected: | ||
| _read_frames(reader, [(selected_source["id"], 0)], frame_schema.names) | ||
| frames = _create_target_table(connection, table_name, frame_schema, options, |
There was a problem hiding this comment.
[P2] Check the full output group before creating any tables
I created only collide_datasets, then invoked merge_lerobot_datasets("collide", "stored_frames"). The call correctly rejected the existing companion table, but it also left collide_frames and collide_episodes behind. A retry then stops on those tables. Please check all three destination names before creating the first table. Preserve any table that existed before the call.
|
|
||
| def _source_tables(connection, name, tag): | ||
| try: | ||
| frames = connection.get_table(name).raw_table |
There was a problem hiding this comment.
[P2] Resolve a LeRobot group prefix when an ordinary table has that name
An ordinary append table named stored can coexist with stored_frames, stored_episodes, and stored_datasets. In this setup the prefix form of merge_lerobot_datasets fails in Data Evolution validation. Passing stored_frames merges all ten rows. Please check whether the exact catalog candidate is a managed Frames table before validating it and otherwise try the group suffix.
| splits, needs_filter = ( | ||
| self._locator.locate(indices) if indices is not None | ||
| else self._locator.locate_predicate(predicate)) | ||
| if needs_filter: |
There was a problem hiding this comment.
[P2] Apply the Dataset filter when the Python index result is inexact
I kept the index B-tree, dropped only the dataset_id B-tree, and selected one of two stored Datasets using the Python path. The candidate splits contain rows from both Datasets, and this merge fails with Source LeRobot frame keys are missing or duplicated. The existing readable index should still be usable. Carry the full predicate through inexact lookup results as in #11299, or add that fix to this PR.
JingsongLi
left a comment
There was a problem hiding this comment.
Additional checks against the merged master tree covered stored quantile statistics and grouped Episode extensions.
| for name, stats in json.loads(source["stats"] or "{}").items(): | ||
| if name not in _CONTROLS: | ||
| parts.setdefault(name, []).append(stats) | ||
| return {name: values[0] if len(values) == 1 else _merge_stats(values) |
There was a problem hiding this comment.
[P1] Preserve quantile normalization in the merged Dataset
Both input Datasets had q01, q50, and q99 for action. merge_lerobot_datasets produced ten frames, but PaimonLeRobotDataset(...).meta.stats["action"] only had min, max, mean, std, and count. Quantile-based training cannot normalize this output. Please aggregate available quantiles using the supported LeRobot policy, as #11614 does for Episode append, and cover a two-Dataset merge.
| continue | ||
| prefixes = ("",) if group == "data" else tuple( | ||
| name + "/" for name in _video_feature_names(source_info)) | ||
| episode[group] = _variant_value(_file_coordinates( |
There was a problem hiding this comment.
[P2] Preserve uint64 Episode extensions when rewriting file coordinates
Initial import accepts a data/vendor_id extension stored as uint64 with value 2**64 - 1. Merging that Dataset fails here because VARIANT decoding returns Decimal and _variant_value rejects it as non-JSON. Please re-encode the remapped data and videos groups with a VARIANT encoder that preserves these values, and cover an import followed by merge.
jerry-024
left a comment
There was a problem hiding this comment.
Found three additional issues on 1a05134be8 covering subset merges after schema evolution, multi-Dataset preflight cache eviction, and source_tag merges after snapshot expiration.
| global_stats = _source_stats(selected) | ||
| if TimeTravelUtil.resolve_snapshot(source["episodes"]).total_record_count != ranges[-1][2]: | ||
| raise ValueError("Source Episodes and Dataset metadata disagree.") | ||
| frame_schema = _target_schema(source["frames"]) |
There was a problem hiding this comment.
[P2] Project frame_schema to the selected Datasets' features on subset merges
In a table group with schema-evolved columns (schema_evolution=True is the default in load_from_lerobot and append_to_lerobot), source["frames"] holds the union of all stored Datasets' columns while info["features"] only contains the selected Datasets' features. Passing _target_schema(source["frames"]) directly to _create_target_table and _copy_frames leaks all-null columns from unselected Datasets into the merged frames table, which desynchronizes frames from datasets.info["features"], causes spurious type conflicts on later append_to_lerobot, and—when an unselected Dataset had a video feature—creates that BLOB column without setting video-frame-field (causing a later append_to_lerobot with that video feature to skip add_column(..., comment=VIDEO_FRAME_FIELD_DIRECTIVE) in _plan_schema_evolution and leave video-frame-field permanently missing). Please project frame_schema to set(info["features"]) | {"dataset_id"} (preserving schema metadata) before opening _PaimonTableFrameReader and creating the target frames table.
| row_group_cache=_ParquetRowGroupCacheRequest(64 * 1024 * 1024)) | ||
| stack.callback(reader.close) | ||
| for selected_source in selected: | ||
| _read_frames(reader, [(selected_source["id"], 0)], frame_schema.names) |
There was a problem hiding this comment.
[P2] Avoid full-width preflight reads that thrash the 64 MiB row-group cache
The preflight loop probes frame 0 of every Dataset in selected using all frame_schema.names, although _read_frames only checks dataset_id and index. When merging multiple Datasets whose individual first row groups fit within 64 MiB (bypassing page pruning in FormatPyArrowReader) but exceed 64 MiB in aggregate, preflight decodes all columns for every Dataset and evicts earlier entries from the 64 MiB LRU cache; _copy_frames then iterates selected in the same order, misses on every Dataset, and decodes each first row group twice. Probing selected[1:] with only ["dataset_id", "index"] keeps index and frame-0 validation while preserving single-Dataset warm-cache reuse.
| snapshot = TimeTravelUtil.resolve_snapshot(table) | ||
| if snapshot is None: | ||
| raise ValueError("Source LeRobot %s table has no snapshot." % key) | ||
| pinned[key] = table._copy_with_snapshot(snapshot) \ |
There was a problem hiding this comment.
[P2] Keep source_tag merges working after the tagged snapshot expires
_source_tables resolves source_tag via TimeTravelUtil.resolve_snapshot (which succeeds from tag/tag-<name> even after snapshot/snapshot-<id> has been expired), then calls table._copy_with_snapshot(snapshot), which clears scan.tag-name and switches options to scan.snapshot-id. When _PaimonTableFrameReader initializes from source["frames"], _indexed_read_table (reader.py:231-233) sees scan_tag_name() is None and calls _time_travel_table(read_table, snapshot_id=plan.snapshot_id), dropping _read_snapshot (file_store_table.py:546), and reader.py:36-39 then calls snapshot_manager().get_snapshot_by_id(self.snapshot_id) which returns None for an expired snapshot and fails with AttributeError: 'NoneType' object has no attribute 'next_row_id'. Please preserve the already-pinned _read_snapshot (or resolve via TimeTravelUtil.resolve_snapshot instead of get_snapshot_by_id) so source_tag merges remain usable after snapshot expiration.
Merge stored Datasets into one independent Dataset with rebuilt indices, tasks, and statistics. Stream only selected Episode metadata and order it using a temporary disk sort.
Tests: 33 merge cases passed on Python and Native, including capture after merge; flake8 passed.