Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-359

Dynamic Activation Quantization

Problem

Quantize activations dynamically: scale = max(|x|) / (2^(bits-1)-1), then round each value to the nearest code clamped to +/-qmax. Return [scale, codes]; an all-zero tensor returns [0.0, zeros].

The signature is dynamic_activation_quant(x, bits=8).

Hint

Dynamic quantization computes the scale at runtime from the current tensor.

Test cases

case 1
in: [[1,-0.5,0.25],8]
expected: [0.007874015748031496,[127,-64,32]]
case 2
in: [[0,0],8]
expected: [0,[0,0]]
case 3
in: [[2],4]
expected: [0.2857142857142857,[7]]
case 4
in: [[1,2,3],4]
expected: [0.42857142857142855,[2,5,7]]
Starter codePython
def dynamic_activation_quant(x, bits=8):
    # Your code here
    pass

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