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

Function UpdateQuantizedWeights

tools/quantization/quantizeWeight.cpp:42–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42void 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
55void UpdateAlpha(const float* weight, const int weightNum, const int kernelNum, float* alpha, int8_t* quantizedWeight) {
56 const int kernelDim = weightNum / kernelNum;

Callers 1

QuantizeWeightADMMFunction · 0.85

Calls 2

minFunction · 0.50
maxFunction · 0.50

Tested by

no test coverage detected