Skip to content

[python] Support heterogeneous LeRobot v3 imports - #11622

Open
Zouxxyy wants to merge 4 commits into
apache:masterfrom
Zouxxyy:feat/lerobot-numeric-widening
Open

Zouxxyy wants to merge 4 commits into
apache:masterfrom
Zouxxyy:feat/lerobot-numeric-widening

Conversation

@Zouxxyy

@Zouxxyy Zouxxyy commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Purpose

Allow LeRobot v3 Datasets with different robot types and feature annotations to share a table group.

  • Validate shared columns by storage type and video layout. Preserve each Dataset's feature definitions and statistics in _datasets.
  • Widen float32 to float64 and int32 to int64 for frame scalars and one-dimensional arrays with schema evolution enabled, including on append.
  • Fill missing Episode task labels from frame IDs. Scope shared task dictionaries to IDs used by the Dataset when the vocabulary is unambiguous. Reject conflicting declared labels and ambiguous active IDs.

Tests

  • LeRobot import, append, read, Ray, writer, and video regression suites: 536 passed, 1 skipped.
  • Flake8 passed for the changed files.

@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 e462986. The LeRobot aggregate, Ray, and native-reader suites ran locally with PyArrow 22. They reported 346 passed and 13 skipped.

if pa.types.is_list(data_type):
path.append("element")
data_type = data_type.value_type
changes.append(SchemaChange.update_column_type(

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] Prevent silent truncation when scanning through a stale table handle

An untagged frame-table handle opened before this ALTER keeps the old INT schema and still scans the latest snapshot. After appending a BIGINT source, I reproduced 2**40 being read as 0 through that handle. A freshly loaded handle returns 1099511627776. Please use a schema that matches the snapshot for untagged reads or reject the incompatible read before casting.

!= _NUMERIC_DTYPE_WIDENINGS.get(dtype, dtype)
or _feature_shape(previous, name) != _feature_shape(feature, name)
or previous.get("names") != feature.get("names")):
raise ValueError(

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] Apply dataset_index before checking feature compatibility across sources

I could read a source with a two-element joints feature through dataset_index=0. After appending a source with three elements, the same reader fails to initialize because _load_dataset() checks the entire group's feature definitions before applying the source selection. Please select the source first and use that Dataset's feature definitions, statistics, and frame ranges.

"Read the table by dataset_id and use each Dataset's info." % name)
for field in _merge_schemas([_schema_from_info(info) for info in infos], widen_numeric=True):
if field.name in frame_schema.names:
_widen_frame_feature(merged["features"][field.name], frame_schema.field(field.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] Validate timestamps using the source Dataset's dtype

After widening, the reader uses float64 to compute the expected timestamp for existing float32 rows. At 30 FPS, the stored timestamp for frame_index=61441 is 2048.033447265625 after widening. The reader expects 2048.0333333333333 and rejects the row at the default 1e-4 tolerance. Please keep the widened storage type and use the source Dataset's timestamp dtype for validation.

changes = [_plan_schema_evolution(
_target_schema(component), schema, schema_evolution, required,
video_fields if ordinal == 0 else ())
metadata["video_fields"] if ordinal == 0 else (), widen_numeric=ordinal == 0)

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] Account for existing B-tree indexes before widening a column

I built a B-tree on an INT frame feature and appended a source declaring the same feature as BIGINT. The old 4-byte keys remain under the same field ID. A vector search with a scalar prefilter then tries to decode those keys as 8-byte values and raises struct.error. Please check for indexes before ALTER and either reject widening the indexed column or rebuild its index for the new schema.

if source_type.value_field.nullable != target_type.value_field.nullable:
return False
source_type, target_type = source_type.value_type, target_type.value_type
return _NUMERIC_TYPE_WIDENINGS.get(source_type) == target_type

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] Check the declared LeRobot dtype before widening storage

A float16 feature uses Arrow float32 for storage, so this check also widens it to float64. I simulated a write failure after ALTER. The original Dataset remained the only row in _datasets. Its training reader failed because its float16 definition still expects a FLOAT column. Please check the declared dtype and reject unsupported promotions before changing the schema.

for row in dictionary.select(["task_index", label_column]).to_pylist():
task_id = _integer(row["task_index"], "task_index")
label = row[label_column]
if task_id < 0 or not isinstance(label, str) or not label.strip() \

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] Scope the shared dictionary before validating ambiguity and count

Conflicting labels for unused ID 3 abort the import even when every frame uses the unambiguous ID 9. The frame-only count also rejects total_tasks=2 when Episodes declare pick and place and the frames only use pick. Please resolve frame IDs and uniquely identifiable Episode labels before validating ambiguity and total_tasks. Existing Episode label behavior

_repair_task_metadata(plan["dataset"], info, metadata)
try:
validate()
except _MissingEpisodeTasks:

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 empty task labels before comparing Episode shard schemas

A shard whose tasks are all empty lists can infer list<null>, while a shard with declared labels uses list<string>. _source_episodes() rejects that combination before this recovery can run. Please allow repairable tasks types through the shard schema check so the missing labels can be derived from frame IDs.

metadata["filled_episode_tasks"] = filled
schema = metadata["episodes_schema"]
index = schema.get_field_index("tasks")
metadata["episodes_schema"] = schema.set(index, schema.field(index).with_type(pa.list_(pa.string())))

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 scalar Episode task columns during dictionary repair

Scoping a shared dictionary changes tasks to ARRAY<STRING> even when every Episode already has a valid scalar label. I reproduced an append failing its schema check against the existing STRING column. Please retain the original column type for dictionary-only repair and write a scalar value when a missing label in a scalar field resolves to a single task.

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