Modules to be parallelized with pipeline parallelism. The key constraint that enables pipeline parallelism is the representation of the forward pass as a sequence of layers and the enforcement of a simple interface between them. The forward pass is implicitly defined by the module `
| 84 | |
| 85 | |
| 86 | class PipelineModule(nn.Module): |
| 87 | """Modules to be parallelized with pipeline parallelism. |
| 88 | |
| 89 | The key constraint that enables pipeline parallelism is the |
| 90 | representation of the forward pass as a sequence of layers |
| 91 | and the enforcement of a simple interface between them. The |
| 92 | forward pass is implicitly defined by the module ``layers``. The key |
| 93 | assumption is that the output of each layer can be directly fed as |
| 94 | input to the next, like a ``torch.nn.Sequence``. The forward pass is |
| 95 | implicitly: |
| 96 | |
| 97 | .. code-block:: python |
| 98 | |
| 99 | def forward(self, inputs): |
| 100 | x = inputs |
| 101 | for layer in self.layers: |
| 102 | x = layer(x) |
| 103 | return x |
| 104 | |
| 105 | .. note:: |
| 106 | Pipeline parallelism is not compatible with ZeRO-2 and ZeRO-3. |
| 107 | |
| 108 | Args: |
| 109 | layers (Iterable): A sequence of layers defining pipeline structure. Can be a ``torch.nn.Sequential`` module. |
| 110 | num_stages (int, optional): The degree of pipeline parallelism. If not specified, ``topology`` must be provided. |
| 111 | topology (``deepspeed.runtime.pipe.ProcessTopology``, optional): Defines the axes of parallelism axes for training. Must be provided if ``num_stages`` is ``None``. |
| 112 | loss_fn (callable, optional): Loss is computed ``loss = loss_fn(outputs, label)`` |
| 113 | seed_layers(bool, optional): Use a different seed for each layer. Defaults to False. |
| 114 | seed_fn(type, optional): The custom seed generating function. Defaults to random seed generator. |
| 115 | base_seed (int, optional): The starting seed. Defaults to 1234. |
| 116 | partition_method (str, optional): The method upon which the layers are partitioned. Defaults to 'parameters'. |
| 117 | activation_checkpoint_interval (int, optional): The granularity activation checkpointing in terms of number of layers. 0 disables activation checkpointing. |
| 118 | activation_checkpoint_func (callable, optional): The function to use for activation checkpointing. Defaults to ``deepspeed.checkpointing.checkpoint``. |
| 119 | checkpointable_layers (list[str], optional): List of layer class names that are eligible for checkpointing. For GPT models, |
| 120 | ParallelTransformerLayerPipe is always checkpointed regardless of this list. If None, all layers with parameters are |
| 121 | considered checkpointable. Defaults to None. |
| 122 | dynamic_shape: Allows dynamic shapes of inputs. This might have a performance impact. |
| 123 | """ |
| 124 | |
| 125 | def __init__(self, |
| 126 | layers, |
| 127 | num_stages=None, |
| 128 | topology=None, |
| 129 | loss_fn=None, |
| 130 | seed_layers=False, |
| 131 | seed_fn=None, |
| 132 | base_seed=1234, |
| 133 | partition_method='parameters', |
| 134 | activation_checkpoint_interval=0, |
| 135 | activation_checkpoint_func=checkpointing.checkpoint, |
| 136 | checkpointable_layers=None, |
| 137 | dynamic_shape=False): |
| 138 | |
| 139 | super().__init__() |
| 140 | |
| 141 | if num_stages is None and topology is None: |
| 142 | raise RuntimeError('must provide num_stages or topology') |
| 143 |
no outgoing calls