Skip to content

vllm_omni.config.composable_parallel

Composable parallel strategies for vLLM-Omni.

A small, runtime-agnostic vocabulary for declaring a stage's parallel layout (:class:StrategySpec + mesh/routing/aggregation patterns), plus the logic to translate a per-role stack of specs into concrete engine sizing and overlay it onto merged stage configs.

The spec/pattern types are deliberately pure data with no engine imports; the translation and apply logic lives alongside them and consumes vLLM-Omni's own config objects.

Modules:

Name Description
aggregation

Closed aggregation-pattern hierarchy for declarative parallel strategies.

apply

Apply declarative parallel strategies onto merged stage configs.

routing

Closed routing-pattern hierarchy for declarative parallel strategies.

spec

Core declarative types for parallel-strategy specification.

strategy_loader

Load per-role parallel strategies from a strategy file.

translator

Translate a StrategySpec stack into vLLM-Omni parallel sizing.

AGGREGATION_PATTERN_VARIANTS module-attribute

MESH_AXIS_KINDS module-attribute

MESH_AXIS_KINDS: tuple[str, ...] = tuple(
    (k.value) for k in MeshAxisKind
)

ROUTING_PATTERN_VARIANTS module-attribute

AggregationConflictError

Bases: ValueError

Raised when two aggregation inputs conflict for the same request id.

AggregationPattern dataclass

Base class for closed aggregation patterns. Subclass only within this module.

pattern_kind

pattern_kind() -> str

AllGather dataclass

Bases: AggregationPattern

All ranks materialize the same aggregate result across the axis.

dim class-attribute instance-attribute

dim: int | None = None

pattern_kind

pattern_kind() -> str

AxisTranslationError

Bases: ValueError

Error for an invalid or unsupported strategy spec.

A single error type (rather than a tree of subclasses) keeps the public surface small and consistent with the rest of the codebase; the specific cause is in the message and is logged before the raise so it is visible even when the type is unavailable to a caller (e.g. across a server boundary).

Strategies that are valid but not built yet — key-stable / affinity routing today — raise NotImplementedError instead, to distinguish "we haven't implemented this" from "your config is wrong".

Broadcast dataclass

Bases: RoutingPattern

Every worker in the group sees the whole batch (TP, dense EP).

pattern_kind

pattern_kind() -> str

Combine dataclass

Bases: AggregationPattern

Custom reducer combination (CFG). Adapter resolves reducer_id.

reducer_id class-attribute instance-attribute

reducer_id: str = 'default'

pattern_kind

pattern_kind() -> str

DuplicateWithCondTag dataclass

Bases: RoutingPattern

Duplicate batch with a conditional tag (CFG).

flag_name class-attribute instance-attribute

flag_name: str = 'guidance_branch'

pattern_kind

pattern_kind() -> str

FanInByStage dataclass

Bases: AggregationPattern

Fan-in results routed by stage (stage replicas).

pattern_kind

pattern_kind() -> str

GatherDim dataclass

Bases: AggregationPattern

Gather along a dimension and materialize on one designated rank.

Default designated rank is axis-rank 0 unless adapter overrides.

dim class-attribute instance-attribute

dim: int = 1

pattern_kind

pattern_kind() -> str

KernelSpec dataclass

L3 kernel slot referenced by StrategySpec; resolved by the kernel registry.

axis_index class-attribute instance-attribute

axis_index: int = 0

category class-attribute instance-attribute

category: HookCategory = 'other'

group_axis_kind class-attribute instance-attribute

group_axis_kind: MeshAxisKind | None = None

kernel_id instance-attribute

kernel_id: str

priority class-attribute instance-attribute

priority: int = 0

requires_collective class-attribute instance-attribute

requires_collective: bool = False

target class-attribute instance-attribute

target: str | None = None

LayerHookSpec dataclass

L2 hook slot referenced by StrategySpec; resolved by the model walker.

axis_index class-attribute instance-attribute

axis_index: int = 0

category class-attribute instance-attribute

category: HookCategory = 'other'

hook_id instance-attribute

hook_id: str

priority class-attribute instance-attribute

priority: int = 0

target class-attribute instance-attribute

target: str | None = None

MeshAxisKind

Bases: str, Enum

Enumerates every parallelism dimension the strategy contract can describe.

Subclassing str keeps existing string comparisons and dict keys working (MeshAxisKind.TP == "tp" and both hash the same), while making the type refactor-safe: a typo'd kind is an AttributeError on the enum rather than a silently-wrong bare string.

CFG class-attribute instance-attribute

CFG = 'cfg'

CP class-attribute instance-attribute

CP = 'cp'

DP class-attribute instance-attribute

DP = 'dp'

EP class-attribute instance-attribute

EP = 'ep'

HSDP class-attribute instance-attribute

HSDP = 'hsdp'

PP class-attribute instance-attribute

PP = 'pp'

SP_RING class-attribute instance-attribute

SP_RING = 'sp_ring'

SP_ULYSSES class-attribute instance-attribute

SP_ULYSSES = 'sp_ulysses'

STAGE_PP class-attribute instance-attribute

STAGE_PP = 'stage_pp'

STAGE_REPLICA class-attribute instance-attribute

STAGE_REPLICA = 'stage_replica'

TP class-attribute instance-attribute

TP = 'tp'

VAE_PP class-attribute instance-attribute

VAE_PP = 'vae_pp'

MeshAxisSpec dataclass

Declares one axis of a process mesh (kind + size).

kind instance-attribute

size instance-attribute

size: int

OmniParallelConfig dataclass

Result of translating a spec stack into omni parallel sizing.

data_parallel_size class-attribute instance-attribute

data_parallel_size: int = 1

delegated_axes property

delegated_axes: tuple[MeshAxisKind, ...]

enable_expert_parallel class-attribute instance-attribute

enable_expert_parallel: bool = False

l1_owners class-attribute instance-attribute

l1_owners: Mapping[MeshAxisKind, L1Owner] = field(
    default_factory=dict
)

omni_lb_policy class-attribute instance-attribute

omni_lb_policy: str | None = None

pipeline_parallel_size class-attribute instance-attribute

pipeline_parallel_size: int = 1

stage_replica_size class-attribute instance-attribute

stage_replica_size: int = 1

tensor_parallel_size class-attribute instance-attribute

tensor_parallel_size: int = 1

world_size property

world_size: int

as_engine_kwargs

as_engine_kwargs() -> dict[str, object]

Return per-stage kwargs keyed by real OmniEngineArgs/EngineArgs field names.

Two derived values are intentionally not emitted here because they are not per-stage engine args:

  • stage_replica_size — a per-stage deploy num_replicas knob (StageDeployConfig); the deploy layer consumes it separately.
  • omni_lb_policy — a pipeline-wide load-balancer policy the engine reads once at construction (see StrategyApplyResult.omni_lb_policy); it is applied at the orchestrator level, not folded into per-stage args.

PartitionByHash dataclass

Bases: RoutingPattern

Stable hash partition by request key (DP, HSDP).

key class-attribute instance-attribute

key: str = 'request_id'

pattern_kind

pattern_kind() -> str

PipelineMicrobatch dataclass

Bases: RoutingPattern

Pipeline parallelism microbatch routing (PP).

microbatch_size class-attribute instance-attribute

microbatch_size: int = 1

pattern_kind

pattern_kind() -> str

RouteByExpert dataclass

Bases: RoutingPattern

Sparse MoE expert routing.

router_id class-attribute instance-attribute

router_id: str = 'default'

pattern_kind

pattern_kind() -> str

RouteByStage dataclass

Bases: RoutingPattern

Route requests by pipeline stage policy (stage replicas).

