量化细节:非对称激活量化时的神经网络非线性如何保证?

首先看下量化:

 

我们对a1的量化称为激活量化,那么采用非对称量化的话,参考下面公式:

Asymmetric Quantization

During the training we optimize the input_low and input_range parameters using gradient descent:

input_high=input_low + input_range

levels=256

level_low=0

level_high=2^{bits}-1

For better accuracy, floating-point zero should be within quantization range and strictly mapped into quant (without rounding). Therefore, the following scheme is applied to ranges of weights and activations before quantization:

{input_low}' = min(input_low, 0)

{input_high}' = max(input_high, 0)

ZP= \left\lfloor \frac{-{input_low}'*(levels-1)}{{input_high}'-{input_low}'} \right \rceil

{input_high}''=\frac{ZP-levels+1}{ZP}*{input_low}'

{input_low}''=\frac{ZP}{ZP-levels+1}*{input_high}'

{input_low,input_high} = \begin{cases} {input_low}',{input_high}', & ZP \in ${0,levels-1}$ \ {input_low}',{input_high}'', & {input_high}'' - {input_low}' > {input_high}' - {input_low}'' \ {input_low}'',{input_high}', & {input_high}'' - {input_low}' <= {input_high}' - {input_low}''\ \end{cases}

 也就是,将a1的值量化到0-255了,这不就是说都大于零了么?那relu就没用了啊!那神经网络非线性怎么体现呢?

接下来,我们在谷歌发表的论文[QuantizationandTrainingofNeuralNetworksforEfficientInteger-Arithmetic-OnlyInference]里寻找答案。

这篇文章里有这样一句话

 

也就是说,clamping吸收了relu的功能,起到了非线性的作用。

但是,其实量化中,每一个参数的量化都有round操作,这不就是也是非线性么!!!暂时先这么理解吧🤣

 

posted @ 2021-05-28 19:14  鲍曼小学生  阅读(341)  评论(0编辑  收藏  举报