To use synthetic data generation features, install inference extras using:
uv sync --extra inference
The InferenceRunner supports vLLM, SGLang, OpenAI-compatible HTTPS endpoints, and a local dummy server. It uses asynchronous batching to maintain high GPU utilization.
Custom Rollouts
A rollout is an async callable that receives a Document, a generate(payload) callback, and shared_context kwargs. You can orchestrate multiple sequential or parallel calls within a single rollout.
- Set
rollouts_per_document to run the same rollout multiple times per sample; results are stored in document.metadata["rollout_results"].
Recoverable Generation
- Checkpointing: Set
checkpoints_local_dir and records_per_chunk to write documents to local chunk files. Failed tasks resume from the last finished chunk. Use ${chunk_index} in the output filename template. - Deduplication: When checkpointing is enabled, a sqlite-backed
RequestCache deduplicates rollouts via payload hashes (requires xxhash and aiosqlite). - Error Handling: Set
skip_bad_requests=True on InferenceRunner to ignore BadRequestError (e.g., context overflows) and continue processing.
from datatrove.data import Document
from datatrove.executor.local import LocalPipelineExecutor
from datatrove.pipeline.inference.run_inference import InferenceConfig, InferenceRunner
from datatrove.pipeline.writers import JsonlWriter
async def simple_rollout(doc: Document, generate):
payload = {"messages": [{"role": "user", "content": [{"type": "text", "text": doc.text}]}], "max_tokens": 2048}
return await generate(payload)
documents = [Document(text="What's the weather in Tokyo?", id=str(i)) for i in range(1005)]
config = InferenceConfig(server_type="vllm", model_name_or_path="google/gemma-3-27b-it", rollouts_per_document=1, max_concurrent_generations=500)
LocalPipelineExecutor(
pipeline=[
documents,
InferenceRunner(
rollout_fn=simple_rollout,
config=config,
skip_bad_requests=True,
records_per_chunk=500,
checkpoints_local_dir="/fsx/.../translate-checkpoints",
output_writer=JsonlWriter("s3://.../final_output_data", output_filename="${rank}_chunk_${chunk_index}.jsonl"),
),
],
logging_dir="/fsx/.../inference_logs",
tasks=1,
).run()