| 14 | #include <MNN/MNNDefine.h> |
| 15 | |
| 16 | void 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 | |
| 42 | void UpdateQuantizedWeights(const float* weight, const int weightNum, const int kernelNum, float* alpha, |
| 43 | const float weightClampValue, int8_t* quantizedWeight) { |
no test coverage detected