spdl.pipeline.defs.PlacementConfig

class PlacementConfig(target: ProcessPoolExecutorConfig | InterpreterPoolExecutorConfig | _MainProcess, name: str = 'placement', buffer_size: int = 1, arena: object | None = None, background_tasks: Sequence[Callable[[], Any]] = ())[source]

[Experimental] A region marker designating where the subsequent stages execute.

Sits among the stage configs in PipelineConfig.pipes: every stage after this marker (until the next PlacementConfig) runs on target. spdl.pipeline.PipelineBuilder.to() appends one of these. A pipeline implicitly starts on the main process, so a marker is needed only to enter a worker-pool region and (with MAIN_PROCESS) to leave it.

Added in version 0.6.0.

Attributes

arena

Borrow a caller-owned arena object or one independent object per worker.

background_tasks

Factories of BackgroundTask objects run in each worker of the region this marker opens.

buffer_size

At most this many items are buffered into one transfer at this marker.

name

Name of the marker (used only for display).

target

Where the stages following this marker execute.

arena: object | None = None

Borrow a caller-owned arena object or one independent object per worker.

A sequence is snapshotted to an immutable tuple. Custom storage endpoints conform to ArenaProtocol structurally; callers provide concrete arena objects, not protocol inheritance or payload lifetime anchors. One object requires one worker; a pool with N workers requires N independent objects. A single SPSC allocation must not serve two directions or concurrently active regions.

The pipeline never closes or unlinks these objects. After successful stop, callers may reuse them, then close/unlink in their own finally block. Early cancellation may invalidate an arena. Stopping waits for every arena call already in progress to complete; the region never abandons such a call on a deadline. Builtin capacity waits use their configured acquire_timeout. A custom backend that can wait without bound must return or raise once the caller calls its close, which the caller does before stopping a pipeline blocked on it.

Added in version 0.9.0.

background_tasks: Sequence[Callable[[], Any]] = ()

Factories of BackgroundTask objects run in each worker of the region this marker opens.

They are added to the background tasks of the nested pipeline that runs the region’s stages in each worker, so they run on the worker’s event loop for as long as that pipeline runs: the worker’s lifetime with a continuous source; otherwise they restart at every input stream boundary. Errors are logged and do not fail the region. Only a marker that opens a worker-pool region accepts them. The sequence is snapshotted to a tuple. With the "spawn" and "forkserver" start methods, and for subinterpreter regions, the factories must be picklable.

Added in version 0.9.0.

buffer_size: int = 1

At most this many items are buffered into one transfer at this marker.

Crossing a process boundary costs a fixed amount per transfer — the pickle and unpickle calls, the queue feeder-thread handoff and the pipe write — no matter how small the item is. 1 (the default) passes one item at a time; a larger value amortizes that over several items. Per-item costs are unaffected: a tensor still needs its own shared-memory segment whether or not it shares a transfer.

Each marker sizes the handoff that happens where it sits, so a region’s entry and exit are configured independently: the marker that opens a region sizes data flowing into its workers, and the marker that closes it sizes results flowing back. That separation matters because the two directions rarely carry comparable items — a region ending in Aggregate() takes single rows in and returns whole batches.

It is an upper bound rather than a fixed grouping: a partial buffer is flushed at the end of a stream and at every epoch boundary, so the last transfer is usually short.

The buffering is transparent — stages on both sides still see individual items, so this is independent of any Aggregate() inside or outside the region.

Added in version 0.7.0.

name: str = 'placement'

Name of the marker (used only for display).

target: ProcessPoolExecutorConfig | InterpreterPoolExecutorConfig | _MainProcess

Where the stages following this marker execute.