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

Function UpdateAlpha

tools/quantization/quantizeWeight.cpp:55–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55void UpdateAlpha(const float* weight, const int weightNum, const int kernelNum, float* alpha, int8_t* quantizedWeight) {
56 const int kernelDim = weightNum / kernelNum;
57 const float eps = 1e-9f;
58
59 for (int i = 0; i < kernelNum; i++) {
60 const int offset = i * kernelDim;
61 float sum1 = 0;
62 float sum2 = 0;
63
64 for (int j = 0; j < kernelDim; j++) {
65 sum1 += weight[offset + j] * quantizedWeight[offset + j];
66 sum2 += quantizedWeight[offset + j] * quantizedWeight[offset + j];
67 }
68 alpha[i] = sum1 / (sum2+eps);
69 }
70}
71
72// weight format is [co, ci, kh, kw]
73int QuantizeWeightADMM(const float* weight, const int weightNum, int8_t* quantizedWeight, float* alpha,

Callers 1

QuantizeWeightADMMFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected