For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Python class
FP8BlockTensor
FP8BlockTensor
class max.nn.common_layers.quant_tensor.FP8BlockTensor(*, weight, weight_scale_inv, block_size=(128, 128))
Bases: _QuantizedWeight
FP8 block-scaled quantized tensor.
-
Parameters:
block_size
Quantization block shape as (rows, cols).
dequantize()
dequantize(dtype=bfloat16)
Decodes the weight: weight * weight_scale_inv, block by block.
Each block_size block of weight is multiplied by its entry of
weight_scale_inv. The product is taken in float32 and rounded once
to dtype, so the result is exact in bfloat16 only when each scaled
value fits bfloat16’s mantissa, as it does for power-of-two scales.
-
Parameters:
-
dtype (DType) – The dtype of the result.
-
Returns:
-
The decoded weight,
[rows, cols]indtype. -
Raises:
-
ValueError – If the weight is not rank 2, its dimensions are not multiples of the block, or the scales are not one entry per block. Ragged edge blocks are not supported.
-
Return type:
local_shards
property local_shards: tuple[FP8BlockTensor, ...]
Per-device shards, pairing each weight shard with its scales.
mesh
property mesh: DeviceMesh
Device mesh of the packed weight tensor.
shard()
shard(axis, mesh)
Co-shard both leaves along axis onto mesh.
-
Parameters:
-
- axis (int) – Tensor axis to shard along (same index into both
weight.shapeandweight_scale_inv.shape). - mesh (DeviceMesh) – 1-D
DeviceMeshto scatter onto.
- axis (int) – Tensor axis to shard along (same index into both
-
Returns:
-
A new
FP8BlockTensorwhoseweightandweight_scale_invleaves are each distributedSharded(axis=axis)acrossmesh. -
Return type:
stacked_zeros()
classmethod stacked_zeros(num_experts, shape, *, block_size=(128, 128), scale_dtype=float32, device=None)
Builds a zero-filled stack of num_experts weights of shape.
weight and weight_scale_inv gain a leading expert axis on
device. scale_dtype is the dtype the scales are stored in, which
a checkpoint may pick differently from the float32 the kernels read;
with_scale_dtype() casts them.
-
Parameters:
-
Return type:
to()
to(target)
Returns a copy with weight and its scales placed on target.
-
Parameters:
-
target (Device | DeviceMesh | DeviceMapping)
-
Return type:
weight_scale_inv
weight_scale_inv: Tensor
with_scale_dtype()
with_scale_dtype(dtype)
Returns this tensor with its scales cast to dtype.
Returns self when the scales already have dtype.
-
Parameters:
-
dtype (DType)
-
Return type:
zeros()
classmethod zeros(shape, *, block_size=(128, 128))
Builds a FP8BlockTensor of the given shape, with all zeros.