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
NVFP4Tensor
NVFP4Tensor
class max.nn.common_layers.quant_tensor.NVFP4Tensor(*, weight, weight_scale, weight_scale_2, input_scale, block_size=(1, 16))
Bases: _QuantizedWeight
NVFP4 (modelopt) block-scaled quantized tensor.
NVFP4 packs two float4_e2m1fn values per uint8 and applies two
scale levels: a per-16-element block scale (float8_e4m3fn) and a
per-tensor global scale (weight_scale_2, float32). The activation
scale (input_scale, float32) is static — loaded from the
checkpoint — and used to normalize activations before dynamic block
quantization (see _matmul_nvfp4()).
-
Parameters:
-
- weight (Tensor) – Packed
uint8weight data of shape[rows, cols // 2]. - weight_scale (Tensor) – Per-block
float8_e4m3fnscales of shape[ceil(rows / block_m), ceil(cols / block_k)]. - weight_scale_2 (Tensor) – Per-tensor
float32global scale, scalar()(or[num_experts]when stacked for grouped MoE). - input_scale (Tensor) – Static per-tensor
float32activation scale, scalar()(or[num_experts]when stacked). - block_size (tuple[int, int]) – Per-block size as
(block_m, block_k);(1, 16)for NVFP4.
- weight (Tensor) – Packed
block_size
Quantization block shape as (rows, cols).
input_scale
input_scale: Tensor
local_experts()
local_experts(device)
device’s experts of a stack sharded on its expert axis.
Unlike local_shards, the per-expert host scales are cut to the
same experts.
-
Parameters:
-
device (int)
-
Return type:
local_shards
property local_shards: tuple[NVFP4Tensor, ...]
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 weight/weight_scale along axis onto mesh.
-
Parameters:
-
- axis (int)
- mesh (DeviceMesh)
-
Return type:
stacked_zeros()
classmethod stacked_zeros(num_experts, shape, *, scales_per_expert=1, block_size=(1, 16), device=None)
Builds a zero-filled stack of num_experts weights of shape.
weight and weight_scale gain a leading expert axis on
device. The per-tensor scales stay on the host as
[num_experts], or [num_experts, scales_per_expert] for a fused
weight that keeps each part’s scale.
-
Parameters:
-
Return type:
to()
to(target)
Returns a copy with weight and weight_scale on target.
-
Parameters:
-
target (Device | DeviceMesh | DeviceMapping)
-
Return type:
weight_scale
weight_scale: Tensor
weight_scale_2
weight_scale_2: Tensor
zeros()
classmethod zeros(shape, *, block_size=(1, 16))
Builds a zero-filled NVFP4Tensor of logical shape.
shape is the unpacked Linear-convention [out_dim, in_dim].
The packed weight leaf has half the trailing dimension.