Skip to content

Commit

Permalink
Merge pull request #3048 from alibaba/feature/bugfix
Browse files Browse the repository at this point in the history
MNN:Bugfix: Fix bug for dynammic quant nan for same value input
  • Loading branch information
jxt1234 authored Oct 11, 2024
2 parents 5340db9 + 9d2b843 commit 470c173
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions source/backend/cpu/compute/ConvInt8TiledExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,15 @@ ErrorCode DenseConvInt8TiledExecutor::onExecute(const std::vector<Tensor*>& inpu

/* Dynamic quant */
float range = maxVal - minVal;
quantscale = 255.0f / range;
dequantscale = range / 255.0f;
zeropoint = roundf(-minVal * 255.f / range) - 128.0f;
if (fabs(range) < 1e-7) {
zeropoint = maxVal;
quantscale = 1.0f;
dequantscale = 1.0f;
} else {
quantscale = 255.0f / range;
dequantscale = range / 255.0f;
zeropoint = roundf(-minVal * 255.f / range) - 128.0f;
}
std::vector<float>qsVec(PackUnit, quantscale);
auto sizeDiv = UP_DIV(inputsize, PackUnit);
int inputPlane = input->batch() * mIm2ColParamter.iw * mIm2ColParamter.ih;
Expand Down

0 comments on commit 470c173

Please sign in to comment.