Skip to content

Commit

Permalink
MNN:Bugfix: Fix bug for dynammic quant nan for same value input
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaying committed Oct 11, 2024
1 parent a3bba4f commit 9d2b843
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 9d2b843

Please sign in to comment.