Skip to content

vllm.models.inkling2.nvidia.ops.mxfp8

MXFP8 (e4m3 values, ue8m0 scales per 32 elements) activation quantization.

Functions:

  • mxfp8_quantize –

    Quantize rows of bf16 x [M, N] to MXFP8 with round-up power-of-two scales.

mxfp8_quantize(x)

Quantize rows of bf16 x [M, N] to MXFP8 with round-up power-of-two scales.

Returns e4m3 values and row-major ue8m0 scale exponents [M, N/32].

Source code in vllm/models/inkling2/nvidia/ops/mxfp8.py
def mxfp8_quantize(x: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
    """Quantize rows of bf16 `x` [M, N] to MXFP8 with round-up power-of-two scales.

    Returns e4m3 values and row-major ue8m0 scale exponents [M, N/32].
    """
    assert x.ndim == 2 and x.is_contiguous() and x.shape[1] % 32 == 0
    rows, n = x.shape
    values = torch.empty((rows, n), dtype=torch.float8_e4m3fn, device=x.device)
    scales = torch.empty((rows, n // 32), dtype=torch.uint8, device=x.device)
    block = math.gcd(n, 1024)
    _mxfp8_quantize_kernel[(min(rows, 8192), n // block)](
        x,
        values,
        scales,
        rows,
        N=n,
        BLOCK=block,
        enable_fp_fusion=False,
        launch_pdl=True,
    )
    return values, scales