Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Deepspeedai DeepSpeed Pipeline Module Construction

From Leeroopedia


Overview

Partitioning a sequential model across pipeline stages by assigning layer subsets to each GPU based on parameter count, uniform distribution, or layer type matching.

Detailed Description

Pipeline module construction takes a sequential list of layers and distributes them across pipeline stages (GPUs). The partitioning algorithm balances compute and memory across stages. The module also establishes the communication topology (PipelineParallelGrid) for inter-stage data transfer.

Partitioning Strategies

Method Description Use Case
'parameters' Balance by total trainable parameter count per stage Default; works well when parameter count correlates with compute
'uniform' Equal number of layers per stage When layers have similar compute cost
'type:regex' Partition by layer type matching a regex pattern When specific layer types (e.g., transformer blocks) dominate compute
'profile' Runtime profiling of layer execution time Not yet implemented; intended for heterogeneous layer architectures

Construction Process

The pipeline module construction follows these steps:

  1. Topology creation: A PipeDataParallelTopology is created based on the number of pipeline stages and data parallel degree, or a custom topology is accepted.
  2. Communication grid: A PipelineParallelGrid is established from the topology, defining point-to-point communication groups between adjacent stages and allreduce groups for data parallelism.
  3. Layer partitioning: The layer list is partitioned using the chosen method, producing a parts array that maps stage IDs to layer index ranges.
  4. Local layer building: Only the layers assigned to the local stage are built (instantiated from LayerSpec or registered as modules). Layers outside the local range are never constructed.
  5. Tied weight indexing: Communication groups are created for any TiedLayerSpec entries that span multiple stages, enabling gradient synchronization for shared weights.

Forward Pass Semantics

The forward pass through a PipelineModule is implicitly sequential:

def forward(self, inputs):
    x = inputs
    for layer in self.forward_funcs:
        x = layer(x)
    return x

This sequential constraint is fundamental — each layer's output must be directly consumable as the next layer's input. This enables the clean partitioning where inter-stage communication only occurs at partition boundaries.

Activation Checkpointing

The module supports activation checkpointing at configurable intervals. When activation_checkpoint_interval > 0, groups of consecutive layers are wrapped with checkpointing to trade compute for memory. The _is_checkpointable() method determines whether a group of layers is eligible for checkpointing based on whether they contain trainable parameters.

Theoretical Basis

Pipeline parallelism partitions model layers L_1...L_n into S stages. The 1F1B (one forward, one backward) schedule overlaps computation across stages to minimize pipeline bubble. Optimal partitioning minimizes the maximum stage computation time (the bottleneck).

Partitioning Optimality

For a model with layers having computation costs c_1, c_2, ..., c_n distributed across S stages, the optimal partition minimizes:

max over all stages s of sum(c_i for i in stage s)

The parameters method approximates computation cost by parameter count. The uniform method assumes equal cost per layer. The type:regex method uses binary weights to ensure equal distribution of specific layer types (e.g., transformer blocks).

Pipeline Bubble

With S stages and M micro-batches, the pipeline bubble ratio is:

(S - 1) / (M + S - 1)

This means that increasing the number of micro-batches M (via gradient accumulation) relative to the number of stages S reduces wasted compute.

References

Related Pages

Knowledge Sources

Last updated: 2026-02-09 00:00 GMT

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment