All problems
Scale Granularity Error Ratio
Problem
Compute the ratio of per-tensor to per-group quantization MSE for a weight matrix. Groups are contiguous chunks of group_size columns using a per-group symmetric scale; return mse_tensor / mse_group, or 1.0 when the group error is zero.
The signature is granularity_error_ratio(W, group_size, bits=8).
Hint
The ratio grows with the spread of per-group dynamic ranges.
Test cases
case 1
in: [[[1,0.7,50,0.3],[100,0,1,0.6]],2,8]
expected: 43.05562614711239
case 2
in: [[[3,2,1,0]],2,8]
expected: 2
case 3
in: [[[0,0]],2,8]
expected: 1
case 4
in: [[[1,0],[100,0]],2,8]
expected: 1
Starter codePython
def granularity_error_ratio(W, group_size, bits=8):
# Your code here
pass4 test cases · run your code against them in the editor