IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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))

source

Bases: _QuantizedWeight

FP8 block-scaled quantized tensor.

Parameters:

  • weight (Tensor) – Packed float8_e4m3fn data of shape [rows, cols].
  • weight_scale_inv (Tensor) – Per-block inverse float32 scales of shape [ceil(rows / block_m), ceil(cols / block_k)].
  • block_size (tuple[int, int]) – Per-block size as (block_m, block_k).

block_size​

property block_size: tuple[int, int]

source

Quantization block shape as (rows, cols).

dequantize()​

dequantize(dtype=bfloat16)

source

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] in dtype.

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:

Tensor

local_shards​

property local_shards: tuple[FP8BlockTensor, ...]

source

Per-device shards, pairing each weight shard with its scales.

mesh​

property mesh: DeviceMesh

source

Device mesh of the packed weight tensor.

shard()​

shard(axis, mesh)

source

Co-shard both leaves along axis onto mesh.

Parameters:

  • axis (int) – Tensor axis to shard along (same index into both weight.shape and weight_scale_inv.shape).
  • mesh (DeviceMesh) – 1-D DeviceMesh to scatter onto.

Returns:

A new FP8BlockTensor whose weight and weight_scale_inv leaves are each distributed Sharded(axis=axis) across mesh.

Return type:

FP8BlockTensor

stacked_zeros()​

classmethod stacked_zeros(num_experts, shape, *, block_size=(128, 128), scale_dtype=float32, device=None)

source

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:

FP8BlockTensor

to()​

to(target)

source

Returns a copy with weight and its scales placed on target.

Parameters:

target (Device | DeviceMesh | DeviceMapping)

Return type:

FP8BlockTensor

weight_scale_inv​

weight_scale_inv: Tensor

source

with_scale_dtype()​

with_scale_dtype(dtype)

source

Returns this tensor with its scales cast to dtype.

Returns self when the scales already have dtype.

Parameters:

dtype (DType)

Return type:

FP8BlockTensor

zeros()​

classmethod zeros(shape, *, block_size=(128, 128))

source

Builds a FP8BlockTensor of the given shape, with all zeros.

Parameters:

Return type:

FP8BlockTensor