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

Method _computeQuantError

tools/quantization/calibration.cpp:1209–1319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1207}
1208
1209void Calibration::_computeQuantError() {
1210 std::map<std::string, std::vector<float>> overflowRatiosMap;
1211 std::map<std::string, std::vector<float>> tensorCosDistanceMap;
1212 std::map<std::string, std::vector<float>> fakeQuantedFeatures;
1213
1214 int count = 0;
1215
1216 for (const auto& file : _calibrationFiles) {
1217 count++;
1218
1219 for (auto& iter : _featureInfo) {
1220 iter.second->setVisited(false);
1221 }
1222 for (auto& iter : _featureInfoOrigin) {
1223 iter.second->setVisited(false);
1224 }
1225 std::vector<VARP> inputs(mInputNames.size());
1226 auto netInfo = _module->getInfo();
1227 if (_inputType == Helper::SEQUENCE) {
1228 inputs = getModuleInputs(file, netInfo, mInputNames);
1229 } else {
1230 inputs.resize(1);
1231 inputs[0] = _Input(mInputShape[mInputNames[0]], netInfo->inputs[0].order, netInfo->inputs[0].type);
1232 Helper::preprocessInput(_process.get(), _preprocessConfig, file, (MNN::Tensor*)inputs[0]->getTensor(), _inputType, inputs[0]);
1233 }
1234 MNN::TensorCallBackWithInfo before = [&](const std::vector<MNN::Tensor*>& nTensors,
1235 const MNN::OperatorInfo* info) {
1236 if (info->type() == "Raster") {
1237 return true;
1238 }
1239 for (auto t : nTensors) {
1240 auto weakPtr = std::weak_ptr<Tensor::InsideDescribe::NativeInsideDescribe>(TensorUtils::getDescribeOrigin(t)->mContent);
1241 if (_featureInfo.find(weakPtr) != _featureInfo.end()) {
1242 if (_featureInfo[weakPtr]->visited() == false) {
1243 auto dequantFeatureAndOverflowRatio = _featureInfo[weakPtr]->fakeQuantFeature();
1244 fakeQuantedFeatures[_featureInfo[weakPtr]->name()] = dequantFeatureAndOverflowRatio.first;
1245 overflowRatiosMap[_featureInfo[weakPtr]->name()].emplace_back(dequantFeatureAndOverflowRatio.second);
1246 }
1247 }
1248 }
1249 return true;
1250 };
1251 MNN::TensorCallBackWithInfo after = [&](const std::vector<MNN::Tensor*>& nTensors,
1252 const MNN::OperatorInfo* info) {
1253 for (auto t : nTensors) {
1254 auto weakPtr = std::weak_ptr<Tensor::InsideDescribe::NativeInsideDescribe>(TensorUtils::getDescribeOrigin(t)->mContent);
1255 if (_featureInfo.find(weakPtr) != _featureInfo.end()) {
1256 if (_featureInfo[weakPtr]->visited() == false) {
1257 auto dequantFeatureAndOverflowRatio = _featureInfo[weakPtr]->fakeQuantFeature();
1258 fakeQuantedFeatures[_featureInfo[weakPtr]->name()] = dequantFeatureAndOverflowRatio.first;
1259 overflowRatiosMap[_featureInfo[weakPtr]->name()].emplace_back(dequantFeatureAndOverflowRatio.second);
1260 }
1261 }
1262 }
1263 return true;
1264 };
1265
1266 MNN::TensorCallBackWithInfo beforeOrigin = [&](const std::vector<MNN::Tensor*>& nTensors,

Callers

nothing calls this directly

Calls 15

getModuleInputsFunction · 0.85
_InputFunction · 0.85
setVisitedMethod · 0.80
fakeQuantFeatureMethod · 0.80
computeDistanceMethod · 0.80
setCallBackMethod · 0.80
sizeMethod · 0.45
getInfoMethod · 0.45
resizeMethod · 0.45
getMethod · 0.45
getTensorMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected