IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/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. /max/get-started.md).

Mojo function

dequant_fp4_nibble

def dequant_fp4_nibble[out_type: DType](packed_byte: UInt8, nibble_hi: Bool, scale_abs: Float32) -> Scalar[out_type]

Dequantizes one E2M1 nibble of a packed byte to out_type.

Low nibble (nibble_hi=False) is the even K element; high nibble is the odd one. The 4-bit value indexes E2M1_TO_FLOAT32 (sign + magnitude already baked into the 16-entry LUT) and is scaled by the block's |scale|.

Parameters:

  • ​out_type (DType): Output element dtype (bf16 for the Apple W4A16 path).

Args:

  • ​packed_byte (UInt8): The two-nibble packed FP4 byte.
  • ​nibble_hi (Bool): True selects the high nibble (byte >> 4), False the low.
  • ​scale_abs (Float32): The block scale, already passed through abs().

Returns:

Scalar[out_type]: The dequantized value E2M1_TO_FLOAT32[nibble] * scale_abs as Scalar[out_type].

Was this page helpful?