core.distributed.fsdp.src.megatron_fsdp.experimental.quantized_dbuffer#
Transformer Engine MXFP8 distributed buffers composed from physical planes.
Module Contents#
Classes#
The MFSDP storage and lifecycle for one TE MXFP8 tensor. |
Functions#
Return a shared MXFP8 quantizer with the given usages. |
|
Return MFSDP’s storage dtype for a parameter. |
|
Derive rowwise scales from the layout shared by rowwise_data and columnwise_data. |
|
Derive columnwise scales from the layout shared by rowwise_data and columnwise_data. |
|
Replace BlockAtomic placements with RowAtomic for coordinates measured in blocks. |
|
Pad rowwise scales to TE’s physical allocation shape. |
|
Pad columnwise scales to TE’s physical allocation shape. |
|
Update |
Data#
API#
- core.distributed.fsdp.src.megatron_fsdp.experimental.quantized_dbuffer._MXFP8_DTYPE#
None
- core.distributed.fsdp.src.megatron_fsdp.experimental.quantized_dbuffer._MXFP8_BLOCK_SIZE#
32
- core.distributed.fsdp.src.megatron_fsdp.experimental.quantized_dbuffer._get_quantizer(
- *,
- rowwise: bool,
- columnwise: bool,
Return a shared MXFP8 quantizer with the given usages.
- core.distributed.fsdp.src.megatron_fsdp.experimental.quantized_dbuffer.effective_dtype(tensor: torch.Tensor) torch.dtype#
Return MFSDP’s storage dtype for a parameter.
- core.distributed.fsdp.src.megatron_fsdp.experimental.quantized_dbuffer._rowwise_scale_layout( ) core.distributed.fsdp.src.megatron_fsdp.experimental.layout.GlobalLayout#
Derive rowwise scales from the layout shared by rowwise_data and columnwise_data.
- core.distributed.fsdp.src.megatron_fsdp.experimental.quantized_dbuffer._columnwise_scale_layout( ) core.distributed.fsdp.src.megatron_fsdp.experimental.layout.GlobalLayout#
Derive columnwise scales from the layout shared by rowwise_data and columnwise_data.
- core.distributed.fsdp.src.megatron_fsdp.experimental.quantized_dbuffer._block_atomic_to_flat(
- placements: collections.abc.Iterable[torch.distributed.tensor.placement_types.Placement],
Replace BlockAtomic placements with RowAtomic for coordinates measured in blocks.
For example, one MXFP8 columnwise scale row represents a 32-row weight block, so RowAtomic preserves the shard boundaries of BlockAtomic(32).
- core.distributed.fsdp.src.megatron_fsdp.experimental.quantized_dbuffer._pad_rowwise_scale(scale: torch.Tensor) torch.Tensor#
Pad rowwise scales to TE’s physical allocation shape.
- core.distributed.fsdp.src.megatron_fsdp.experimental.quantized_dbuffer._pad_columnwise_scale(scale: torch.Tensor) torch.Tensor#
Pad columnwise scales to TE’s physical allocation shape.
- core.distributed.fsdp.src.megatron_fsdp.experimental.quantized_dbuffer.update_mxfp8_tensor(
- src: transformer_engine.pytorch.tensor.mxfp8_tensor.MXFP8Tensor,
- dst: transformer_engine.pytorch.tensor.mxfp8_tensor.MXFP8Tensor,
- *,
- rowwise: bool = True,
- columnwise: bool = True,
Update
dstin place fromsrc, a compact view of the allocated planes.rowwiseandcolumnwiseselect the newly gathered planes, which are taken fromsrcwith padded scales. Planes gathered earlier for the other phase stay as installed ondst, and planes absent fromsrcare cleared.srcis not modified.
- class core.distributed.fsdp.src.megatron_fsdp.experimental.quantized_dbuffer.QuantizedDBuffer(
- mesh: torch.distributed.DeviceMesh,
- placements: collections.abc.Iterable[torch.distributed.tensor.placement_types.Placement],
- layout: core.distributed.fsdp.src.megatron_fsdp.experimental.layout.GlobalLayout,
- device: torch.device | str,
The MFSDP storage and lifecycle for one TE MXFP8 tensor.
The data layout owns the parameter-to-rank partition. Scale planes use its compact MXFP8 coordinates, so every plane on a rank describes the same local data rows. TE-only padding is added when materializing a wrapper for compute, not to distributed storage.
Initialization
Allocate MXFP8 data and scale planes from a shared weight layout.
- rowwise_data: core.distributed.fsdp.src.megatron_fsdp.experimental.dbuffer.DBuffer#
None
- columnwise_data: core.distributed.fsdp.src.megatron_fsdp.experimental.dbuffer.DBuffer#
None
- rowwise_scale: core.distributed.fsdp.src.megatron_fsdp.experimental.dbuffer.DBuffer#
None
- columnwise_scale: core.distributed.fsdp.src.megatron_fsdp.experimental.dbuffer.DBuffer#
None
- classmethod empty(
- mesh: torch.distributed.DeviceMesh,
- placements: collections.abc.Iterable[torch.distributed.tensor.placement_types.Placement],
- tensor_shapes: collections.abc.Iterable[core.distributed.fsdp.src.megatron_fsdp.experimental.layout.Shape],
- device: torch.device | str,
- *,
- shard_layout: core.distributed.fsdp.src.megatron_fsdp.experimental.placement.ShardLayout = ShardLayout.PADDED,
Build an MXFP8 layout from logical tensor shapes and allocate its planes.
- Parameters:
mesh – Device mesh whose dimensions correspond to
placements.placements – Per-mesh-axis DBuffer placements.
tensor_shapes – Logical 2D shapes that the buffer manages.
device – Device for the local planes.
shard_layout – Padded (equal) or unpadded (32-row-block-aligned, unequal) rank segments; see
DBuffer.empty.
- property mesh: torch.distributed.DeviceMesh#
Device mesh shared by all physical planes.
- property placements: tuple[torch.distributed.tensor.placement_types.Placement, ...]#
Logical weight placements; scale planes map these to scale coordinates.
- classmethod _from_planes(
- rowwise_data: core.distributed.fsdp.src.megatron_fsdp.experimental.dbuffer.DBuffer,
- columnwise_data: core.distributed.fsdp.src.megatron_fsdp.experimental.dbuffer.DBuffer,
- rowwise_scale: core.distributed.fsdp.src.megatron_fsdp.experimental.dbuffer.DBuffer,
- columnwise_scale: core.distributed.fsdp.src.megatron_fsdp.experimental.dbuffer.DBuffer,
Create a composed view from already-allocated physical planes.
- property is_rowwise_allocated: bool#
Whether rowwise data and scales are allocated.
- property is_columnwise_allocated: bool#
Whether columnwise data and scales are allocated.
- get_tensor_view(
- index: int,
Return a compact, unswizzled MXFP8 view that aliases every allocated plane pair.
Released planes are omitted, so the view never reads storage that
release_storage()freed.
- quantize_( ) None#
Quantize a local master shard with matching mesh, placements, layout, and device.
- property planes: tuple[core.distributed.fsdp.src.megatron_fsdp.experimental.dbuffer.DBuffer, core.distributed.fsdp.src.megatron_fsdp.experimental.dbuffer.DBuffer, core.distributed.fsdp.src.megatron_fsdp.experimental.dbuffer.DBuffer, core.distributed.fsdp.src.megatron_fsdp.experimental.dbuffer.DBuffer]#
Physical planes in TE’s rowwise-data-first order.
- planes_for(
- *,
- rowwise: bool,
- columnwise: bool,
Physical data and scale planes of the selected representations.
- property is_symmetric_memory: bool#
Whether every plane is backed by symmetric memory.
- reallocate_storage() None#
Restore every plane’s backing storage.
- release_storage(*, rowwise_only: bool = False) None#
Release all plane storage, or only rowwise storage, while retaining aliases.
- view(
- placements: collections.abc.Iterable[torch.distributed.tensor.placement_types.Placement],
Return a storage-sharing view of every physical plane.
- redistribute(
- new_placements: collections.abc.Iterable[torch.distributed.tensor.placement_types.Placement],
- *,
- out: QuantizedDBuffer | None = None,
- rowwise: bool = True,
- columnwise: bool = True,
Redistribute the selected planes, returning
outor a new wrapper.
- allgather(
- mesh_axis: int | collections.abc.Iterable[int],
- *,
- out: QuantizedDBuffer | None = None,
Gather one or more axes in every plane, reusing
outwhen supplied.