The random/round_robin/least_queue policies describe stateless load balancing that a runtime (e.g. an engine's built-in DP load balancer, or the omni StagePool balancer) can realize. hash describes deterministic, key-stable routing that a load balancer cannot honor on its own (see PartitionByHash).

routing_policy class-attribute instance-attribute

routing_policy: Literal[
    "random", "round_robin", "least_queue", "hash"
] = "round_robin"

pattern_kind

pattern_kind() -> str

RoutingKeyError

Bases: KeyError

Raised when a routing key is missing from a request.

missing_key instance-attribute

missing_key = missing_key

request_id instance-attribute

request_id = request_id

RoutingPattern dataclass

Base class for closed routing patterns. Subclass only within this module.

pattern_kind

pattern_kind() -> str

ShardSequence dataclass

Bases: RoutingPattern

Shard along a sequence dimension (SP-Ulysses, SP-Ring, CP).

dim class-attribute instance-attribute

dim: int = 1

pattern_kind

pattern_kind() -> str

ShardSpatial dataclass

Bases: RoutingPattern

Shard along a spatial grid (VAE-PP).

grid class-attribute instance-attribute

grid: tuple[int, int] = (1, 1)

pattern_kind

pattern_kind() -> str

SpecMergeConflictError

Bases: ValueError

Raised when merged hook/kernel specs have conflicting declarations.

StitchPipeline dataclass

Bases: AggregationPattern

Stitch pipeline stage outputs (PP).

pattern_kind

pattern_kind() -> str

StitchSpatial dataclass

Bases: AggregationPattern

Stitch spatial patches (VAE-PP).

grid class-attribute instance-attribute

grid: tuple[int, int] = (1, 1)

pattern_kind

pattern_kind() -> str

StrategyApplyError

Bases: ValueError

Error for applying a strategy onto stage configs.

A single error type (rather than per-cause subclasses) keeps the public surface small and consistent with the rest of the codebase; the specific cause — an unmatched role, a conflict with an explicit deploy value, or a device-count mismatch — is in the message and is logged before the raise so it stays visible even when the type is unavailable to a caller (e.g. across a server boundary).

StrategyApplyResult dataclass

Outcome of applying strategies to a stage list.

stages is the same list passed in (mutated in place and returned for convenience). omni_lb_policy is the pipeline-wide load-balancer policy derived from any stage_replica axes (None if none declared one); the caller wires it into the orchestrator, since omni does not read it from stage configs.

per_role_config is keyed by the role key the caller supplied — a model_stage name (str). per_stage_config is the same information keyed by the resolved integer stage_id — handy for re-validating a stage after later layers (e.g. CLI overrides) have run.

omni_lb_policy class-attribute instance-attribute

omni_lb_policy: str | None = None

per_role_config class-attribute instance-attribute

per_role_config: dict[RoleKey, OmniParallelConfig] = field(
    default_factory=dict
)

per_stage_config class-attribute instance-attribute

per_stage_config: dict[int, OmniParallelConfig] = field(
    default_factory=dict
)

stages instance-attribute

stages: list[Any]

StrategySpec dataclass

Declarative contract for one parallelism scheme (data + hook/kernel slots).

aggregation instance-attribute

aggregation: AggregationPattern

kernel_specs class-attribute instance-attribute

kernel_specs: tuple[KernelSpec, ...] = ()

layer_hook_specs class-attribute instance-attribute

layer_hook_specs: tuple[LayerHookSpec, ...] = ()

mesh_axis instance-attribute

mesh_axis: MeshAxisSpec

name instance-attribute

name: str

routing instance-attribute

routing: RoutingPattern

shard_extension class-attribute instance-attribute

shard_extension: Mapping[str, Any] = field(
    default_factory=dict
)

TakeRank dataclass

Bases: AggregationPattern

Select one rank's result (TP — all ranks agree).

rank class-attribute instance-attribute

rank: int = 0

pattern_kind

pattern_kind() -> str

Union dataclass

Bases: AggregationPattern

Union of disjoint replica results (DP, HSDP).

pattern_kind

pattern_kind() -> str

apply_strategy_specs

apply_strategy_specs(
    stages: list[Any],
    strategy_specs: Mapping[
        RoleKey, Sequence[StrategySpec]
    ],
) -> StrategyApplyResult

Overlay per-role strategy specs onto a merged stage list.

Parameters:

Name Type Description Default
stages list[Any]

the list[StageConfig] returned by merge_pipeline_deploy.

required
strategy_specs Mapping[RoleKey, Sequence[StrategySpec]]

maps a role (a model_stage name, e.g. "thinker") to that stage's stack of StrategySpec (one per declared mesh axis). Role keys are model_stage names (str).

required

Returns:

Name Type Description
A StrategyApplyResult

class:StrategyApplyResult with the mutated stages and the derived

StrategyApplyResult

pipeline-wide omni_lb_policy (if any stage_replica axis set one).

Raises:

Type Description
StrategyApplyError

a role matched zero or multiple stages, a derived value conflicts with an explicit deploy value (including two roles deriving different omni_lb_policy values), or a stage's device count is inconsistent with its world size.

AxisTranslationError

the spec stack is invalid/unsupported.

NotImplementedError

the spec stack requests routing not built yet.

check_device_layout

check_device_layout(
    devices: Any,
    *,
    tensor_parallel_size: int,
    data_parallel_size: int,
    pipeline_parallel_size: int,
    num_replicas: int,
    role: RoleKey,
) -> None

Validate a stage's device count against its world size (× replicas in pool mode).

Raises :class:StrategyApplyError when the declared devices count is neither the per-replica world size nor the full num_replicas pool. Exposed publicly so the resolved (post-CLI) layout can be re-checked after later override layers, not just the strategy-derived snapshot.

translate_strategy_stack

translate_strategy_stack(
    specs: Sequence[StrategySpec],
) -> OmniParallelConfig

Translate a spec stack into an OmniParallelConfig.

Supported kinds: dp (engine data parallel), tp, pp, (dense) ep, and stage_replica (omni replicas). Raises NotImplementedError for deferred (affinity / key-stable) routing, and :class:AxisTranslationError for any other invalid spec (a kind not yet translatable, a repeated kind, an owner incompatible with the axis kind, or unsupported routing). The EP degree must equal tensor_parallel_size * data_parallel_size.