OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
ReduceSum LPT issue with different precision (#33162)
Nazanin Beheshtib79843901092
diff --git a/src/common/low_precision_transformations/src/reduce_sum.cpp b/src/common/low_precision_transformations/src/reduce_sum.cppindex 49d812c6297..dd8b0192218 100644--- a/src/common/low_precision_transformations/src/reduce_sum.cpp+++ b/src/common/low_precision_transformations/src/reduce_sum.cpp@@ -70,12 +70,14 @@ void ReduceSumTransformation::changeDequantizationValues(}// (a1 - s) + (a2 - s) + ... + (an - s) = (a1 + a2 + ... + an) - n * s- const auto reductionSizeConstant = ov::opset1::Constant::create(deqPrecision, Shape{}, { static_cast<float>(reductionSize) });- OPENVINO_ASSERT(deqPrecision == dequantization.subtract->get_input_element_type(0),- "dequantization precision ", deqPrecision,- " differs from zero point 0 input ", dequantization.subtract->get_input_element_type(0));+ // Note: since original shift may be in low precision+ // (in which we can't compute multiplication without accuracy loss because of overflow),+ // we use precision of multiply constant (which is always float) for new shift computation+ const auto& newShiftPrecision = dequantization.multiplyConstant->get_element_type();+ const auto reductionSizeConstant = ov::opset1::Constant::create(newShiftPrecision, Shape{}, { static_cast<float>(reductionSize) });+const auto result = fold<ov::opset1::Multiply>(- foldConvert(dequantization.subtractConstant, deqPrecision),+ foldConvert(dequantization.subtractConstant, newShiftPrecision),reductionSizeConstant);replace_node(diff --git a/src/common/low_precision_transformations/tests/reduce_sum_transformation.cpp b/src/common/low_precision_transformations/tests/reduce_sum_transformation.cppindex 85e4e5636a0..aa860e2caeb 100644--- a/src/common/low_precision_transformations/tests/reduce_sum_transformation.cpp+++ b/src/common/low_precision_transformations/tests/reduce_sum_transformation.cpp@@ -389,6 +389,29 @@ namespace testValues3 {{{0.1f, 1.f, 10.f}, ov::element::f32, {1, 3, 1, 1}}}}+ },+ {+ LayerTransformation::createParamsU8I8(),+ {0},+ true,+ {+ ov::element::i8,+ {+ {ov::element::f16},+ {{40.f}, ov::element::f16, {}, false, {}, ov::element::f16, true},+ {{0.1f}, ov::element::f16, {}}+ }+ },+ {+ ov::element::i8,+ {},+ ov::element::f16,+ {+ {},+ {{160.f}, ov::element::f16, {}},+ {{0.1f}, ov::element::f16, {}}+ }+ }}};