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
[LPT] Remove mandatory weight folding in ConvolutionTransformation (#35969)
Mikhail Dvoretckiia9db3aeff547
diff --git a/src/common/low_precision_transformations/src/convolution.cpp b/src/common/low_precision_transformations/src/convolution.cppindex 0733c397fef..989eeb826c8 100644--- a/src/common/low_precision_transformations/src/convolution.cpp+++ b/src/common/low_precision_transformations/src/convolution.cpp@@ -70,27 +70,7 @@ bool ConvolutionTransformation::transform(ov::pass::pattern::Matcher &m) {auto convolution = m.get_match_root();if (!canConvolutionBeTransformed(convolution, defaultPrecisions)) {- const auto weightInput = convolution->get_input_node_shared_ptr(1);- const auto reshapeFromWeights = ov::as_type_ptr<ov::opset1::Reshape>(weightInput);- FakeQuantizeDequantization dequantization = reshapeFromWeights == nullptr ?- NetworkHelper::getDequantization(convolution, defaultPrecisions, 1ul) :- NetworkHelper::getDequantization(reshapeFromWeights, defaultPrecisions);- if (dequantization.empty()) {- const auto fqOnWeights = getFakeQuantizeOnWeights(convolution);- std::shared_ptr<ov::Node> resultConstant = NetworkHelper::fold_fake_quantize(fqOnWeights);- if (reshapeFromWeights != nullptr) {- resultConstant = fold_reshape<ov::opset1::Reshape>(- resultConstant,- reshapeFromWeights->input_value(1),- false);- }- if (ov::is_type<ov::opset1::Constant>(resultConstant)) {- replace_node(weightInput, resultConstant);- }- } else {- NetworkHelper::foldDequantization(dequantization.multiply, 0, defaultPrecisions, true);- }- return true;+ return false;}convolution = NetworkHelper::separateInStandaloneBranch(convolution, defaultPrecisions);diff --git a/src/common/low_precision_transformations/tests/convolution_qdq_transformation.cpp b/src/common/low_precision_transformations/tests/convolution_qdq_transformation.cppindex 800f710cdfc..a7908e9beda 100644--- a/src/common/low_precision_transformations/tests/convolution_qdq_transformation.cpp+++ b/src/common/low_precision_transformations/tests/convolution_qdq_transformation.cpp@@ -237,61 +237,6 @@ const std::vector<ConvolutionQDqTransformationTestValues> testValues = {}},- // Actual:- //- // Parameter Constant Constant Constant- // |U8 |U8 |FP32 |I8- // | | | |- // Convert Convert Convert Convert- // \FP32 /FP32 |FP32 /FP32- // \ / | /- // Subtract Constant Subtract Constant- // \FP32 /FP32 |FP32 /FP32- // \ / | /- // Multiply Multiply- // \FP32 /FP32- // \ /- // Convolution- //- // Transformed:- //- // Parameter Constant- // |U8 |U8- // | |- // Convert Convert- // \FP32 /FP32- // \ /- // Subtract Constant- // \FP32 /FP32- // \ /- // Multiply Constant- // \FP32 /FP32- // \ /- // Convolution- {- LayerTransformation::createParamsU8I8().setSupportAsymmetricQuantization(true),- // ActualValues- {- ov::element::u8,- {{ov::element::f32}, { {127.f}, element::f32, {}, false, 1ul, element::u8, true }, { 0.02f }},- {{ov::element::f32}, { {127.f}, element::f32, {}, false, 1ul, element::i8, true }, { 0.03f }},- { std::vector<float>{ 2.f }, ov::element::f32},- {},- ov::element::f32,- {}- },- // ExpectedValues- {- ov::element::u8,- {{ov::element::f32}, { {127.f}, element::f32, {}, false, 1ul, element::u8, true }, { 0.02f }},- {},- { std::vector<float>{ -3.75f }, ov::element::f32},- {},- ov::element::f32,- {}- }- },-// Actual://// Parameter Constant Constant Constant@@ -453,6 +398,32 @@ const std::vector<ConvolutionQDqTransformationTestValues> testValues = {{{}, {}, {{ 0.0006f }, ov::element::f16, {}, false, 1, ov::element::f32}}}},++ // fp32 base weight value [not transformed]+ {+ LayerTransformation::createParamsU8I8().setSupportAsymmetricQuantization(true),+ // ActualValues+ {+ ov::element::u8,+ {{ov::element::f32}, { {127.f}, element::f32, {}, false, 1ul, element::u8, true }, { 0.02f }},+ {{ov::element::f32}, { {127.f}, element::f32, {}, false, 1ul, element::i8, true }, { 0.03f }},+ { std::vector<float>{ 2.f }, ov::element::f32},+ {},+ ov::element::f32,+ {}+ },+ // ExpectedValues+ {+ ov::element::u8,+ {{ov::element::f32}, { {127.f}, element::f32, {}, false, 1ul, element::u8, true }, { 0.02f }},+ {{ov::element::f32}, { {127.f}, element::f32, {}, false, 1ul, element::i8, true }, { 0.03f }},+ { std::vector<float>{ 2.f }, ov::element::f32},+ {},+ ov::element::f32,+ {}+ }+ },+// incorrect zero point on activations [not transformed]{LayerTransformation::createParamsU8I8().setSupportAsymmetricQuantization(true),@@ -482,14 +453,18 @@ const std::vector<ConvolutionQDqTransformationTestValues> testValues = {{ {1000.f}, element::f32, {}, false },{ {0.02f}, element::f32, {}, false }},- {},- { std::vector<float>{ -3.75f }, ov::element::f32},+ {+ { ov::element::f32, false },+ { {127.f}, element::f32, {}, false },+ { {0.03f}, element::f32, {}, false }+ },+ { std::vector<float>{ 2.f }, ov::element::i8},{},ov::element::f32,{}}},- // incorrect zero point on weights [not transformed, weights folded]+ // incorrect zero point on weights [not transformed]{LayerTransformation::createParamsU8I8().setSupportAsymmetricQuantization(true),// ActualValues@@ -518,8 +493,12 @@ const std::vector<ConvolutionQDqTransformationTestValues> testValues = {{ {127.f}, element::f32, {}, false, 1ul, element::u8, true },{ {0.02f}, element::f32, {}, false }},- {},- { std::vector<float>{ -29.94f }, ov::element::f32},+ {+ { ov::element::f32, false },+ { {1000.f}, element::f32, {}, false },+ { {0.03f}, element::f32, {}, false }+ },+ { std::vector<float>{ 2.f }, ov::element::i8},{},ov::element::f32,{}@@ -570,8 +549,12 @@ const std::vector<ConvolutionQDqTransformationTestValues> testValues = {{ {127.f}, element::f32, {}, false, 1ul, element::u8, true },{ {0.02f}, element::f32, {}, false }},- {},- { std::vector<float>{ -3.75 }, ov::element::f32},+ {+ { ov::element::f32, false },+ { {127.f}, element::f32, {}, false, 1ul, element::i8, true },+ { {0.03f}, element::f32, {}, false }+ },+ { std::vector<float>{ 2.f }, ov::element::i8},{},ov::element::f32,{}diff --git a/src/common/low_precision_transformations/tests/convolution_transformation.cpp b/src/common/low_precision_transformations/tests/convolution_transformation.cppindex acaf5983876..604bb59f642 100644--- a/src/common/low_precision_transformations/tests/convolution_transformation.cpp+++ b/src/common/low_precision_transformations/tests/convolution_transformation.cpp@@ -300,10 +300,8 @@ const std::vector<ConvolutionTransformationTestValues> testValues = {{{ 128.f, 0.f, 128.f }, ov::element::f32, { 1, 3, 1, 1 }},{{ 0.02f, 0.01f, 0.03f }, ov::element::f32, {1, 3, 1, 1}}},- op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{ -1.25f }),- {},- ov::element::f32,- {}+ op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{ 2.f }),+ { 255ul, Shape({ 1, 1, 1, 1 }), { 0.f }, { 254.f }, { -1.27f }, { 1.27f } }}},// float input@@ -328,10 +326,8 @@ const std::vector<ConvolutionTransformationTestValues> testValues = {{{ 128.f }, ov::element::f32, { 1, 1, 1, 1 }},{{ 0.02f }, ov::element::f32, {1, 1, 1, 1}}},- op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{ -1.25f }),- {},- ov::element::f32,- {}+ op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{ 2.f }),+ { 255ul, Shape({ 1, 1, 1, 1 }), { 0.f }, { 254.f }, { -1.27f }, { 1.27f } }}},// without dequantization operations@@ -367,11 +363,9 @@ const std::vector<ConvolutionTransformationTestValues> testValues = {// ExpectedValues{ov::element::f32,- {{}, {}, { {0.02f}, element::f32 }},- op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{ -1.25f }),- {},- ov::element::f32,- {}+ {{}, {}, { 0.02f }},+ op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{ 2.f }),+ { 255ul, Shape({ 1, 1, 1, 1 }), { 0.f }, { 254.f }, { -1.27f }, { 1.27f } }}},// without zero point@@ -408,10 +402,8 @@ const std::vector<ConvolutionTransformationTestValues> testValues = {{ov::element::u8,{{element::f32}, { 1000.f }, { {0.02f}, element::f32 }},- op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{ -1.25f }),- {},- ov::element::f32,- {}+ op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{ 2.f }),+ { 255ul, Shape({ 1, 1, 1, 1 }), { 0.f }, { 254.f }, { -1.27f }, { 1.27f } }}},// TODO: uncomment: remove precisionsOnActivations & precisionsOnWeights@@ -471,11 +463,9 @@ const std::vector<ConvolutionTransformationTestValues> testValues = {// ExpectedValues{ov::element::u8,- {{ ov::element::f32 }, { 128.f }, { 0.02f }},- op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{ -1.25f }),- {},- ov::element::f32,- {}+ {{ov::element::f32}, { 128.f }, { 0.02f }},+ op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{ 2.f }),+ { 255ul, Shape({ 1, 1, 1, 1 }), { 0.f }, { 254.f }, { -1.27f }, { 1.27f } }}},// without zero point@@ -491,11 +481,9 @@ const std::vector<ConvolutionTransformationTestValues> testValues = {// ExpectedValues{ov::element::u8,- {{ ov::element::f32 }, {}, { 0.02f }},- op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{ -1.25f }),- {},- ov::element::f32,- {}+ {{ov::element::f32}, {}, { 0.02f }},+ op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{ 2.f }),+ { 255ul, Shape({ 1, 1, 1, 1 }), { 0.f }, { 254.f }, { -1.27f }, { 1.27f } }}},};diff --git a/src/common/low_precision_transformations/tests/group_convolution_transformation.cpp b/src/common/low_precision_transformations/tests/group_convolution_transformation.cppindex 775a4e7794e..523645ae1d6 100644--- a/src/common/low_precision_transformations/tests/group_convolution_transformation.cpp+++ b/src/common/low_precision_transformations/tests/group_convolution_transformation.cpp@@ -378,10 +378,8 @@ const std::vector<GroupConvolutionTestValues> testValuesGroupConv = {{ov::element::f32,{{}, {}, {0.02f}},- op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{-1.25f}),- {},- {},- ov::element::f32,+ op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{2.f}),+ {255ul, Shape({1, 1, 1, 1}), {0.f}, {254.f}, {-1.27f}, {1.27f}},{}}},@@ -864,10 +862,8 @@ const std::vector<GroupConvolutionTestValues> testValuesForDepthWiseConv = {{ov::element::f32,{{}, {}, {0.02f}},- op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{-1.25f}),- {},- {},- ov::element::f32,+ op::v0::Constant::create(ov::element::f32, ov::Shape{}, std::vector<float>{2.f}),+ {255ul, Shape({1, 1, 1, 1}), {0.f}, {254.f}, {-1.27f}, {1.27f}},{}}},