Implementation:416rehman DeepZero PipelineRunner run
| Knowledge Sources | |
|---|---|
| Domains | Pipeline_Orchestration, Execution_Engine |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
Breadth-first pipeline executor that runs stages with ThreadPoolExecutor parallelism, sync barriers, retry/backoff, timeout-as-budget handling, and crash-safe resumability.
Description
The PipelineRunner class is the execution engine of DeepZero. It takes a loaded PipelineDefinition (an ingest processor plus a list of stage processors) and drives it to completion. The runner executes stages breadth-first: each stage processes all active samples before the next stage begins, forming a synchronization barrier. Map stages fan out across samples via a ThreadPoolExecutor; Reduce stages see all samples at once; BulkMap stages batch all samples into a single invocation.
Key design decisions baked into the runner:
- Timeout-as-budget: a stage that exceeds its timeout is marked TIMED_OUT (not FAILED), because the timeout is a statement about the budget, not the sample. The largest samples—often the most interesting—hit timeouts, and filing them as errors would bias runs away from good targets.
- Crash-safe resume: state is persisted atomically after each stage. Re-running the same command resumes from disk, skipping already-completed stages.
- SIGINT handling: a Ctrl+C is caught, state is saved as INTERRUPTED, and the runner exits cleanly.
Usage
- Running a pipeline end-to-end: construct a PipelineRunner and call run().
- Resuming an interrupted or failed run: call run() again on the same target and pipeline—the runner detects existing state on disk and skips completed stages.
- Retrying timed-out stages: pass --retry-timeouts on the CLI, which calls SampleState.clear_timed_out_stages() before running.
Code Reference
Source Location
- Repository: DeepZero
- File: src/deepzero/engine/runner.py
Signature
class PipelineRunner:
def __init__(
self,
ingest: IngestProcessor,
stages: list[tuple[StageSpec, Processor]],
state_store: StateStore,
pipeline_dir: Path,
global_config: GlobalConfig,
llm: LLMProtocol | None = None,
default_max_workers: int = 4,
console: Console | None = None,
dashboard: PipelineDashboard | None = None,
progress_hook: Callable[[], None] | None = None,
): ...
def run(
self,
target: Path,
run_state: RunState,
) -> RunState: ...
Import
from deepzero.engine.runner import PipelineRunner
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| ingest | IngestProcessor | Yes | First-stage processor that discovers samples |
| stages | list[tuple[StageSpec, Processor]] | Yes | Subsequent stage processors with their specs |
| state_store | StateStore | Yes | Atomic state persistence layer |
| target | Path | Yes | File or directory to scan (passed to ingest) |
| run_state | RunState | Yes | Run metadata (run_id, pipeline, model, etc.) |
| llm | None | No | LLM provider for stages that need one |
| default_max_workers | int | No | Thread pool size for Map stages (default 4) |
Outputs
| Name | Type | Description |
|---|---|---|
| run() returns | RunState | Updated run state with final status (completed/interrupted/failed) |
| run.json | File | Run metadata persisted to work_dir |
| run_manifest.json | File | Per-sample summary manifest |
| samples/<id>/state.json | Files | Per-sample state with stage history |
Usage Examples
Full Pipeline Run
from pathlib import Path
from deepzero.engine.pipeline import load_pipeline
from deepzero.engine.runner import PipelineRunner
from deepzero.engine.state import RunState, StateStore
# 1. Load and resolve the pipeline
pipeline = load_pipeline("demo")
pipeline.bind_corpus(Path("./sample_files"))
# 2. Create state store and run state
store = StateStore(pipeline.work_dir)
run_state = RunState(
run_id="run-001",
pipeline=pipeline.name,
target=str(Path("./sample_files")),
model=pipeline.model,
)
# 3. Build and run the pipeline
runner = PipelineRunner(
ingest=pipeline.ingest_processor,
stages=pipeline.stages,
state_store=store,
pipeline_dir=pipeline.pipeline_dir,
global_config=pipeline.to_global_config(),
)
result = runner.run(Path("./sample_files"), run_state)
print(f"Run status: {result.status}")
Resume After Interruption
# Re-running the same command resumes automatically.
# The runner detects existing state on disk and skips completed stages.
runner.run(Path("./sample_files"), run_state)