From b713dc5aa3da76e2244cd4df9715a4fb2b2545ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Kot=C5=82owski?= Date: Tue, 5 Jul 2022 09:42:02 +0200 Subject: [PATCH] [BUGFIX] Fix DNNL requantize operator overflow error (#21079) * Fix DNNL requantize operator overflow error * Update src/operator/quantization/dnnl/dnnl_requantize-inl.h Co-authored-by: bartekkuncer --- src/operator/quantization/dnnl/dnnl_requantize-inl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/operator/quantization/dnnl/dnnl_requantize-inl.h b/src/operator/quantization/dnnl/dnnl_requantize-inl.h index 3095b87bd4ad..e2009d65081c 100644 --- a/src/operator/quantization/dnnl/dnnl_requantize-inl.h +++ b/src/operator/quantization/dnnl/dnnl_requantize-inl.h @@ -132,7 +132,8 @@ static void DNNLRequantizeForward(const nnvm::NodeAttrs& attrs, data_min = data_mins[i]; } float src_range = MinAbs(MinValue(), MaxValue()); - SrcDType data_range = MaxAbs(data_min, data_max); + // MaxAbs is not used here as it converts data to float what could cause overflow errors. + SrcDType data_range = std::max(std::abs(data_min), std::abs(data_max)); float data_scale = MaxAbs(*inputs[1].data().dptr(), *inputs[2].data().dptr()); real_range = data_range * data_scale / src_range; }