Skip to content
DeepForgeby svx
All problems
EasyDeep Learningdl-324

Block-Wise Scale Factor

Problem

Compute the symmetric scale for a quantization block: max(|x|) / (2^(bits-1) - 1), where the denominator is the largest representable signed integer. An all-zero block gives 0.0.

The signature is block_scale_factor(block, bits=8).

Hint

Smaller blocks adapt better to local ranges but cost more scale bytes.

Test cases

case 1
in: [[-1,2,0.5],8]
expected: 0.015748031496062992
case 2
in: [[0,0],8]
expected: 0
case 3
in: [[3,-4],4]
expected: 0.5714285714285714
case 4
in: [[1.5],8]
expected: 0.011811023622047244
Starter codePython
def block_scale_factor(block, bits=8):
    # Your code here
    pass

4 test cases · run your code against them in the editor