Skip to navigation

nemo_automodel.components.distributed.pipelining

View as MarkdownOpen in Claude

Submodules

Package Contents

Classes

NameDescription
AutoPipelineOrchestrates pipeline-parallel training on top of torch.distributed.pipelining.

API

class nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline(
world_mesh: torch.distributed.device_mesh.DeviceMesh | None = None,
moe_mesh: torch.distributed.device_mesh.DeviceMesh | None = None,
pp_axis_name: str = 'pp',
dp_axis_names: tuple[str, ...] = ('dp',),
cp_axis_name: str | None = None,
tp_axis_name: str | None = None,
ep_axis_name: str | None = None,
ep_shard_axis_names: tuple[str, ...] | None = None,
pp_schedule: str | None = '1f1b',
pp_schedule_csv: str | None = None,
pp_microbatch_size: int = 1,
pp_batch_size: int = 1,
layers_per_stage: int | None = None,
round_virtual_stages_to_pp_multiple: typing.Literal['up', 'down'] | None = None,
module_fqns_per_model_part: list[list[str]] | None = None,
patch_inner_model: bool = True,
patch_causal_lm_model: bool = True,
patch_stage_backward_maybe_with_nosync: bool = False,
defer_fsdp_grad_sync: bool = True,
device: torch.device | None = None,
dtype: torch.dtype | None = None,
scale_grads_in_schedule: bool = False,
pp_seq_len: int | None = None,
pp_recv_buffer_pool: bool = False,
pp_recv_buffer_pool_slack: int = 2
)

Orchestrates pipeline-parallel training on top of torch.distributed.pipelining.

_device
device
_info
_pp_current_seq_len
int | None = None
_pp_runtime_num_tokens
int = 0
_runtime_initializers
list[PipelineRuntimeInitializer] = []
device
device
info
PipelineInfo
parts
list[Module]
pp_mesh
DeviceMesh = self.world_mesh[pp_axis_name]
nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline._count_parameters(
module: torch.nn.Module,
trainable_only: bool = False
) -> int
staticmethod
nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline._get_schedule_kwargs_chunk_spec(
kwargs: dict[str, typing.Any]
) -> dict[str, typing.Any] | None

Build pipeline microbatch chunking metadata for keyword inputs.

PyTorch’s default schedule chunking splits every tensor kwarg on dim 0. Most AutoModel batch tensors are batch-major and should keep that default, but some model-owned input layouts place batch on another axis. The canonical local model part can declare those exceptions by implementing get_pipeline_kwargs_chunk_dims(kwargs) -> dict[str, int].

Parameters:

kwargs
dict[str, Any]

Mapping passed to the pipeline schedule. Tensor values may have arbitrary model-defined layouts; the model hook identifies any nonstandard batch axis.

Returns: dict[str, Any] | None

A chunk-spec mapping with the same nested structure as kwargs,

nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline.build(
model: torch.nn.Module,
loss_fn: typing.Callable | None = None,
)

Build the pipeline: validate -> init meta -> split -> schedule.

nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline.debug_summary() -> str
nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline.get_stage_param_counts(
trainable_only: bool = False
) -> list[int]
nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline.get_total_param_count(
trainable_only: bool = False
) -> int
nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline.list_stage_modules() -> list[list[str]]
nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline.log_debug_summary() -> None
nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline.pretty_print_stages(
max_modules_per_stage: int = 16,
trainable_only: bool = False
) -> str
nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline.step(
model_input: torch.Tensor,
target: torch.Tensor | None = None,
losses: list[torch.Tensor] | None = None,
return_outputs: bool = False,
kwargs: typing.Any = {}
) -> typing.Any

Run one pipeline schedule step with model-owned input chunking.

Parameters:

model_input
torch.Tensor

Tensor of shape [batch, …] containing the first pipeline stage’s input. Ignored on ranks without the first stage.

target
torch.Tensor | NoneDefaults to None

Tensor with a model-defined target layout, or None on ranks without the last pipeline stage.

losses
list[torch.Tensor] | NoneDefaults to None

Mutable list populated with scalar loss tensors, or None on ranks without the last pipeline stage.

return_outputs
boolDefaults to False

Whether the last stage keeps every microbatch’s output and returns them merged. This costs two copies of the last stage’s output for the whole local batch, so pass True only when the caller reads it.

**kwargs
AnyDefaults to {}

Keyword schedule inputs. Tensor values may have arbitrary model-defined layouts; model-owned metadata identifies any nonstandard batch axis.

Returns: Any

The last stage’s output for the whole local batch, merged along the

nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline.update_seq_len(
seq_len: int
) -> None

Reset pipeline stage infrastructure for a new sequence length.

VLM training batches can have wildly different sequence lengths across steps (image batches vs. text-only batches). PyTorch’s PipelineStage locks in recv buffer sizes on the first step, causing a shape-mismatch error on later steps with different seq_lens.

Call this before every schedule.step() to update the stage shapes without running an expensive forward pass. Stage reset is a no-op when seq_len has not changed; model-owned runtime initializers are still prepared.

Parameters:

seq_len
int

Sequence length of the upcoming batch (input_ids.shape[1]).

nemo_automodel.components.distributed.pipelining.autopipeline.AutoPipeline.visualize_current_schedule(
filename: str | None = None
) -> None