Runtime and tuning¶
How a pipeline executes, what it reports while running, and what it checks before it starts. The guide covers these in Inspecting and Tuning Pipelines and Distributed Training.
Runtime options¶
Runtime options for Pipeline.options() (RuntimeOptions, IpcTransport).
- class RuntimeOptions(runner=None, run_id='default_run_id', per_stage_runner=<factory>, mp_context=<multiprocessing.context.SpawnContext object>, worker_allocation='fit_to_ops', max_workers=None, deterministic=True, prefetch_batches=None, default_stage_prefetch=None, per_stage_prefetch=<factory>, op_queue_capacity=None, ipc_transport='socketpair', ipc_buffer_bytes=524288, mixture_config=None, io_options=<factory>, allow_latency_flush_in_deterministic=True, flush_every_k_chunks=None, shutdown_mode='graceful', auto_validation='strict', mtp_mode=False, mtp_buffer=None, mtp_buffer_bytes=8388608, mtp_prefetch=None, mtp_auto_checkpoint=True, world_size=1, global_rank=0, dp_degree=None, dp_group_id=None, canonical_replicas=None, mapping_strategy=None, shm_enabled=True, shm_coalesce=True, shm_min_item_bytes=4096, shm_min_new_allocation_bytes=1048576, shm_min_forward_bytes=131072, shm_compact_above_ratio=8.0, shm_compact_min_savings_bytes=16777216, shm_max_coalesced_bytes=67108864, max_worker_retries=3, aggregate_dir=None, aggregate_timeout_s=180.0, aggregate_serializer='msgpack', aggregate_compressor='zstd', execution_tracking=ExecutionTrackingMode.OFF, metrics_sink_config=None)[source]¶
Bases:
objectUser-tunable knobs that influence how the engine constructs runners.
Numeric tuning knobs default to
None, resulting in sensible defaults viaresolve_*helpers that form a dependency cascade. Each resolver calls the ones above it when its own field is unset:max_workers ← os.cpu_count(), clamped [4, 16] └── prefetch_batches = max(8, 2 × max_workers) ├── op_queue_capacity = max(8, prefetch_batches) ├── mtp_buffer = max(4, prefetch_batches // 2) │ └── mtp_prefetch = max(4, mtp_buffer // 10) └── default_stage_prefetch = max(4, prefetch_batches // 4) [process] max(8, prefetch_batches // 2) [threads/inline]For example,
max_workers=24naturally bumps the prefetch / queue / MTP buffers without the user having to set them too, whileprefetch_batches=64overrides the tail buffer alone and lets the rest auto-derive from it.By default,
max_workersis derived from the host’s CPU count, but is clamped to a range of[4, 16]. For any large deployment this will hit the upper limit, but the clamp allows Zephon to run reasonably on small machines as well.- mixture_config: MixtureReadConfig | None = None¶
- io_options: StoreOptions¶
- execution_tracking: ExecutionTrackingMode = 'off'¶
- metrics_sink_config: MetricsSinkConfig | None = None¶
- IpcTransport: Literal['socketpair', 'pipe']¶
Transport for the process runner’s and MTP’s IPC queues.
Observability¶
Observability configuration and helpers used across Zephon.
- class ExecutionTrackingMode(*values)[source]¶
-
Controls how much execution detail is collected.
- OFF = 'off'¶
- STAGES = 'stages'¶
- NODES = 'nodes'¶
- class FetchStageSummary(index, totals=<factory>, shard_totals=<factory>)[source]¶
Bases:
objectStage fetch timings keyed by
(dataset_id, shard_id).- totals: FetchTimingTotals¶
- shard_totals: MutableMapping[tuple[int, int], FetchTimingTotals]¶
- class FetchTimingDelta(stage_index, dataset_id, shard_id, samples, group_ns, resolve_ns, open_ns, read_ns, close_ns, retries, cache_hits, cache_misses, shard_reopens=0)[source]¶
Bases:
objectIncremental fetch metrics emitted per shard group.
- class FetchTimingSummary(plan_id=None, reporting_interval_s=None, tracking_mode=ExecutionTrackingMode.OFF, stages=<factory>)[source]¶
Bases:
objectAggregated fetch metrics for an entire pipeline.
- tracking_mode: ExecutionTrackingMode = 'off'¶
- stages: MutableMapping[int, FetchStageSummary]¶
- class FetchTimingTotals(samples=0, groups=0, group_ns=0, resolve_ns=0, open_ns=0, read_ns=0, close_ns=0, retries=0, cache_hits=0, cache_misses=0, shard_reopens=0)[source]¶
Bases:
objectAggregated timing totals accumulated across deltas.
- class MTPQueueStats(depth, capacity, staged_bytes, prefetch_depth)[source]¶
Bases:
objectPoint-in-time occupancy of the MTP hand-off queue (
data_q).depthcounts queued items, which may not have been pickled yet;staged_bytesis the already-pickled data in the kernel transport buffer, readable without the feeder running. Zero staged withdepthnearcapacitymeans the feeder is starved.prefetch_depthcounts items already drained into the main-process prefetch buffer; it is sampled without locking and may be slightly stale.A field is -1 when unmeasurable:
depthon macOS (sem_getvalueis unsupported there),staged_bytesonce the queue is closed.
- class MetricsSinkConfig(mode=MetricsSinkMode.LOG, namespace='zephon.pipeline', statsd_host='127.0.0.1', statsd_port=8125, default_tags=<factory>, json_logs=True, max_batch_size=32, flush_interval_s=5.0)[source]¶
Bases:
objectDescribe how observability data is exported.
- mode: MetricsSinkMode = 'log'¶
- class MetricsSinkMode(*values)[source]¶
-
Where metrics should be emitted.
- LOG = 'log'¶
- STATSD = 'statsd'¶
- BOTH = 'both'¶
- class PipelineSummary(plan_id=None, reporting_interval_s=None, tracking_mode=ExecutionTrackingMode.OFF, stages=<factory>, total_wait_ratio=None)[source]¶
Bases:
objectAggregated metrics for an entire pipeline invocation.
- tracking_mode: ExecutionTrackingMode = 'off'¶
- stages: MutableMapping[int, StageSummary]¶
- class PrefetchTimingDelta(stage_index, batch_size, prefetch_requests, prefetch_succeeded, prefetch_failed)[source]¶
Bases:
objectIncremental prefetch metrics emitted per batch.
- class PrefetchTimingSummary(plan_id=None, reporting_interval_s=None, tracking_mode=ExecutionTrackingMode.OFF, stages=<factory>)[source]¶
Bases:
objectAggregated prefetch metrics for an entire pipeline.
- tracking_mode: ExecutionTrackingMode = 'off'¶
- stages: MutableMapping[int, PrefetchTimingTotals]¶
Validation¶
Validation harness for user-supplied operators and accumulators.
The framework guarantees deterministic parallel execution only when the
callables passed to Pipeline.add_op honor several contracts that the
type system cannot enforce: process_many must be stateless across
calls, the accumulator must drain on flush() and reset on
flush(reset=True), and so on. This module runs a synthetic-sample
smoke test that catches the most common violations before the engine
starts. See the “Accumulators and Operators” page in the published
documentation for the contracts being checked.
The harness is intentionally a smoke test, not a proof: it cannot catch violations that only surface after many iterations or under specific data shapes. Errors here are real bugs; passing this harness is necessary but not sufficient for correctness.
Unlike the rest of zephon (custom exception subclasses + warnings.warn),
this module aggregates findings into a ValidationReport of
string-coded Issue records. Aggregation lets the user see every
problem in their op at once; the tradeoff is identification by string
equality on issue.code rather than by isinstance.
- class Issue(severity, code, op_name, message, doc_link='https://datologyai.github.io/zephon/understanding/accumulators_operators.html')[source]¶
Bases:
objectA single validation finding.
- exception ValidationError(report)[source]¶
Bases:
RuntimeErrorRaised when a strict-mode validation entry point finds at least one error.
Raisers:
Pipeline.validate(strict=True), strict auto-validation, andPipeline.preflight_tokenizers(strict=True).
- class ValidationReport(issues=<factory>)[source]¶
Bases:
objectResult of running the validation harness against a pipeline.
- preflight_tokenizers(pipeline)[source]¶
Return tokenizer initialization failures for a pipeline.
Each tokenizer operator is deep-copied before its lazy initialization runs, leaving pipeline-owned operators unchanged. This may download tokenizer files.
- Parameters:
pipeline (Pipeline) – Pipeline to inspect.
- Returns:
A
ValidationReportcontaining oneTOKENIZER_PREFLIGHT_FAILEDerror per failure.- Return type:
Debugging¶
Diagnostics for a run that leaks or hangs on shutdown.