Metadata-Version: 2.5
Name: lerobot-tailor
Version: 0.14.1
Summary: Refine distributed robot datasets into training-ready data: acceptance checks, episode-level filtering, deterministic cleaning, provenance.
Project-URL: Homepage, https://github.com/XBR-1111/tailor
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: data-quality,dataset,lerobot,robotics,validation
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.12
Requires-Dist: av>=12
Requires-Dist: huggingface-hub>=0.26
Requires-Dist: pandas>=2
Requires-Dist: pyarrow>=15
Requires-Dist: pyyaml>=6
Requires-Dist: rich>=13
Requires-Dist: typer>=0.12
Provides-Extra: lerobot
Requires-Dist: lerobot[dataset]>=0.6; extra == 'lerobot'
Description-Content-Type: text/markdown

# tailor

**Refine distributed robot datasets into training-ready data.**

[![CI](https://github.com/XBR-1111/tailor/actions/workflows/ci.yml/badge.svg)](https://github.com/XBR-1111/tailor/actions/workflows/ci.yml)
[![Python 3.12+](https://img.shields.io/badge/python-3.12%2B-blue)](https://www.python.org/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![mypy](https://img.shields.io/badge/mypy-checked-blue)](https://mypy-lang.org/)
[![License](https://img.shields.io/badge/license-Apache--2.0-green)](LICENSE)

English | [简体中文](README.zh-CN.md)

tailor is a data-refinement pipeline for robot learning datasets (LeRobot **v2.0 / v2.1 / v3.0**):

- **Accept** — verify incoming distributed datasets: format-version compliance, metadata-vs-data consistency ("does the package match the label"), transfer integrity, dims and stats vs your training config
- **Cut** — episode-level filtering (frame-level issues escalate to episode removal to preserve action-chunk coherence)
- **Sew** — deterministic cleaning only: timestamp rebuild, stats recompute. No imputation, no video re-encode (planned — see roadmap)
- **Re-check** — cleaned output must pass the acceptance suite again before release
- **Register** — provenance ledger: source version, dropped episodes + why, recipe hash

Declarative recipes (YAML) in git; every dataset is reproducible and auditable.

*tailor-made datasets for your training.*

## Quickstart

```bash
pip install lerobot-tailor
# or track main: pip install git+https://github.com/XBR-1111/tailor

tailor check /path/to/lerobot/dataset
tailor check dataset.zip                # zip archive (wrapper dirs peeled)
tailor check lerobot/unitreeh1_fold_clothes   # HF repo id: meta pre-check, no full download
tailor check lerobot/... --full               # download everything, all 25 checks
```

```
┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ check             ┃ status ┃ detail       ┃
┡━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━┩
│ info_json         │  PASS  │              │
│ codebase_version  │  PASS  │ v3.0         │
│ fps               │  PASS  │ 50           │
│ episodes_metadata │  PASS  │ 38 episodes  │
│ episode_files     │  PASS  │              │
│ total_frames      │  PASS  │ 19000        │
│ episode_lengths   │  PASS  │              │
│ task_indices      │  PASS  │ 1 task       │
│ state_action_dims │  PASS  │              │
│ nan_inf           │  PASS  │              │
│ timestamps        │  PASS  │              │
└───────────────────┴────────┴──────────────┘
ACCEPTED  ·  11 passed, 0 warn, 0 failed  ·  11 skipped (meta-only run)
```

By default, remote mode downloads `meta/*` (a few MB) and skips checks that
need data and video files. Local inputs and remote `--full` runs reject
missing required files and unreadable Parquet for the selected episodes.
Downloads cache under `~/.cache/tailor-hf/`.

Exit codes make it a CI gate: **0** accepted · **1** rejected · **2** unreadable
(`--fail-on-warn` makes WARN exit 1 too). `--json` emits machine-readable output,
`--markdown report.md` writes a PR/dataset-card friendly report, `--max-episodes N`
samples N episodes of huge datasets — a convenience sample, defaulting to the
tail (`--sample last`): tail-end episodes are a common corruption site that a
first-N sample never sees. `--fail-on-skip` exits 3 when any check was SKIPped
(remote meta-only runs leave file-dependent checks unjudged — green is not a
full pass there).

## Filter — the Cut stage

`tailor filter` rewrites a dataset without the episodes you don't want, using
lerobot's official `delete_episodes` engine (so the output is format-compatible
by construction — parquet, videos and stats are rebuilt consistently). The
result is **re-checked automatically**; its verdict is printed.

```bash
# drop explicit episodes (say, the ones a report flagged)
tailor filter /data/ds --drop-episodes 5,17,23 -o /data/ds_clean

# drop everything FAIL-level checks can pin to an episode (--drop-warn adds WARN)
tailor filter /data/ds --from-check --dry-run --json
tailor filter /data/ds --from-check --drop-warn

# rule-based
tailor filter /data/ds --min-length 100        # too short for your policy
tailor filter /data/ds --dedupe                # byte-identical trajectories, keep first
```

Requires `pip install 'lerobot-tailor[lerobot]'` (the acceptance suite itself stays
dependency-free). Currently v3.0 datasets. Every drop is printed with its
reason — no silent removals.

Use `--dry-run` to inspect the full plan before writing an output. Add `--json`
to save the plan or consume it in CI. Previewing works without the LeRobot extra.

`--from-check` uses every identified episode, including those beyond the
report's examples. Video spans that exceed a shared shard identify specific
episodes for removal. If the rules select every episode, the command exits
with an error before writing an output.

## Reproduce a run with YAML

The [Unitree recipe](examples/unitree.yaml) pins the public dataset revision
and uses the same checks for planning and rechecking. It downloads the full
dataset on the first run. The episode plan is available before any output is
written.

```bash
tailor run examples/unitree.yaml --json
tailor run examples/unitree.yaml --apply --json
```

Install `lerobot-tailor[lerobot]` to apply a recipe that removes episodes.
See the [recipe CLI reference](docs/cli.md#run).

## Clean — deterministic repairs

`tailor clean` rebuilds timestamps as `frame_index / fps` and recomputes
`meta/stats.json` from the resulting Parquet values. It preserves statistics
for unprocessed features like video. Existing numerical percentiles are
recomputed exactly, using temporary disk space for multi-shard data. By
default it previews the repair.
`--apply` backs up replaced files to `<dataset>_pre_clean/` outside the dataset
root, applies the repair, then re-checks the dataset. A rejection exits `1`.

```bash
tailor clean /data/ds            # dry-run: what would change, nothing written
tailor clean /data/ds --apply    # repair + backup + automatic re-check
```

## Register — the provenance ledger

Every `filter` and `clean --apply` appends one event to
`meta/tailor_ledger.jsonl` **inside the dataset**, so the processing history
travels with the data: filter writes a birth record into the output (source
fingerprint, dropped episodes and why), clean appends what it rewrote.

```bash
tailor provenance /data/ds_filtered
# 2026-10-31T02:37:45+00:00  filter  from raw (b6b8be2337b9aae4, 38 eps) -> dropped 1: ep37 (explicit --drop-episodes)
# 2026-10-31T02:37:47+00:00  clean   rewrote ['meta/stats.json']
```

`check` never writes — acceptance is read-only. Fingerprints are structural
(episode metadata + data file sizes), for identity not cryptographic proof.

## Diff and datasheet

Two commands for the pipeline around the gate. `tailor diff OLD NEW` compares
two dataset versions at meta level — structure, feature-schema drift, episode
set/length changes, video re-encodes (file-size signal), stats drift — with
exit codes **0** identical / **1** differs, so a re-delivery can be gated on
"did anything change". `tailor datasheet PATH` renders a delivery document:
scale and footage hours, feature table, acceptance verdicts, lineage — one
run of the check suite, ready for a dataset card or a handoff ticket.

## Use as a CI gate

`tailor check` is designed to sit in someone else's CI: exit codes are the
contract (**0** accepted / **1** rejected / **2** unreadable), `--json` for
machines, `--markdown` for humans. A ready-made reusable workflow ships in
this repo — one line gates a dataset in your pipeline:

```yaml
# your-repo/.github/workflows/dataset-quality.yml
jobs:
  check-dataset:
    uses: XBR-1111/tailor/.github/workflows/tailor-check.yml@v0.14.1
    with:
      dataset: lerobot/unitreeh1_fold_clothes   # HF repo id, local path, or .zip
      fail-on-warn: false
```

A rejected dataset fails the job; the markdown report lands in the run's
artifacts. Pin to a tag; `check` is read-only and never writes to the dataset.

## Configurable acceptance profiles

What counts as acceptable differs per robot, task and training config. A
profile (YAML in git — your dataset SLA, versioned and auditable) overrides
per-check thresholds and severities; tailor is the engine that executes it:

```yaml
# my_requirements.yaml
checks:
  codebase_version:
    allowed: [v2.1]     # this org only accepts v2.1
  fps:
    allowed: [30, 50]   # hardware reality
  episode_lengths:
    min: 100            # policy window needs headroom
    severity: fail      # short episodes are a hard reject here
  timestamps:
    spacing_tolerance: 0.2
```

```bash
tailor check /data/dataset --profile my_requirements.yaml
```

Any check can be remapped between WARN and FAIL, and any check can be
switched off entirely with `enabled: false` (it reports SKIP naming the
profile, is not executed, and contributes nothing to `--from-check`).
Unknown check names or keys in a profile fail fast with a clear error — a
typo in your requirements must not silently keep a default you meant to
change.

Full reference: [every tunable with defaults and guidance](docs/configuration.md)
· [every check's logic and corruption repro](docs/checks.md)
· [every command and flag](docs/cli.md).

Reading a report: [skill/SKILL.md](skill/SKILL.md) — severity buckets for all
checks and nine benign-finding scenarios (a binary gripper dimension trips
range-edge pegging in every episode by construction; sampled stats drift is
expected under `--max-episodes`), plus the SKIP-is-not-a-pass trap.

## The 25 acceptance checks

| check | catches |
| --- | --- |
| info_json | missing / invalid meta/info.json |
| codebase_version | format version outside v2.0/v2.1/v3.0 |
| fps | non-positive or unusual fps |
| episodes_metadata | missing/invalid episode metadata |
| episode_files | missing or unreadable Parquet, v3 shard membership and episode order |
| total_frames | declared total ≠ sum of episode lengths |
| episode_lengths | zero/negative lengths; very short episodes that break chunked sampling |
| task_indices | task references out of range; declared task count mismatch |
| state_action_dims | state/action dims ≠ info.json features |
| nan_inf | non-finite values in state/action |
| timestamps | non-monotonic timestamps; frame spacing deviating >10% from 1/fps |
| stats_recompute | declared stats.json mean/std drifting from recomputed values |
| action_quality | frozen (stuck) action runs; one action dim pegged at its declared range edge; sudden jumps beyond k·sigma |
| video_files | declared video streams missing on disk (v2 per-episode files, v3 shard pointers) |
| video_streams | undecodable video; frame count vs episode lengths; resolution vs declared shape; container fps vs declared fps; header duration vs decodable content (truncated recordings); rotation metadata; interlaced streams |
| video_black | black openings/closings — lens cap left on, camera that never started (decodes only the first/last frames of each file) |
| video_content | **deep scan, OFF by default**: full decode per video, flags frozen frames (double threshold: near-identical run + ≥25% bit-exact), mid-file black, covered lens, over-exposure, persistent blur (Laplacian vs dataset baseline, motion excluded). Enable with `video_content: {enabled: true}` in a profile |
| video_sync | cross-camera from/to timestamp drift in one episode (v3.0 metadata; stereo rigs without hardware sync) |
| zero_variance | dims that never move (std < eps): normalization would divide by zero |
| schema_consistency | column sets/dtypes drifting across episodes |
| frame_continuity | dropped frames (row count vs declared length, frame_index holes) |
| training_readiness | episodes shorter than your policy's chunk_size/horizon (configure to enable) |
| portability | symlinks (break on transfer), stray files in data/, unexpected top-level entries |
| duplicate_episodes | byte-identical state/action trajectories across episodes |
| splits | overlapping episode ranges across declared splits (train/eval leakage) |

Validated on real distributed datasets across all three supported formats —
v3.0: `lerobot/unitreeh1_fold_clothes` (921 MB); v2.1 AND v2.0 of
`lerobot/pusht` (206 eps), `lerobot/xarm_lift_medium_image` (800 eps) and
`lerobot/utaustin_mutex` (1500 eps / 362k frames / 1.4 GB — the full check
runs end-to-end in **~3 s**), all checked via the `@ref` syntax since `main`
always points at the latest format. Real findings on the way: frozen action
runs in 6 utaustin episodes (worst: 12 identical actions in ep 180), and
range-edge pegging in 3 pusht v2.0 episodes. The v2.x round surfaced and
fixed a layout bug where every v2.x dataset misreported all video files
missing (the synthetic fixture carried the same wrong layout — real data
caught what fixtures could not). The v0.10.1 round ran the deep video scan
across all 1500 utaustin episodes and surfaced three false-positive classes
that fixtures never could: a dataset-wide Laplacian baseline flagged every
wrist close-up as blur (404 hits), a wrist camera dimming into occlusion read
as a recorder failure, and `--max-episodes` did not bound the decode scan.
All three are fixed; the full re-run scans 3000 segments clean.

Also validated on a real 921 MB distributed dataset (`lerobot/unitreeh1_fold_clothes`,
38 episodes / 19k frames / stereo video) plus deterministic synthetic fixtures
with injected corruptions — every corruption is caught by a test, on both
format versions. The real dataset itself shipped two findings tailor caught
on first contact: an action dim pegged at its range edge for 29 frames
(gripper holding a folded shirt — WARN), and a genuine metadata defect where
`cam_left`'s episode-to-shard pointers all target `file-000.mp4` while 500 of
its frames actually live in an orphan `file-001.mp4` — verified with the
official reader: `LeRobotDataset` loads fine but every episode-37 frame
raises `IndexError` (video index capped at 18500), so training crashes the
moment a sampler touches the last episode.

## Performance

The suite converts each episode column to a numpy array exactly once and
shares it across checks (`DatasetSnapshot.col_array`), probes videos through
container metadata (`nb_frames`) in a thread pool, and vectorizes the
run-length scans. On a synthetic 150k-frame dataset (300 episodes x 500
frames): checks stage 0.79s -> 0.22s vs v0.5, ~11x on the pure check
computation — the end-to-end ratio is lower because loading PyAV (~0.16s,
one-time per process) dominates what's left. Reproduce with
`python scripts/bench.py`.

## Status

v0.10.0: 25 acceptance checks (video depth included), `filter` / `clean` /
provenance ledger, `diff` and `datasheet`, and the full reference docs under
`docs/`. Roadmap, in priority order:

**Accept depth** — complete through video content scanning (opt-in full
decode: frozen frames, covered lens, blur, mid-file black).

**Pipeline closure — Cut/Sew/Re-check/Register:**

- ~~`filter`~~ shipped (see above): explicit / rule-based / check-driven drops, dedupe, on official `delete_episodes`, auto re-check
- ~~`clean`~~ shipped (see above): stats recompute + timestamp rebuild, dry-run first
- ~~provenance ledger~~ shipped (see above): append-only, travels with the dataset
- ~~`diff` / `datasheet`~~ shipped (v0.10.0): version comparison and delivery documents
- ~~YAML recipes~~ shipped (v0.14.0): pinned input, plans and verified output

Reference points: lerobot-doctor (diagnostics, now in the official dataset visualizer), Calibra (episode disposition decisions). tailor's lane is the acceptance gate plus the executed pipeline — verdict + exit code as a CI door, then deterministic refinement with provenance, not another report.
