Skip to content
DeepForgeby svx
All problems
HardDeep Learningdl-342

Optimal Clip Search

Problem

Search candidate clipping values for symmetric quantization. For each candidate c, quantize values with scale c / (2^(bits-1)-1) after clipping to [-c, c], dequantize, and compute the MSE. Return the candidate with the lowest MSE, breaking ties toward the smaller c.

The signature is optimal_clip_search(values, candidates, bits=8).

Hint

Clipping a few extreme values can reduce total error by tightening the step size.

Test cases

case 1
in: [[-5,-1,0.5,1,5],[1,2,5],8]
expected: 5
case 2
in: [[0.1,0.2,0.1],[0.1,1],8]
expected: 1
case 3
in: [[1,2,100],[1,2,100],8]
expected: 100
case 4
in: [[0,0],[2,1],8]
expected: 1
Starter codePython
def optimal_clip_search(values, candidates, bits=8):
    # Your code here
    pass

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