| 1440 | } |
| 1441 | |
| 1442 | void Calibration::runQuantizeModel() { |
| 1443 | if (_featureQuantizeMethod == "EMA") { |
| 1444 | _quantizeModelEMA(); |
| 1445 | return; |
| 1446 | } |
| 1447 | |
| 1448 | if (_featureQuantizeMethod == "KL") { |
| 1449 | _computeFeatureScaleKL(); |
| 1450 | } else if (_featureQuantizeMethod == "ADMM") { |
| 1451 | _computeFeatureScaleADMM(); |
| 1452 | } |
| 1453 | if (_debug) { |
| 1454 | _computeQuantError(); |
| 1455 | } |
| 1456 | _insertScale(); |
| 1457 | ComputeUnaryBuffer(_originalModel); |
| 1458 | _originalModel->extraTensorDescribe.clear(); |
| 1459 | for (auto& iter : _tensorDescribes) { |
| 1460 | _originalModel->extraTensorDescribe.emplace_back(std::move(iter.second)); |
| 1461 | } |
| 1462 | _tensorDescribes.clear(); |
| 1463 | |
| 1464 | { |
| 1465 | flatbuffers::FlatBufferBuilder builderOutput(1024); |
| 1466 | builderOutput.ForceDefaults(true); |
| 1467 | auto len = MNN::Net::Pack(builderOutput, _originalModel); |
| 1468 | builderOutput.Finish(len); |
| 1469 | std::ofstream output(_destModelFile, std::ofstream::binary); |
| 1470 | output.write((const char*)builderOutput.GetBufferPointer(), builderOutput.GetSize()); |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | void Calibration::dumpTensorScales(const std::string& modelFile) { |
| 1475 | rapidjson::StringBuffer sb; |
no test coverage detected