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] Fix out-of-bounds access on low-rank dequantization constants (#38702)
mingmingtasd7e507a4ca9a7
diff --git a/src/common/low_precision_transformations/src/gather.cpp b/src/common/low_precision_transformations/src/gather.cppindex c19b5bf41dd..4f3a60d1494 100644--- a/src/common/low_precision_transformations/src/gather.cpp+++ b/src/common/low_precision_transformations/src/gather.cpp@@ -38,7 +38,8 @@ std::shared_ptr<opset1::Constant> gatherDeqConstant(const auto rank = gather->get_input_partial_shape(0).size();if (rank != constantShape.size()) {// case when constShape without batch- while ((constantShape.size() > 1) && (constantShape.size() < rank)) {+ // Pad rank-1 per-channel constants too, else the normalizedAxis indexing below goes out of bounds.+ while (constantShape.size() < rank) {constantShape.insert(constantShape.begin(), 1);}const auto newConstant = fold<ov::opset1::Broadcast>(@@ -52,7 +53,7 @@ std::shared_ptr<opset1::Constant> gatherDeqConstant(ov::util::try_normalize_axis(axis, gather->get_input_partial_shape(0).rank(), *gather);// Dequantization channel matches with gather axis- if (constantShape[normalizedAxis] != 1ul) {+ if (normalizedAxis < constantShape.size() && constantShape[normalizedAxis] != 1ul) {const auto gather1 = ov::as_type_ptr<ov::opset1::Gather>(gather);if (gather1) {const auto output = fold<ov::opset1::Gather>(@@ -171,7 +172,8 @@ bool GatherTransformation::canBeTransformed(const std::shared_ptr<Node>& operatiauto constantShape = dequantizationConstant->get_shape();const auto rank = operation->get_input_partial_shape(0).size();if (rank != constantShape.size()) {- while ((constantShape.size() > 1) && (constantShape.size() < rank)) {+ // Pad rank-1 (per-channel) constants too, matching gatherDeqConstant above.+ while (constantShape.size() < rank) {constantShape.insert(constantShape.begin(), 1);}}@@ -179,7 +181,7 @@ bool GatherTransformation::canBeTransformed(const std::shared_ptr<Node>& operaticonst size_t normalizedAxis =ov::util::try_normalize_axis(axis, operation->get_input_partial_shape(0).rank(), *operation);- if (constantShape[normalizedAxis] != 1ul) {+ if (normalizedAxis < constantShape.size() && constantShape[normalizedAxis] != 1ul) {const auto indicesConstant = ov::as_type_ptr<opset1::Constant>(operation->get_input_node_shared_ptr(1));if (indicesConstant == nullptr)return false;diff --git a/src/common/low_precision_transformations/src/network_helper.cpp b/src/common/low_precision_transformations/src/network_helper.cppindex dd271573779..c732f1a1138 100644--- a/src/common/low_precision_transformations/src/network_helper.cpp+++ b/src/common/low_precision_transformations/src/network_helper.cpp@@ -1573,16 +1573,46 @@ NetworkHelper::InsertDequantizationResult NetworkHelper::moveDequantizationBeforstd::vector<std::vector<std::shared_ptr<ov::opset1::Constant>>> multiplyConstants, subtractConstants;if (is_type<ov::opset1::Concat>(operation)) {const auto concatNode = as_type_ptr<ov::opset1::Concat>(operation);- int64_t axis = -1;- if (concatNode->get_output_partial_shape(0).rank().is_static()) {- const auto rank = concatNode->get_output_partial_shape(0).rank().get_length();- axis = ov::util::normalize(concatNode->get_axis(), rank);- }- if (dequantization.multiply && dequantization.multiplyConstant->get_shape().size() > 1 && dequantization.multiplyConstant->get_shape()[axis] != 1) {- multiplyConstants = NetworkHelper::splitConstantsBeforeConcat(operation, { dequantization.multiplyConstant });- }- if (dequantization.subtract && dequantization.subtractConstant->get_shape().size() > 1 && dequantization.subtractConstant->get_shape()[axis] != 1) {- subtractConstants = NetworkHelper::splitConstantsBeforeConcat(operation, { dequantization.subtractConstant });+ const auto rank = concatNode->get_output_partial_shape(0).rank();+ const auto isScalar = [](const std::shared_ptr<ov::opset1::Constant>& constant) {+ return constant == nullptr || ov::shape_size(constant->get_shape()) == 1;+ };+ // Without a static rank the Concat axis can't be mapped onto a per-channel constant, so it is+ // unknown whether the constant has to be split per input.+ OPENVINO_ASSERT(rank.is_static() ||+ (isScalar(dequantization.multiplyConstant) && isScalar(dequantization.subtractConstant)),+ "Dequantization constants must be scalar to be moved before a dynamic-rank Concat ",+ concatNode->get_friendly_name());++ if (rank.is_static()) {+ const auto concatRank = static_cast<size_t>(rank.get_length());+ const auto axis = static_cast<size_t>(ov::util::normalize(concatNode->get_axis(), rank.get_length()));+ // The constant broadcasts against the Concat output aligned to the trailing dims: split it only+ // if its dim aligned with the Concat axis isn't broadcast, after padding it to the Concat rank.+ const auto splitIfNeeded = [&](const std::shared_ptr<ov::opset1::Constant>& constant) {+ std::vector<std::vector<std::shared_ptr<ov::opset1::Constant>>> splitConstants;+ if (isScalar(constant)) {+ return splitConstants;+ }+ const auto& constantShape = constant->get_shape();+ OPENVINO_ASSERT(constantShape.size() <= concatRank,+ "Dequantization constant rank exceeds the rank of Concat ",+ concatNode->get_friendly_name());+ const size_t offset = concatRank - constantShape.size();+ if (axis < offset || constantShape[axis - offset] == 1) {+ return splitConstants;+ }+ Shape paddedShape(offset, 1ul);+ paddedShape.insert(paddedShape.end(), constantShape.begin(), constantShape.end());+ const auto paddedConstant = std::make_shared<ov::opset1::Constant>(*constant, paddedShape);+ return NetworkHelper::splitConstantsBeforeConcat(operation, {paddedConstant});+ };+ if (dequantization.multiply) {+ multiplyConstants = splitIfNeeded(dequantization.multiplyConstant);+ }+ if (dequantization.subtract) {+ subtractConstants = splitIfNeeded(dequantization.subtractConstant);+ }}} else {multiplyConstants = {{ dequantization.multiplyConstant }};diff --git a/src/common/low_precision_transformations/src/reshape.cpp b/src/common/low_precision_transformations/src/reshape.cppindex 050be55f9a5..cf88d611074 100644--- a/src/common/low_precision_transformations/src/reshape.cpp+++ b/src/common/low_precision_transformations/src/reshape.cpp@@ -80,19 +80,34 @@ void reshapeDequantizationConstant(const std::shared_ptr<ov::opset1::Reshape>& rauto const reshapeInputRank = reshape->get_input_partial_shape(0).rank();assert(reshapeInputRank.is_static());- if (constantShape.size() > 1ul) {- while (constantShape.size() < static_cast<size_t>(reshapeInputRank.get_length())) {- constantShape.insert(constantShape.begin(), 1ul);- }+ // Left-pad up to the Reshape input rank: rank-1 per-channel constants must be padded too,+ // otherwise the channel indexing below goes out of bounds.+ while (constantShape.size() < static_cast<size_t>(reshapeInputRank.get_length())) {+ constantShape.insert(constantShape.begin(), 1ul);+ }++ // Materialize the padded shape on the constant itself, so the broadcast helper below+ // sees a consistent rank instead of the original (possibly rank-1) shape.+ std::shared_ptr<ov::opset1::Constant> paddedConstant = originalConstant;+ if (originalConstant->get_shape().size() != constantShape.size()) {+ paddedConstant = ov::as_type_ptr<ov::opset1::Constant>(fold<ov::opset1::Reshape>(+ originalConstant,+ ov::opset1::Constant::create(element::i32, Shape{ constantShape.size() }, constantShape),+ false));}const auto reshapeOutputPShape = reshape->get_output_partial_shape(0);const auto reshapeOutputRank = reshapeOutputPShape.rank();assert(reshapeOutputRank.is_static());- assert(reshapeOutputRank.get_length() >= 2);- assert(reshapeOutputPShape[1].is_static());- assert(static_cast<size_t>(reshapeOutputPShape[1].get_length()) >= constantShape[1]);- assert(reshapeOutputPShape[1].get_length() % constantShape[1] == 0);+ // Explicit guard: the equivalent asserts are compiled out under NDEBUG.+ if (reshapeOutputRank.is_dynamic() || reshapeOutputRank.get_length() < 2 ||+ reshapeOutputPShape[1].is_dynamic() || constantShape.size() < 2ul) {+ return;+ }+ if ((static_cast<size_t>(reshapeOutputPShape[1].get_length()) < constantShape[1]) ||+ (reshapeOutputPShape[1].get_length() % constantShape[1] != 0)) {+ return;+ }const size_t dimensionsToBroadcast = reshapeOutputPShape[1].get_length() / constantShape[1];if (dimensionsToBroadcast == 0ul) {return;@@ -119,7 +134,7 @@ void reshapeDequantizationConstant(const std::shared_ptr<ov::opset1::Reshape>& rreturn fold<ov::opset1::Broadcast>(constant, targetShapeConstant);};- const std::shared_ptr<Node> broadcastedConstant = getBCastedConst(originalConstant, dimensionsToBroadcast);+ const std::shared_ptr<Node> broadcastedConstant = getBCastedConst(paddedConstant, dimensionsToBroadcast);std::vector<int> newReshapeConstValues(reshapeOutputRank.get_length(), 1ul);newReshapeConstValues[1] = static_cast<int>(reshapeOutputPShape[1].get_length());diff --git a/src/common/low_precision_transformations/tests/gather_transformation.cpp b/src/common/low_precision_transformations/tests/gather_transformation.cppindex 14e29b60e32..5b3d95e06b5 100644--- a/src/common/low_precision_transformations/tests/gather_transformation.cpp+++ b/src/common/low_precision_transformations/tests/gather_transformation.cpp@@ -185,6 +185,22 @@ const std::vector<GatherTransformationTestValues> testValues = {{{}, {}, {}},ov::element::u8,{{ov::element::f32}, {{64}, ov::element::f32, {}}, {{0.2f}, ov::element::f32, {}}}}},+ // U8: rank-1 (model-declared, per-channel) dequantization constant, gather axis at the last+ // dimension == channel. The constant reaches LPT unpadded, so the transform must left-pad it+ // up to the data rank instead of indexing the dequantization shape out of bounds.+ {{1},+ {0},+ {2}, // axis: last dimension+ std::int64_t{0},+ LayerTransformation::createParamsU8I8(),+ {ov::element::u8,+ {{ov::element::f32},+ {{128, 64, 32, 16}, ov::element::f32, ov::Shape{4}},+ {{0.4f, 0.3f, 0.2f, 0.1f}, ov::element::f32, ov::Shape{4}}}},+ {ov::element::u8,+ {{}, {}, {}},+ ov::element::u8,+ {{ov::element::f32}, {{128}, ov::element::f32, {}}, {{0.4f}, ov::element::f32, {}}}}},// U8: per-channel quantization, gather axis and channel doesn't match{{1},{0},diff --git a/src/common/low_precision_transformations/tests/move_dequantization_before_transformation.cpp b/src/common/low_precision_transformations/tests/move_dequantization_before_transformation.cppnew file mode 100644index 00000000000..13996571daa--- /dev/null+++ b/src/common/low_precision_transformations/tests/move_dequantization_before_transformation.cpp@@ -0,0 +1,172 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <gtest/gtest.h>++#include <memory>+#include <sstream>+#include <string>+#include <vector>++#include "common_test_utils/ov_test_utils.hpp"+#include "layer_transformation.hpp"+#include "low_precision/network_helper.hpp"+#include "openvino/op/concat.hpp"+#include "ov_lpt_models/common/dequantization_operations.hpp"+#include "ov_lpt_models/move_dequantization_before.hpp"+#include "transformations/init_node_info.hpp"+#include "transformations/utils/utils.hpp"++using namespace testing;+using namespace ov::pass;+using namespace ov::builder::subgraph;++namespace {++std::shared_ptr<ov::Node> getConcat(const std::shared_ptr<ov::Model>& model) {+ for (const auto& op : model->get_ordered_ops()) {+ if (ov::is_type<ov::op::v0::Concat>(op)) {+ return op;+ }+ }+ return nullptr;+}++void moveDequantizationBeforeConcat(const std::shared_ptr<ov::Model>& model) {+ const auto concat = getConcat(model);+ OPENVINO_ASSERT(concat != nullptr, "Concat is not found");+ const auto dequantization = ov::pass::low_precision::NetworkHelper::getDequantizationBelow(concat);+ ov::pass::low_precision::NetworkHelper::moveDequantizationBefore(concat, dequantization, true);+}++} // namespace++class MoveDequantizationBeforeTransformationTestValues {+public:+ ov::PartialShape inputShape;+ std::int64_t axis;+ DequantizationOperations actual;+ // dequantization expected in front of each Concat input+ std::vector<DequantizationOperations> expected;+};++class MoveDequantizationBeforeTransformation+ : public LayerTransformation,+ public testing::WithParamInterface<MoveDequantizationBeforeTransformationTestValues> {+public:+ void SetUp() override {+ const auto testValues = GetParam();+ actualFunction = MoveDequantizationBeforeFunction::getOriginal(ov::element::u8,+ testValues.inputShape,+ testValues.axis,+ testValues.actual);+ moveDequantizationBeforeConcat(actualFunction);++ referenceFunction = MoveDequantizationBeforeFunction::getReference(ov::element::u8,+ testValues.inputShape,+ testValues.axis,+ testValues.expected);+ }++ static std::string getTestCaseName(testing::TestParamInfo<MoveDequantizationBeforeTransformationTestValues> obj) {+ const auto testValues = obj.param;++ std::ostringstream result;+ result << testValues.inputShape << "_axis_" << testValues.axis << "_" << testValues.actual;+ return result.str();+ }+};++TEST_P(MoveDequantizationBeforeTransformation, CompareFunctions) {+ actualFunction->validate_nodes_and_infer_types();+ auto res = compare_functions(actualFunction, referenceFunction, true, false, true);+ ASSERT_TRUE(res.first) << res.second;++ ASSERT_TRUE(LayerTransformation::allNamesAreUnique(actualFunction)) << "Not all names are unique";+}++namespace {+const std::vector<MoveDequantizationBeforeTransformationTestValues> testValues = {+ // per-channel constants of the Concat rank, split by the Concat axis+ {+ {1, 2, 4, 4},+ 1,+ {{ov::element::f32},+ {{1.f, 2.f, 3.f, 4.f}, ov::element::f32, {1, 4, 1, 1}},+ {{0.1f, 0.2f, 0.3f, 0.4f}, ov::element::f32, {1, 4, 1, 1}}},+ {+ {{ov::element::f32},+ {{1.f, 2.f}, ov::element::f32, {1, 2, 1, 1}},+ {{0.1f, 0.2f}, ov::element::f32, {1, 2, 1, 1}}},+ {{ov::element::f32},+ {{3.f, 4.f}, ov::element::f32, {1, 2, 1, 1}},+ {{0.3f, 0.4f}, ov::element::f32, {1, 2, 1, 1}}},+ },+ },+ // lower-rank constants broadcast against the Concat aligned to the trailing dims: the+ // constant's last dim is the Concat axis, so it is padded to the Concat rank and split+ {+ {1, 1, 2, 3},+ 3,+ {{ov::element::f32},+ {{1.f, 2.f, 3.f, 4.f, 5.f, 6.f}, ov::element::f32, {1, 6}},+ {{0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f}, ov::element::f32, {1, 6}}},+ {+ {{ov::element::f32},+ {{1.f, 2.f, 3.f}, ov::element::f32, {1, 1, 1, 3}},+ {{0.1f, 0.2f, 0.3f}, ov::element::f32, {1, 1, 1, 3}}},+ {{ov::element::f32},+ {{4.f, 5.f, 6.f}, ov::element::f32, {1, 1, 1, 3}},+ {{0.4f, 0.5f, 0.6f}, ov::element::f32, {1, 1, 1, 3}}},+ },+ },+ // lower-rank constants broadcast along the Concat axis: no split+ {+ {1, 1, 2, 6},+ 1,+ {{ov::element::f32},+ {{1.f, 2.f, 3.f, 4.f, 5.f, 6.f}, ov::element::f32, {1, 6}},+ {{0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f}, ov::element::f32, {1, 6}}},+ {+ {{ov::element::f32},+ {{1.f, 2.f, 3.f, 4.f, 5.f, 6.f}, ov::element::f32, {1, 6}},+ {{0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f}, ov::element::f32, {1, 6}}},+ {{ov::element::f32},+ {{1.f, 2.f, 3.f, 4.f, 5.f, 6.f}, ov::element::f32, {1, 6}},+ {{0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f}, ov::element::f32, {1, 6}}},+ },+ },+ // dynamic-rank Concat with scalar constants: no split needed+ {+ ov::PartialShape::dynamic(),+ 1,+ {{ov::element::f32}, {2.f}, {0.2f}},+ {+ {{ov::element::f32}, {2.f}, {0.2f}},+ {{ov::element::f32}, {2.f}, {0.2f}},+ },+ },+};++INSTANTIATE_TEST_SUITE_P(smoke_LPT,+ MoveDequantizationBeforeTransformation,+ ::testing::ValuesIn(testValues),+ MoveDequantizationBeforeTransformation::getTestCaseName);+} // namespace++// With a dynamic rank the Concat axis can't be mapped onto a non-scalar constant, so whether it has+// to be split per input is unknown.+TEST(LPT, MoveDequantizationBeforeTransformationDynamicRankNegative) {+ const std::vector<DequantizationOperations> dequantizations = {+ {{ov::element::f32}, {2.f}, {{0.1f, 0.2f}, ov::element::f32, {2, 1}}},+ {{ov::element::f32}, {{1.f, 2.f}, ov::element::f32, {2, 1}}, {0.2f}},+ };+ for (const auto& dequantization : dequantizations) {+ const auto model = MoveDequantizationBeforeFunction::getOriginal(ov::element::u8,+ ov::PartialShape::dynamic(),+ 1,+ dequantization);+ EXPECT_THROW(moveDequantizationBeforeConcat(model), ov::Exception) << dequantization;+ }+}diff --git a/src/common/low_precision_transformations/tests/move_fake_quantize_transformation.cpp b/src/common/low_precision_transformations/tests/move_fake_quantize_transformation.cppindex 498ba40529b..98b227e9e41 100644--- a/src/common/low_precision_transformations/tests/move_fake_quantize_transformation.cpp+++ b/src/common/low_precision_transformations/tests/move_fake_quantize_transformation.cpp@@ -343,6 +343,30 @@ const std::vector<MoveFakeQuantizeTransformationTestValues> testValues = {{},{},}},+ // Q/DQ concat by the last axis with rank-2 dequantization constants+ {LayerTransformation::createParamsU8I8(),+ false,+ 3,+ {+ 2,+ {},+ {},+ {},+ "",+ {256ul, {}, {0.f}, {2.55f}, {0.f}, {2.55f}},+ {ov::element::u8},+ {{element::f32}, {{0.01f}, element::f32, {1, 1}}, {{0.01f}, element::f32, {1, 1}}},+ },+ {+ 2,+ {{256ul, {}, {0.f}, {2.55f}, {0.f}, {2.55f}}},+ {ov::element::u8},+ {{element::f32}, {{0.01f}, element::f32, {1, 1}}, {{0.01f}, element::f32, {1, 1}}},+ "",+ {},+ {},+ {},+ }},};INSTANTIATE_TEST_SUITE_P(smoke_LPT,diff --git a/src/common/low_precision_transformations/tests/reshape_transformation.cpp b/src/common/low_precision_transformations/tests/reshape_transformation.cppindex 087352fe71a..d1fb8671105 100644--- a/src/common/low_precision_transformations/tests/reshape_transformation.cpp+++ b/src/common/low_precision_transformations/tests/reshape_transformation.cpp@@ -272,6 +272,18 @@ const std::vector<ReshapeTransformationTestValues> testValues = {{{ov::element::f32}, {{0.f, 128.f, 255.f}, ov::element::f32}, {{0.1f, 0.2f, 0.3f}}},ov::element::f32,{{}, {}, {}}}},+ // U8: rank-1 (per-channel) dequantization constant: left-pad it up to the Reshape input rank+ // instead of indexing the constant out of bounds. A model-declared rank-1 constant {C} reaches+ // LPT unpadded here (AlignEltwiseInputRanks does not run in this isolated harness), so the+ // transform must normalize the rank itself.+ {{1, 3},+ {1, 3, 1, 1},+ LayerTransformation::createParamsU8I8(),+ {ov::element::u8, {{ov::element::f32}, {}, {{0.1f, 0.2f, 0.3f}, ov::element::f32, ov::Shape{3}}}},+ {ov::element::u8,+ {{}, {}, {}},+ ov::element::u8,+ {{ov::element::f32}, {}, {{0.1f, 0.2f, 0.3f}, ov::element::f32, {1, 3, 1, 1}}}}},// empty: FP32{{1, 3, 4, 8},{12, -1},diff --git a/src/common/low_precision_transformations/tests/sources.cmake b/src/common/low_precision_transformations/tests/sources.cmakeindex d953c9c6efb..a2de985d7ff 100644--- a/src/common/low_precision_transformations/tests/sources.cmake+++ b/src/common/low_precision_transformations/tests/sources.cmake@@ -68,6 +68,7 @@ set(LP_TRANSFORMATIONS_TESTS_SRCS${CMAKE_CURRENT_SOURCE_DIR}/mat_mul_with_constant_transformation.cpp${CMAKE_CURRENT_SOURCE_DIR}/max_pool_transformation.cpp${CMAKE_CURRENT_SOURCE_DIR}/move_dequantization_after_transformation.cpp+ ${CMAKE_CURRENT_SOURCE_DIR}/move_dequantization_before_transformation.cpp${CMAKE_CURRENT_SOURCE_DIR}/move_fake_quantize_transformation.cpp${CMAKE_CURRENT_SOURCE_DIR}/multiply_partial_transformation.cpp${CMAKE_CURRENT_SOURCE_DIR}/multiply_to_group_convolution_transformation.cppdiff --git a/src/tests/ov_helpers/ov_lpt_models/include/ov_lpt_models/move_dequantization_before.hpp b/src/tests/ov_helpers/ov_lpt_models/include/ov_lpt_models/move_dequantization_before.hppnew file mode 100644index 00000000000..d96e59dd13c--- /dev/null+++ b/src/tests/ov_helpers/ov_lpt_models/include/ov_lpt_models/move_dequantization_before.hpp@@ -0,0 +1,36 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <cstdint>+#include <memory>+#include <vector>++#include "ov_lpt_models/common/dequantization_operations.hpp"++namespace ov {+namespace builder {+namespace subgraph {++class MoveDequantizationBeforeFunction {+public:+ // Two inputs of inputShape concatenated along axis, followed by dequantization.+ static std::shared_ptr<ov::Model> getOriginal(+ const ov::element::Type precision,+ const ov::PartialShape& inputShape,+ const std::int64_t axis,+ const ov::builder::subgraph::DequantizationOperations& dequantization);++ // A Concat along axis with dequantizationsBefore[i] in front of its i-th input.+ static std::shared_ptr<ov::Model> getReference(+ const ov::element::Type precision,+ const ov::PartialShape& inputShape,+ const std::int64_t axis,+ const std::vector<ov::builder::subgraph::DequantizationOperations>& dequantizationsBefore);+};++} // namespace subgraph+} // namespace builder+} // namespace ovdiff --git a/src/tests/ov_helpers/ov_lpt_models/src/move_dequantization_before.cpp b/src/tests/ov_helpers/ov_lpt_models/src/move_dequantization_before.cppnew file mode 100644index 00000000000..7ac949d7d44--- /dev/null+++ b/src/tests/ov_helpers/ov_lpt_models/src/move_dequantization_before.cpp@@ -0,0 +1,52 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "ov_lpt_models/move_dequantization_before.hpp"++#include "openvino/op/concat.hpp"+#include "openvino/op/parameter.hpp"+#include "openvino/op/result.hpp"+#include "ov_lpt_models/common/builders.hpp"++namespace ov {+namespace builder {+namespace subgraph {++std::shared_ptr<ov::Model> MoveDequantizationBeforeFunction::getOriginal(+ const ov::element::Type precision,+ const ov::PartialShape& inputShape,+ const std::int64_t axis,+ const ov::builder::subgraph::DequantizationOperations& dequantization) {+ const auto input1 = std::make_shared<ov::op::v0::Parameter>(precision, inputShape);+ const auto input2 = std::make_shared<ov::op::v0::Parameter>(precision, inputShape);+ const auto concat = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{input1, input2}, axis);+ const auto deq = makeDequantization(concat, dequantization);++ return std::make_shared<ov::Model>(ov::ResultVector{std::make_shared<ov::op::v0::Result>(deq)},+ ov::ParameterVector{input1, input2},+ "MoveDequantizationBeforeFunction");+}++std::shared_ptr<ov::Model> MoveDequantizationBeforeFunction::getReference(+ const ov::element::Type precision,+ const ov::PartialShape& inputShape,+ const std::int64_t axis,+ const std::vector<ov::builder::subgraph::DequantizationOperations>& dequantizationsBefore) {+ ov::ParameterVector inputs;+ ov::OutputVector concatInputs;+ for (const auto& dequantization : dequantizationsBefore) {+ const auto input = std::make_shared<ov::op::v0::Parameter>(precision, inputShape);+ inputs.push_back(input);+ concatInputs.push_back(makeDequantization(input, dequantization));+ }+ const auto concat = std::make_shared<ov::op::v0::Concat>(concatInputs, axis);++ return std::make_shared<ov::Model>(ov::ResultVector{std::make_shared<ov::op::v0::Result>(concat)},+ inputs,+ "MoveDequantizationBeforeFunction");+}++} // namespace subgraph+} // namespace builder+} // namespace ov