| 40 | } |
| 41 | |
| 42 | void UpdateQuantizedWeights(const float* weight, const int weightNum, const int kernelNum, float* alpha, |
| 43 | const float weightClampValue, int8_t* quantizedWeight) { |
| 44 | const int kernelDim = weightNum / kernelNum; |
| 45 | const float eps = 1e-9f; |
| 46 | float weightQuan; |
| 47 | CHECK((int)weightClampValue >= 7) << "quantization bits less than 4 not supported yet."; |
| 48 | |
| 49 | for (int i = 0; i < weightNum; i++) { |
| 50 | weightQuan = weight[i] / (alpha[i / kernelDim]+ eps); |
| 51 | quantizedWeight[i] = std::min(weightClampValue, std::max(-weightClampValue, std::roundf(weightQuan))); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | void UpdateAlpha(const float* weight, const int weightNum, const int kernelNum, float* alpha, int8_t* quantizedWeight) { |
| 56 | const int kernelDim = weightNum / kernelNum; |
no test coverage detected