MCPcopy Create free account
hub / github.com/alibaba/MNN / InitAlpha

Function InitAlpha

tools/quantization/quantizeWeight.cpp:16–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#include <MNN/MNNDefine.h>
15
16void InitAlpha(const float* weight, const int weightNum, const int kernelNum, float* alpha, const float weightClampValue) {
17 const int kernelDim = weightNum / kernelNum;
18
19 for (int i = 0; i < kernelNum; i++) {
20 float avg = 0;
21 float max = 0;
22 float absVal;
23
24 for (int j = 0; j < kernelDim; j++) {
25 absVal = std::fabs(weight[i * kernelDim + j]);
26 avg += absVal;
27 if (absVal > max) {
28 max = absVal;
29 }
30 }
31 avg = avg / float(kernelDim);
32
33 if (weightClampValue > 1) {
34 alpha[i] = max / (weightClampValue * 1.25);
35 }
36 else {
37 alpha[i] = avg;
38 }
39 }
40}
41
42void UpdateQuantizedWeights(const float* weight, const int weightNum, const int kernelNum, float* alpha,
43 const float weightClampValue, int8_t* quantizedWeight) {

Callers 1

QuantizeWeightADMMFunction · 0.85

Calls 1

fabsFunction · 0.85

Tested by

no test coverage detected