Class MxFp8

java.lang.Object
smile.llm.quant.MxFp8

public final class MxFp8 extends Object
MXFP8 (OCP microscaling) weights: FP8 E4M3 elements with one shared E8M0 scale per 32 consecutive elements along the reduction dimension.

An E8M0 byte s encodes the power of two 2^(s - 127); 255 is NaN. A weight W[n][k] is fp8[n][k] * 2^(scale[n][k / 32] - 127). Checkpoints store the scales as <name>.weight_scale_inv (U8, [N, K / 32]).

This is the portable reference: it expands a weight to a dense tensor. Production kernels keep the FP8 bytes and apply the scales in the GEMM.

  • Field Details

  • Method Details

    • e8m0ToFloat

      public static float e8m0ToFloat(int code)
      Returns the value of an E8M0 scale byte.
      Parameters:
      code - the stored byte, 0..255.
      Returns:
      2^(code - 127), or NaN for 255.
    • dequantize

      public static Tensor dequantize(Tensor weight, Tensor scale, ScalarType dtype)
      Expands an MXFP8 weight to a dense tensor.
      Parameters:
      weight - FP8 E4M3 weight [N, K] with K a multiple of BLOCK.
      scale - E8M0 scales as UInt8 [N, K / 32], on the same device as weight.
      dtype - result dtype.
      Returns:
      the dense weight [N, K]; the caller owns it.
      Throws:
      IllegalArgumentException - if the shapes are not an MXFP8 layout.