weight format is [co, ci, kh, kw]
| 71 | |
| 72 | // weight format is [co, ci, kh, kw] |
| 73 | int QuantizeWeightADMM(const float* weight, const int weightNum, int8_t* quantizedWeight, float* alpha, |
| 74 | const int kernelNum, const float weightClampValue) { |
| 75 | // channels: co |
| 76 | DCHECK((weightNum % kernelNum) == 0) << "weight size error!"; |
| 77 | const int kernelDim = weightNum / kernelNum; // ci * kh * kw |
| 78 | |
| 79 | InitAlpha(weight, weightNum, kernelNum, alpha, weightClampValue); |
| 80 | |
| 81 | int iter = 0; |
| 82 | float diffRate = 1; |
| 83 | float preSum = 0; |
| 84 | float curSum = 0; |
| 85 | const int maxIter = 1000; |
| 86 | |
| 87 | for (int i = 0; i < weightNum; i++){ |
| 88 | preSum += std::fabs(weight[i]); |
| 89 | } |
| 90 | // update weights quan |
| 91 | while(iter < maxIter) { |
| 92 | UpdateQuantizedWeights(weight, weightNum, kernelNum, alpha, weightClampValue, quantizedWeight); |
| 93 | UpdateAlpha(weight, weightNum, kernelNum, alpha, quantizedWeight); |
| 94 | iter++; |
| 95 | } |
| 96 | |
| 97 | for (int i = 0; i < weightNum; i++){ |
| 98 | curSum += std::fabs(quantizedWeight[i]*alpha[i/kernelDim]); |
| 99 | } |
| 100 | DLOG(INFO) << "iter: " << iter << " with diff "<< preSum-curSum; |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | // weight format is [co, ci, kh, kw] |
| 105 | int SymmetricQuantizeWeight(const float* weight, const int size, int8_t* quantizedWeight, float* scale, |
no test coverage detected