nemo_automodel.components.distributed.tp_replicas
nemo_automodel.components.distributed.tp_replicas
Synchronization helpers for parameters replicated across tensor parallel ranks.
Module Contents
Functions
Data
_MODEL_OWNED_GRAD_DIVISOR_ATTR
_TP_REPLICA_GRAD_REDUCTION_ATTR
API
Return a non-trivial TP submesh when one is present.
Split gradients into bounded communication buffers.
Parameters:
Dense rank-local gradients of arbitrary shape on one device with one dtype. Low-precision elements are budgeted at their FP32 communication size.
Return an FP32 communication dtype for low-precision gradients.
Return whether rank-local tensor storage is replicated across TP peers.
A DTensor may live on a DP-only submesh even though physical copies exist for
every TP coordinate. Conversely, an MoE mesh may fold the TP ranks into axes
named ep or ep_shard. Comparing mesh coordinates and placements keeps
both cases explicit instead of assuming every unnamed TP dimension is a copy.
Parameters:
Tensor or DTensor of arbitrary global and rank-local shape.
Ordered global ranks in the current TP group.
Current global rank.
Name of the tensor-parallel mesh dimension.
Returns: bool
Whether every TP peer represented in the tensor mesh differs only along
Yield model buffers once in rank-stable fully qualified name order.
Yield unmarked parameters once with their module reduction semantic.
Yield parameters once in rank-stable fully qualified name order.
Return rank-local storage for a Tensor or DTensor.
Broadcast replicated parameters and buffers from the first TP rank.
Intended TP shards are excluded by their DTensor placement, and model-owned shards are excluded by their explicit parameter or module marker. The collective operates on each tensor’s rank-local storage, whose shape is identical within a TP group even when another mesh axis shards the global tensor.
Parameters:
Local pipeline-stage modules containing tensors of arbitrary shape. Shared tensors are visited once.
Root mesh containing the tensor-parallel axis.
Name of the tensor-parallel mesh dimension.
Returns: int
Number of rank-local tensors broadcast on this rank.
Exclude an owner-sharded module subtree from TP replica synchronization.
Some parameter owners use a mesh that folds physical TP ranks into another
logical axis. Their local tensors are different shards, even though they are
not DTensors carrying an explicit tp placement. Marking the complete
subtree keeps both parameter and buffer synchronization from treating those
owner-local tensors as TP replicas.
Parameters:
Owner-sharded module whose current subtree must remain local.
Mark direct parameters of a module with their TP-replica reduction semantic.
Parameters:
Module whose direct parameters are replicated across TP ranks.
"mean" for redundant full computation or "sum" for
disjoint partial contributions.
Reduce TP-replicated gradients once at the optimizer boundary.
Call this exactly once per optimizer update, after gradient accumulation and
before gradient scaling, norm calculation, clipping, or optimizer.step().
Full-computation replicas are mean-reduced so each logical parameter has one
optimizer update. Modules explicitly marked as producing disjoint partial
contributions are sum-reduced, which makes repeated synchronization within
one update non-idempotent. Gradients are flattened into bounded buffers by
reduction, device, and dtype before communication. DTensor gradients are
reduced through rank-local storage while retaining their global shape and
placements. Model-owned shards and parameters or gradients sharded or partial
on the TP axis are untouched. Low-precision gradients are reduced in FP32 and
cast back to their storage dtype after synchronization.
Parameters:
Local pipeline-stage modules whose gradients have arbitrary shapes and have completed accumulation for this optimizer update.
Root mesh containing the tensor-parallel axis.
Name of the tensor-parallel mesh dimension.
Returns: int
Number of rank-local gradients synchronized on this rank.
Raises:
RuntimeError: If gradient presence differs across TP replicas, or if a replicated parameter has a sparse gradient that cannot be flattened without changing its representation.