All problems
MXFP4 Block Quantization Error
Problem
Estimate the RMS error of MXFP4 block quantization. Elements use the E2M1 value set {0, 0.5, 1, 1.5, 2, 3, 4, 6} with a shared power-of-two scale 2^(floor(log2(amax)) - 2). Round each element to the nearest level (ties to the smaller), dequantize with the sign, and return the root-mean-square error; an all-zero block returns 0.0.
The signature is mxfp4_block_error(values).
Hint
The shared exponent is chosen from the block amax; the largest E2M1 level is 6.
Test cases
case 1
in: [[1,-1,0.5,-0.5]]
expected: 0
case 2
in: [[1.5,-1.5,0,3]]
expected: 0
case 3
in: [[1.7,0]]
expected: 0.14142135623730948
case 4
in: [[0,0]]
expected: 0
case 5
in: [[5]]
expected: 1
Starter codePython
import math
def mxfp4_block_error(values):
# Your code here
pass5 test cases · run your code against them in the editor