Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Huggingface Datatrove LLM Inference Execution

From Leeroopedia
Revision as of 18:09, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/Huggingface_Datatrove_LLM_Inference_Execution.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Inference, Synthetic_Data
Last Updated 2026-02-14 00:00 GMT

Overview

Orchestrating concurrent LLM inference across documents using user-defined rollout functions for scalable synthetic data generation.

Description

Inference execution is the core processing step of the datatrove synthetic data generation pipeline. It manages the concurrent processing of documents through user-defined rollout functions, which define the application-specific logic for interacting with an LLM. Each rollout function receives a document and a generate callback, sends one or more requests to the inference server, and returns structured results that are stored in the document's metadata.

The execution model is built around several key design decisions:

  • Rollout function protocol: Rollout functions follow a defined async protocol: Template:Code. The Template:Code callback is a Template:Code that sends a request payload to the inference server and returns the parsed result. This design decouples the application logic (what to ask the LLM) from the infrastructure (how to send requests).
  • Multi-rollout aggregation: Each document can be processed through multiple independent rollouts (controlled by Template:Code). All rollouts for a single document execute concurrently via Template:Code, and results are collected into a list stored under the configured metadata key. If all rollouts return Template:Code, the document is marked for removal.
  • Concurrency control: Two levels of concurrency are managed: (1) document-level concurrency via a task pool bounded by Template:Code, and (2) request-level concurrency via an Template:Code bounded by Template:Code. This two-tier approach prevents overwhelming the inference server while maximizing throughput.
  • Shared context: Rollout functions can receive additional keyword arguments from a shared context (e.g., process pools, coding environments). The shared context can be a plain dict, a callable, or a context manager, providing flexibility for resource initialization and cleanup.
  • Metrics collection: Real-time metrics are tracked for token throughput (prompt and completion), request success/failure rates, and queue sizes (waiting vs. running requests). Metrics are reported at configurable intervals with both lifetime and windowed (5-minute) rates.

Usage

Inference execution is the core step of synthetic data generation pipelines:

  • After server launch, as the main document processing loop
  • When generating annotations, labels, summaries, or other synthetic data for each document
  • When running multi-turn or multi-step reasoning workflows that require multiple LLM calls per document
  • In combination with checkpointing for long-running jobs that may be interrupted

Theoretical Basis

The execution model follows an async concurrent processing pattern with configurable parallelism:

Rollout Function Protocol:

class RolloutFunction(Protocol):
    def __call__(
        self,
        document: Document,
        generate: GenerateFunction,
        **kwargs: Any,
    ) -> Awaitable[RolloutResult]: ...

The rollout function is the user's entry point into the inference pipeline. It receives:

  • document: The input document to process
  • generate: An async callback that sends a request payload (dict) to the inference server and returns an Template:Code containing text, finish reason, and usage statistics
  • **kwargs: Additional keyword arguments from the shared context

Processing Pipeline:

  1. Data ingestion: Synchronous document iterators are wrapped in an async generator via a thread pool executor, allowing the pipeline to start processing without blocking on I/O
  2. Document dispatch: Documents are dispatched to the task pool up to Template:Code; when the pool is full, the pipeline waits for at least one task to complete
  3. Rollout execution: For each document, Template:Code rollout tasks are created and executed concurrently
  4. Request caching: Each generate call checks the request cache before sending to the server, preventing redundant inference on job restart
  5. Result aggregation: Rollout results are collected, filtered (removing Template:Code values), and stored in Template:Code
  6. Checkpoint and write: Processed documents are written to both the output writer and checkpoint files atomically

Retry Strategy:

Retryable errors use exponential backoff with a formula of Template:Code seconds, up to 6 retries. This yields delays of 5, 10, 20, 40, 80, 160 seconds across attempts.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment