core.distributed.fsdp.src.megatron_fsdp.experimental.placement#
DBuffer placement definitions.
DBuffer uses PyTorch DTensor’s Placement, Replicate, and Partial
types directly. RowAtomic, BlockAtomic, and TensorAtomic are
DBuffer-specific dim-0 Shard placements whose local storage is part of one
flattened buffer. RowAtomic and BlockAtomic split the flattened buffer into
equal-size per-rank shards; TensorAtomic instead assigns every logical
tensor as a whole to one owner rank, so per-rank shards may differ in size.
============= ============= ====================
Source Destination DBuffer operation
============= ============= ====================
sharded Replicate allgather()
Partial sharded reduce_scatter()
Partial Replicate allreduce()
Replicate sharded view() (local)
============= ============= ====================
Module Contents#
Classes#
How a |
|
DBuffer-specific dim-0 shard placement that keeps each row intact. |
|
Flattened dim-0 shard placement that keeps |
|
Dim-0 shard placement that assigns each logical tensor as a whole to one rank. |
Functions#
Return the changed mesh axis, requiring at most one placement change. |
Data#
API#
- core.distributed.fsdp.src.megatron_fsdp.experimental.placement.__all__#
[‘BlockAtomic’, ‘RowAtomic’, ‘ShardLayout’, ‘TensorAtomic’, ‘changed_mesh_axis’]
- class core.distributed.fsdp.src.megatron_fsdp.experimental.placement.ShardLayout(*args, **kwds)#
Bases:
enum.EnumHow a
RowAtomic/BlockAtomicgroup is split into per-rank segments.Initialization
- PADDED#
‘padded’
Equal segments. The group is padded to a multiple of
dp_size * LCM(row sizes)(times the block size forBlockAtomic).
- UNPADDED#
‘unpadded’
No padding. Tensors are packed back to back and segments end on the row/block boundary nearest to an even split.
- class core.distributed.fsdp.src.megatron_fsdp.experimental.placement.RowAtomic#
Bases:
torch.distributed.tensor.ShardDBuffer-specific dim-0 shard placement that keeps each row intact.
Initialization
- __eq__(other: object) bool#
- class core.distributed.fsdp.src.megatron_fsdp.experimental.placement.BlockAtomic(block_size: int)#
Bases:
torch.distributed.tensor.ShardFlattened dim-0 shard placement that keeps
block_sizerows together.Initialization
- __eq__(other: object) bool#
- __repr__() str#
- class core.distributed.fsdp.src.megatron_fsdp.experimental.placement.TensorAtomic#
Bases:
torch.distributed.tensor.ShardDim-0 shard placement that assigns each logical tensor as a whole to one rank.
With
fully_shard, useTensorAtomic()inPlacementsand supply onlyFsdpContext(parameter_to_owner=...). Each parameter group derives its tensor owners from that mapping and passes them tolayout_builder.build_for_tensor_atomic. Ownership is encoded by the layout’s offsets; this placement stores no owner assignments.Initialization
- __eq__(other: object) bool#
- __repr__() str#
- core.distributed.fsdp.src.megatron_fsdp.experimental.placement.changed_mesh_axis(
- old_placements: collections.abc.Iterable[torch.distributed.tensor.placement_types.Placement],
- new_placements: collections.abc.Iterable[torch.distributed.tensor.placement_types.Placement],
Return the changed mesh axis, requiring at most one placement change.