[03-groupwise-int4-quantization]'s INT4 uses a fixed absolute step size within each group, so small values within a group still lose relative precision compared to the group's largest value. FP8 (E4M3: 1 sign bit, 4 exponent bits, 3 mantissa bits) keeps a floating-point-style exponent instead, so its relative precision stays roughly constant across magnitudes. Implement a simplified block-wise FP8 quantization scheme: split a weight matrix into fixed-size 2D blocks, compute one scale per block, and quantize each block's values into a simulated 8-bit floating-point format with 4 exponent bits and 3 mantissa bits.
scale[block] = max(|W[block]|) / 448 -- FP8 E4M3 max representable magnitude
x_scaled = W[block] / scale[block]
x_fp8 = round_to_3_mantissa_bits(x_scaled) -- simulated via frexp/ldexp
x_hat = x_fp8 * scale[block]
block_rows/block_cols respectively.np.frexp splits a float into a mantissa in [0.5, 1) and an integer exponent — round the mantissa to 2**-3 granularity, then reconstruct with np.ldexp. Compute one scale per 2D tile using nested reshaping similar to group-wise quantization, but over 2 axes instead of 1.
No results yet
Run your code to check it against the examples, or submit to run every test.