Class Fp8BlockDequant

java.lang.Object
smile.llm.quant.Fp8BlockDequant

public final class Fp8BlockDequant extends Object
Dequantizes DeepSeek / Qwen-style fine-grained FP8 weights (weight_block_size = [128, 128] + weight_scale_inv).

Official Qwen3.8-FP8 checkpoints use block scales; Fp8BlockLinear runs them via at::_scaled_mm_v2. This helper dequantizes for reference tests and debug only.

  • Field Details

    • BLOCK

      public static final int BLOCK
      Qwen / DeepSeek fine-grained FP8 block size.
      See Also:
  • Method Details

    • isBlockScale

      public static boolean isBlockScale(Tensor weight, Tensor scale)
      Returns true when scale is a block layout for weight.
      Parameters:
      weight - FP8 weight [N, K].
      scale - candidate scale tensor.
      Returns:
      true when scale is a [ceil(N/128), ceil(K/128)] block layout for weight shaped [N, K].
    • isTensorScale

      public static boolean isTensorScale(Tensor scale)
      Returns true when scale is a scalar / length-1 tensor scale.
      Parameters:
      scale - candidate scale tensor.
      Returns:
      true when scale is a scalar / length-1 tensor scale.
    • dequant

      public static Tensor dequant(Tensor weightFp8, Tensor scaleInv, ScalarType outDtype)
      Dequantizes weight_fp8 * broadcast(scale_inv) to outDtype.
      Parameters:
      weightFp8 - FP8 weight [N, K].
      scaleInv - block inverse scales [ceil(N/128), ceil(K/128)].
      outDtype - compute dtype (BF16 or FP16).
      Returns:
      dense weight on the same device as weightFp8 (caller owns).