forge icon indicating copy to clipboard operation
forge copied to clipboard

feat(rlds): carry source episode metadata into RLDS episode_metadata

Open idoco2003 opened this issue 5 months ago • 0 comments

What

The RLDS writer dropped Episode.metadata on conversion. RLDS supports per-episode metadata first-class, so this carries it through under a new episode_metadata/metadata_json field: the source episode's metadata, JSON-encoded.

Why

Episode already has a metadata dict, and other formats can preserve it, but the RLDS path silently discarded it. Any per-episode annotations a source carried (operator, site, trial id, collection notes) were lost on conversion to RLDS.

How

  • _create_tf_example: write episode_metadata/metadata_json = json.dumps(episode.metadata or {}) alongside the existing episode_metadata/file_path.
  • _write_features_json: declare metadata_json (a TFDS Text feature) in the episode_metadata features dict.

A single JSON string keeps arbitrary metadata keys in one fixed TFDS feature, so the schema stays uniform across episodes (the field is "{}" when an episode has no metadata). The new field sits beside file_path, so existing readers are unaffected.

Tests

tests/test_rlds_writer.py: the metadata round-trips through the written TFRecord and is declared in features.json; an episode with no metadata still writes a valid "{}". The existing RLDS writer tests pass unchanged.

Scope

This PR covers the RLDS writer only. The lerobot-v3 writer also drops Episode.metadata, but its episodes parquet is a fixed spec with no metadata slot, so carrying it there is a schema extension with compatibility considerations; I left it out of this focused fix. Happy to look at it separately if you'd want it.

idoco2003 avatar Jun 16 '26 12:06 idoco2003