Macrodata_Labs
AboutBlogDemo
Announcing MacroHands, our SOTA model for 3D hands and camera path from egocentric video!
// Docs›
Quickstart
Running pipelines
  • In-process debugging
  • Local launcher
Reading data
  • Reader model
  • Sharding
  • LeRobot reader
  • HDF5 reader
  • Zarr reader
  • MCAP reader
  • Tabular files
  • Files and videos
  • Hugging Face
  • TensorFlow
  • Lance
  • Custom readers
Episode data
  • Episode rows
  • Frames and videos
  • Metadata, tasks, and stats
  • Converting to robot rows
Transforms
  • Row transforms
  • Async and batch transforms
  • Vectorized transforms
  • Expressions
  • Schemas and DTypes
Episode operations
  • Motion trimming
  • Subtask annotation
Inference
  • Generate text
  • Multimodal and structured output
  • Inference providers
  • Pooling
Writing data
  • Writer model
  • LeRobot writer
  • Zarr writer
  • Parquet and JSONL writers
  • Lance
  • Media assets and reducers
Examples
  • ALOHA HDF5
  • robomimic HDF5
  • Zarr replay buffer
  • MCAP Franka
  • LIBERO HDF5
  • Merge LeRobot datasets
  • Annotate subtasks
Reference
  • Path formats
  • Optional dependencies
// Docs
Quickstart
Running pipelines
  • In-process debugging
  • Local launcher
Reading data
  • Reader model
  • Sharding
  • LeRobot reader
  • HDF5 reader
  • Zarr reader
  • MCAP reader
  • Tabular files
  • Files and videos
  • Hugging Face
  • TensorFlow
  • Lance
  • Custom readers
Episode data
  • Episode rows
  • Frames and videos
  • Metadata, tasks, and stats
  • Converting to robot rows
Transforms
  • Row transforms
  • Async and batch transforms
  • Vectorized transforms
  • Expressions
  • Schemas and DTypes
Episode operations
  • Motion trimming
  • Subtask annotation
Inference
  • Generate text
  • Multimodal and structured output
  • Inference providers
  • Pooling
Writing data
  • Writer model
  • LeRobot writer
  • Zarr writer
  • Parquet and JSONL writers
  • Lance
  • Media assets and reducers
Examples
  • ALOHA HDF5
  • robomimic HDF5
  • Zarr replay buffer
  • MCAP Franka
  • LIBERO HDF5
  • Merge LeRobot datasets
  • Annotate subtasks
Reference
  • Path formats
  • Optional dependencies

Async and batch transforms

Use map_async, batch_map, and batch_map_async for concurrent I/O and batched model work

Use async and batch transforms when a row transform would be too slow one row at a time.

map_async

map_async runs an async function over rows with bounded concurrency.

1
2
3
4
5
6
7
8
9
10
async def classify_episode(row):
    label = "long" if row.num_frames > 300 else "short"
    return row.update({"label": label})


pipeline = pipeline.map_async(
    classify_episode,
    max_in_flight=32,
    preserve_order=True,
)

Use max_in_flight to match provider rate limits, memory limits, or open file limits.

For expensive worker-local state, pass a zero-argument factory instead of a callback:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Classifier:
    def __init__(self):
        self.client = create_client()

    async def __call__(self, row):
        label = await self.client.classify(row["text"])
        return {"label": label}


def create_classifier():
    return Classifier()


pipeline = pipeline.map_async(
    factory=create_classifier,
    max_in_flight=32,
)

When callbacks return large values such as image or video bytes, set a small execution block row limit:

1
pipeline = pipeline.with_max_block_rows(16)

The row limit applies to source and transformed Python row blocks before they reach the sink. Callback results that are still in flight are separate, so choose max_in_flight and max_block_rows with the largest expected result in mind. with_max_vectorized_block_bytes(...) applies only to Arrow blocks from sources or vectorized operations; it does not estimate the size of Python row values.

Inference helpers

Most model calls should use Refiner's inference helpers instead of calling an API directly:

1
2
3
4
5
6
7
8
pipeline = pipeline.map_async(
    mdr.inference.generate_text(
        fn=annotate,
        provider=mdr.inference.OpenAIResponsesProvider(model="gpt-4.1"),
        max_concurrent_requests=64,
    ),
    max_in_flight=64,
)

See Generate Text.

batch_map

batch_map receives a list of rows and returns rows.

1
2
3
4
5
6
def add_batch_rank(rows):
    for index, row in enumerate(rows):
        yield row.update({"batch_rank": index})


pipeline = pipeline.batch_map(add_batch_rank, batch_size=32)

Use this for perception pipelines or model APIs that naturally process batches.

Use factory when constructing the batch callback loads a model or another expensive resource:

1
2
3
4
5
6
7
8
9
10
11
12
13
def create_batch_model():
    model = load_model("model.pt")

    def infer(rows):
        return model.predict(rows)

    return infer


pipeline = pipeline.batch_map(
    factory=create_batch_model,
    batch_size=32,
)

batch_map_async

batch_map_async processes multiple batches concurrently. Use max_in_flight to bound concurrency and preserve_order when output order must match input order:

1
2
3
4
5
6
pipeline = pipeline.batch_map_async(
    factory=create_async_batch_model,
    batch_size=64,
    max_in_flight=2,
    preserve_order=True,
)

The callback receives list[Row] and returns rows, either directly or through an awaitable.

Order and backpressure

SettingEffect
preserve_order=TrueOutput order follows input order.
preserve_order=FalseFaster rows may be emitted first.
Smaller max_in_flightLower memory and lower external pressure.
Larger max_in_flightMore concurrency, but easier to hit rate limits.

Related pages

  • Subtask Annotation

// Table of Contents

  1. mapasync
  2. Inference helpers
  3. batchmap
  4. batchmapasync
  5. Order and backpressure
  6. Related pages
Macrodata_Labs
TermsPrivacyContact
  • GitHub
  • LinkedIn
  • X
  • HuggingFace
  • Discord