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

Method fakeQuantFeature

tools/quantization/TensorStatistic.cpp:279–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277}
278
279std::pair<std::vector<float>, float> TensorStatistic::fakeQuantFeature() {
280 const int count = mOriginTensor->elementSize();
281 const float bound = mFeatureClampValue;
282 float* originData = mOriginTensor->host<float>();
283 const float scale = mScale;
284 std::vector<float> fakeQuantedFeature;
285 int overflowCount = 0;
286
287 for (int i = 0; i < count; i++) {
288 float dataQuant = std::roundf(originData[i] / scale) + mZeroPoint;
289 dataQuant = std::fmin(bound, std::fmax(-bound, dataQuant));
290 float dataDequant = (dataQuant - mZeroPoint) * scale;
291
292 originData[i] = dataDequant;
293 fakeQuantedFeature.emplace_back(dataDequant);
294
295 if (std::fabs(std::fabs(dataQuant) - bound) < 1e-6) {
296 overflowCount++;
297 }
298 }
299
300 float overflowRatio = overflowCount / float(count);
301 auto result = std::make_pair(fakeQuantedFeature, overflowRatio);
302
303 mVisited = true;
304 return result;
305}
306
307float TensorStatistic::computeDistance(std::vector<float> fakeQuantedFeature) {
308 const int count = mOriginTensor->elementSize();

Callers 1

_computeQuantErrorMethod · 0.80

Calls 3

fminFunction · 0.85
fmaxFunction · 0.85
fabsFunction · 0.85

Tested by

no test coverage detected