Skip to navigation
ReferenceFull Library ReferenceNemo AutomodelNemo AutomodelComponentsModelsErgonemo_automodel.components.models.ergo.context_parallel

nemo_automodel.components.models.ergo.context_parallel

View as MarkdownOpen in Claude

Ergo document-preserving batch preparation over the shared CP sharder.

Module Contents

Functions

NameDescription
shard_batchKeep IDs global for embedding, and shard auxiliaries in contiguous order.
shard_te_batchKeep packed stage-zero IDs global while TE owns the token partition.

API

nemo_automodel.components.models.ergo.context_parallel.shard_batch(
cp_mesh: torch.distributed.device_mesh.DeviceMesh,
tp_mesh: torch.distributed.device_mesh.DeviceMesh | None,
batch: dict[str, torch.Tensor | str],
loss_mask: torch.Tensor | None = None,
padding_token_id: int = 0
) -> tuple[collections.abc.Callable[[], contextlib.AbstractContextManager], dict[str, torch.Tensor | str], nemo_automodel.components.distributed.context_parallel.sharder.ShardLayout]

Keep IDs global for embedding, and shard auxiliaries in contiguous order.

Parameters:

cp_mesh
DeviceMesh

Stage-local context mesh. Peers receive the same full batch.

tp_mesh
DeviceMesh | None

Unused TP mesh passed to the shared sharder.

batch
dict[str, torch.Tensor | str]

Global IDs, labels, positions, masks [batch, sequence]. The attention mask contains document IDs (zero means padding); positions must be supplied for packed documents. Entries are replaced in place, but input tensor storage is never modified. Native THD is unsupported.

loss_mask
torch.Tensor | NoneDefaults to None

Optional global supervision weights [batch, sequence].

padding_token_id
intDefaults to 0

Sentinel passed to shared padding machinery.

Returns: Callable[[], contextlib.AbstractContextManager]

Null context factory, prepared batch, and contiguous shard layout.

nemo_automodel.components.models.ergo.context_parallel.shard_te_batch(
cp_mesh: torch.distributed.device_mesh.DeviceMesh | None,
tp_mesh: torch.distributed.device_mesh.DeviceMesh | None,
batch: dict[str, torch.Tensor | str],
num_chunks: int,
loss_mask: torch.Tensor | None = None,
padding_token_id: int = 0
) -> tuple[collections.abc.Callable[[], contextlib.AbstractContextManager], dict[str, torch.Tensor | str | int | bool], nemo_automodel.components.distributed.context_parallel.sharder.ShardLayout | None]

Keep packed stage-zero IDs global while TE owns the token partition.

Parameters:

cp_mesh
DeviceMesh | None

This pipeline stage’s context mesh; None means CP1.

tp_mesh
DeviceMesh | None

Unused TP mesh from the shared sharder contract.

batch
dict[str, torch.Tensor | str]

IDs, labels and positions [batch, sequence], real/padded document lengths [batch, documents], and optional loss weights of the ID shape. Tensor storage is retained unchanged; the returned mapping is new.

num_chunks
int

Number of PP microbatches, evenly dividing the batch dimension.

loss_mask
torch.Tensor | NoneDefaults to None

Optional supervision weights [batch, sequence].

padding_token_id
intDefaults to 0

Filler passed to the shared TE preparation.

Returns: Callable[[], contextlib.AbstractContextManager]

Null context, prepared mapping and single-chunk layout (None for multiple