Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[Transformations] Shared low_precision_dequantize decomposition helper (#36058)

Maxim Vafin9a3a705f5115
diff --git a/src/common/transformations/include/openvino/decompositions/low_precision_dequantize.hpp b/src/common/transformations/include/openvino/decompositions/low_precision_dequantize.hpp
new file mode 100644
index 00000000000..84a1a4e23f0
--- /dev/null
+++ b/src/common/transformations/include/openvino/decompositions/low_precision_dequantize.hpp
@@ -0,0 +1,74 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "openvino/core/node.hpp"
+#include "openvino/core/node_output.hpp"
+#include "openvino/pass/node_registry.hpp"
+#include "transformations_visibility.hpp"
+
+namespace ov {
+namespace decomposition {
+
+/// \brief Build the canonical low-precision dequantization sub-graph that is
+/// recognised by ov::pass::MarkDequantization and downstream LPT /
+/// weight-decompression passes.
+///
+/// The returned sub-graph implements one of:
+/// y = Multiply(Convert(x, scale_type), scale) // symmetric
+/// y = Multiply(Subtract(Convert(x, scale_type), zp), scale) // asymmetric
+/// optionally followed by a Reshape when \p output_shape is provided.
+///
+/// MarkDequantization matches the Multiply(Subtract(Convert(...), zp), scale)
+/// / Multiply(Convert(...), scale) pattern and protects the leading Convert
+/// from ConstantFolding. The optional trailing Reshape and any caller-applied
+/// ConvertLike sit *outside* the matched pattern — they do not break matching,
+/// but they are not themselves marked as dequantization nodes.
+///
+/// The output element type is taken from \p scale. If \p zero_point is given
+/// and its element type differs from \p scale, a Convert is inserted on the
+/// zero_point input as well — both forms (with and without that Convert) are
+/// matched by ov::pass::MarkDequantization.
+///
+/// The helper intentionally does not append a trailing ConvertLike: that cast
+/// is outside the pattern that MarkDequantization recognises and is best
+/// applied by the caller when needed (e.g. mixed-precision frontends that
+/// need to match the original input element type).
+///
+/// All nodes created by the helper are added to \p reg so the caller can
+/// post-process them uniformly (e.g. PyTorch frontend iterates the registry
+/// and calls NodeContext::mark_node on each entry). Callers that don't need
+/// post-processing can use the overload without a NodeRegistry.
+///
+/// When \p output_shape is provided, a Reshape is appended only if the
+/// Multiply output shape doesn't already match it (statically). This avoids
+/// inserting a no-op Reshape when broadcasting already produces the desired
+/// shape.
+///
+/// \param reg Node registry that collects every node created by the helper.
+/// \param x Quantized input tensor (typically a low-precision Constant).
+/// \param scale Dequantization scale; its element type determines the
+/// output element type of the sub-graph.
+/// \param zero_point Optional zero point. When provided a Subtract is
+/// inserted between the Convert and the Multiply.
+/// \param output_shape Optional shape constant. When provided a Reshape with
+/// special_zero=false is appended after the Multiply
+/// (skipped if the Multiply output already has that shape).
+ov::Output<ov::Node> TRANSFORMATIONS_API low_precision_dequantize(ov::pass::NodeRegistry& reg,
+ const ov::Output<ov::Node>& x,
+ const ov::Output<ov::Node>& scale,
+ const ov::Output<ov::Node>& zero_point = {},
+ const ov::Output<ov::Node>& output_shape = {});
+
+/// \brief Convenience overload for callers that do not need access to the
+/// intermediate nodes. Internally allocates a NodeRegistry and
+/// forwards to the registry-based overload.
+ov::Output<ov::Node> TRANSFORMATIONS_API low_precision_dequantize(const ov::Output<ov::Node>& x,
+ const ov::Output<ov::Node>& scale,
+ const ov::Output<ov::Node>& zero_point = {},
+ const ov::Output<ov::Node>& output_shape = {});
+
+} // namespace decomposition
+} // namespace ov
diff --git a/src/common/transformations/src/decompositions/low_precision_dequantize.cpp b/src/common/transformations/src/decompositions/low_precision_dequantize.cpp
new file mode 100644
index 00000000000..fa5b4dc9bec
--- /dev/null
+++ b/src/common/transformations/src/decompositions/low_precision_dequantize.cpp
@@ -0,0 +1,80 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/decompositions/low_precision_dequantize.hpp"
+
+#include "openvino/op/constant.hpp"
+#include "openvino/op/convert.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/reshape.hpp"
+#include "openvino/op/subtract.hpp"
+
+namespace ov {
+namespace decomposition {
+
+namespace {
+
+bool reshape_is_noop(const ov::Output<ov::Node>& multiply_out, const ov::Output<ov::Node>& output_shape) {
+ const auto shape_const = ov::as_type_ptr<ov::op::v0::Constant>(output_shape.get_node_shared_ptr());
+ if (!shape_const) {
+ return false;
+ }
+ const auto& current_shape = multiply_out.get_partial_shape();
+ if (current_shape.is_dynamic()) {
+ return false;
+ }
+ const auto target_shape = shape_const->cast_vector<int64_t>();
+ const auto current = current_shape.to_shape();
+ if (current.size() != target_shape.size()) {
+ return false;
+ }
+ for (size_t i = 0; i < current.size(); ++i) {
+ if (target_shape[i] != static_cast<int64_t>(current[i])) {
+ return false;
+ }
+ }
+ return true;
+}
+
+} // namespace
+
+ov::Output<ov::Node> low_precision_dequantize(ov::pass::NodeRegistry& reg,
+ const ov::Output<ov::Node>& x,
+ const ov::Output<ov::Node>& scale,
+ const ov::Output<ov::Node>& zero_point,
+ const ov::Output<ov::Node>& output_shape) {
+ // Decomposition shape (matches ov::pass::MarkDequantization):
+ // Multiply(Subtract(Convert(x), zp), scale) [-> Reshape]
+ // or, when zero_point is empty:
+ // Multiply(Convert(x), scale) [-> Reshape]
+ const auto& dst_type = scale.get_element_type();
+ ov::Output<ov::Node> result = reg.make<ov::op::v0::Convert>(x, dst_type);
+
+ if (zero_point.get_node_shared_ptr()) {
+ ov::Output<ov::Node> zp = zero_point;
+ if (zp.get_element_type() != dst_type) {
+ zp = reg.make<ov::op::v0::Convert>(zp, dst_type);
+ }
+ result = reg.make<ov::op::v1::Subtract>(result, zp);
+ }
+
+ result = reg.make<ov::op::v1::Multiply>(result, scale);
+
+ if (output_shape.get_node_shared_ptr() && !reshape_is_noop(result, output_shape)) {
+ result = reg.make<ov::op::v1::Reshape>(result, output_shape, /*special_zero=*/false);
+ }
+
+ return result;
+}
+
+ov::Output<ov::Node> low_precision_dequantize(const ov::Output<ov::Node>& x,
+ const ov::Output<ov::Node>& scale,
+ const ov::Output<ov::Node>& zero_point,
+ const ov::Output<ov::Node>& output_shape) {
+ ov::pass::NodeRegistry reg;
+ return low_precision_dequantize(reg, x, scale, zero_point, output_shape);
+}
+
+} // namespace decomposition
+} // namespace ov
diff --git a/src/common/transformations/tests/decompositions/low_precision_dequantize_decomposition_mark_test.cpp b/src/common/transformations/tests/decompositions/low_precision_dequantize_decomposition_mark_test.cpp
new file mode 100644
index 00000000000..650babeabda
--- /dev/null
+++ b/src/common/transformations/tests/decompositions/low_precision_dequantize_decomposition_mark_test.cpp
@@ -0,0 +1,233 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+// Tests that the canonical decomposition emitted by
+// ov::decomposition::low_precision_dequantize is recognised by
+// ov::pass::MarkDequantization. These tests act as a guard for both
+// directions:
+// * decomposition authors must keep the produced sub-graph in the shape
+// accepted by MarkDequantization;
+// * MarkDequantization authors must keep accepting the canonical
+// decomposition shape that frontends emit.
+
+#include <gtest/gtest.h>
+
+#include <memory>
+
+#include "common_test_utils/ov_test_utils.hpp"
+#include "openvino/decompositions/low_precision_dequantize.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/convert.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/reshape.hpp"
+#include "openvino/op/subtract.hpp"
+#include "openvino/pass/constant_folding.hpp"
+#include "transformations/low_precision/mark_dequantization_subgraph.hpp"
+#include "transformations/rt_info/dequantization_node.hpp"
+#include "transformations/rt_info/disable_constant_folding.hpp"
+
+using namespace ov;
+
+namespace {
+
+const element::TypeVector kLowPrecisionTypes{element::u8, element::i8, element::u4, element::i4};
+
+} // namespace
+
+TEST_F(TransformationTestsF, LowPrecisionDequantize_Asymmetric) {
+ const Shape weights_shape{4, 16};
+
+ {
+ auto weights = op::v0::Constant::create(element::u8, weights_shape, {1});
+ auto zero_point = op::v0::Constant::create(element::u8, Shape{}, {127});
+ auto scale = op::v0::Constant::create(element::f32, Shape{}, {0.2f});
+
+ auto out = decomposition::low_precision_dequantize(weights, scale, zero_point);
+ model = std::make_shared<Model>(OutputVector{out}, ParameterVector{});
+ }
+
+ manager.register_pass<pass::MarkDequantization>(kLowPrecisionTypes);
+ manager.register_pass<pass::ConstantFolding>();
+
+ {
+ auto weights = op::v0::Constant::create(element::u8, weights_shape, {1});
+ auto convert = std::make_shared<op::v0::Convert>(weights, element::f32);
+ disable_constant_folding(convert);
+
+ auto zero_point = op::v0::Constant::create(element::u8, Shape{}, {127});
+ auto zp_convert = std::make_shared<op::v0::Convert>(zero_point, element::f32);
+ disable_constant_folding(zp_convert);
+
+ auto subtract = std::make_shared<op::v1::Subtract>(convert, zp_convert);
+ mark_as_dequantization_node(subtract);
+
+ auto scale = op::v0::Constant::create(element::f32, Shape{}, {0.2f});
+ auto multiply = std::make_shared<op::v1::Multiply>(subtract, scale);
+ mark_as_dequantization_node(multiply);
+
+ model_ref = std::make_shared<Model>(OutputVector{multiply}, ParameterVector{});
+ }
+
+ comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES);
+ comparator.enable(FunctionsComparator::CmpValues::RUNTIME_KEYS);
+}
+
+TEST_F(TransformationTestsF, LowPrecisionDequantize_Symmetric) {
+ const Shape weights_shape{4, 16};
+
+ {
+ auto weights = op::v0::Constant::create(element::i8, weights_shape, {-2});
+ auto scale = op::v0::Constant::create(element::f32, Shape{}, {0.2f});
+
+ auto out = decomposition::low_precision_dequantize(weights, scale);
+ model = std::make_shared<Model>(OutputVector{out}, ParameterVector{});
+ }
+
+ manager.register_pass<pass::MarkDequantization>(kLowPrecisionTypes);
+ manager.register_pass<pass::ConstantFolding>();
+
+ {
+ auto weights = op::v0::Constant::create(element::i8, weights_shape, {-2});
+ auto convert = std::make_shared<op::v0::Convert>(weights, element::f32);
+ disable_constant_folding(convert);
+
+ auto scale = op::v0::Constant::create(element::f32, Shape{}, {0.2f});
+ auto multiply = std::make_shared<op::v1::Multiply>(convert, scale);
+ mark_as_dequantization_node(multiply);
+
+ model_ref = std::make_shared<Model>(OutputVector{multiply}, ParameterVector{});
+ }
+
+ comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES);
+ comparator.enable(FunctionsComparator::CmpValues::RUNTIME_KEYS);
+}
+
+TEST_F(TransformationTestsF, LowPrecisionDequantize_U4Asymmetric) {
+ // Group-quantised u4 weights — the AWQ/GPTQ shape used by the PyTorch frontend.
+ const Shape weights_shape{2, 8, 16};
+ const Shape scale_shape{2, 1, 16};
+
+ {
+ auto weights = op::v0::Constant::create(element::u4, weights_shape, {0});
+ auto zero_point = op::v0::Constant::create(element::u4, Shape{}, {8});
+ auto scale = op::v0::Constant::create(element::f16, scale_shape, {0.1f});
+
+ auto out = decomposition::low_precision_dequantize(weights, scale, zero_point);
+ model = std::make_shared<Model>(OutputVector{out}, ParameterVector{});
+ }
+
+ manager.register_pass<pass::MarkDequantization>(kLowPrecisionTypes);
+ manager.register_pass<pass::ConstantFolding>();
+
+ {
+ auto weights = op::v0::Constant::create(element::u4, weights_shape, {0});
+ auto convert = std::make_shared<op::v0::Convert>(weights, element::f16);
+ disable_constant_folding(convert);
+
+ auto zero_point = op::v0::Constant::create(element::u4, Shape{}, {8});
+ auto zp_convert = std::make_shared<op::v0::Convert>(zero_point, element::f16);
+ disable_constant_folding(zp_convert);
+
+ auto subtract = std::make_shared<op::v1::Subtract>(convert, zp_convert);
+ mark_as_dequantization_node(subtract);
+
+ auto scale = op::v0::Constant::create(element::f16, scale_shape, {0.1f});
+ auto multiply = std::make_shared<op::v1::Multiply>(subtract, scale);
+ mark_as_dequantization_node(multiply);
+
+ model_ref = std::make_shared<Model>(OutputVector{multiply}, ParameterVector{});
+ }
+
+ comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES);
+ comparator.enable(FunctionsComparator::CmpValues::RUNTIME_KEYS);
+}
+
+// Reshape branch — explicit output_shape that differs from the Multiply output.
+// ONNX blocked DequantizeLinear reshapes a [num_blocks, block_size, ...] grid
+// back to the input rank.
+TEST_F(TransformationTestsF, LowPrecisionDequantize_WithReshape) {
+ const Shape grid_shape{2, 4, 16}; // num_blocks, block_size, channels
+ const Shape scale_shape{2, 1, 16};
+ const std::vector<int32_t> target_shape{8, 16}; // num_blocks * block_size, channels
+
+ {
+ auto weights = op::v0::Constant::create(element::u8, grid_shape, {0});
+ auto zero_point = op::v0::Constant::create(element::u8, Shape{}, {8});
+ auto scale = op::v0::Constant::create(element::f32, scale_shape, {0.1f});
+ auto out_shape = op::v0::Constant::create(element::i32, Shape{2}, target_shape);
+
+ auto out = decomposition::low_precision_dequantize(weights, scale, zero_point, out_shape);
+ model = std::make_shared<Model>(OutputVector{out}, ParameterVector{});
+ }
+
+ manager.register_pass<pass::MarkDequantization>(kLowPrecisionTypes);
+ manager.register_pass<pass::ConstantFolding>();
+
+ {
+ auto weights = op::v0::Constant::create(element::u8, grid_shape, {0});
+ auto convert = std::make_shared<op::v0::Convert>(weights, element::f32);
+ disable_constant_folding(convert);
+
+ auto zero_point = op::v0::Constant::create(element::u8, Shape{}, {8});
+ auto zp_convert = std::make_shared<op::v0::Convert>(zero_point, element::f32);
+ disable_constant_folding(zp_convert);
+
+ auto subtract = std::make_shared<op::v1::Subtract>(convert, zp_convert);
+ mark_as_dequantization_node(subtract);
+
+ auto scale = op::v0::Constant::create(element::f32, scale_shape, {0.1f});
+ auto multiply = std::make_shared<op::v1::Multiply>(subtract, scale);
+ mark_as_dequantization_node(multiply);
+
+ auto out_shape = op::v0::Constant::create(element::i32, Shape{2}, target_shape);
+ auto reshape = std::make_shared<op::v1::Reshape>(multiply, out_shape, /*special_zero=*/false);
+
+ model_ref = std::make_shared<Model>(OutputVector{reshape}, ParameterVector{});
+ }
+
+ comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES);
+ comparator.enable(FunctionsComparator::CmpValues::RUNTIME_KEYS);
+}
+
+// When output_shape matches the Multiply output shape, the helper should skip
+// the trailing Reshape entirely.
+TEST_F(TransformationTestsF, LowPrecisionDequantize_NoopReshapeSkipped) {
+ const Shape weights_shape{4, 16};
+ const std::vector<int32_t> target_shape{4, 16};
+
+ {
+ auto weights = op::v0::Constant::create(element::u8, weights_shape, {1});
+ auto zero_point = op::v0::Constant::create(element::u8, Shape{}, {127});
+ auto scale = op::v0::Constant::create(element::f32, Shape{}, {0.2f});
+ auto out_shape = op::v0::Constant::create(element::i32, Shape{2}, target_shape);
+
+ auto out = decomposition::low_precision_dequantize(weights, scale, zero_point, out_shape);
+ model = std::make_shared<Model>(OutputVector{out}, ParameterVector{});
+ }
+
+ manager.register_pass<pass::MarkDequantization>(kLowPrecisionTypes);
+ manager.register_pass<pass::ConstantFolding>();
+
+ {
+ auto weights = op::v0::Constant::create(element::u8, weights_shape, {1});
+ auto convert = std::make_shared<op::v0::Convert>(weights, element::f32);
+ disable_constant_folding(convert);
+
+ auto zero_point = op::v0::Constant::create(element::u8, Shape{}, {127});
+ auto zp_convert = std::make_shared<op::v0::Convert>(zero_point, element::f32);
+ disable_constant_folding(zp_convert);
+
+ auto subtract = std::make_shared<op::v1::Subtract>(convert, zp_convert);
+ mark_as_dequantization_node(subtract);
+
+ auto scale = op::v0::Constant::create(element::f32, Shape{}, {0.2f});
+ auto multiply = std::make_shared<op::v1::Multiply>(subtract, scale);
+ mark_as_dequantization_node(multiply);
+
+ // No Reshape — helper detects output_shape == current shape and skips it.
+ model_ref = std::make_shared<Model>(OutputVector{multiply}, ParameterVector{});
+ }
+
+ comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES);
+ comparator.enable(FunctionsComparator::CmpValues::RUNTIME_KEYS);
+}
diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/dynamic_quantize_matmul.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/dynamic_quantize_matmul.cpp
index d904d955b65..bc519b9fed9 100644
--- a/src/frontends/onnx/frontend/src/op/com.microsoft/dynamic_quantize_matmul.cpp
+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/dynamic_quantize_matmul.cpp
@@ -4,12 +4,10 @@
#include "core/operator_set.hpp"
#include "exceptions.hpp"
+#include "openvino/decompositions/low_precision_dequantize.hpp"
#include "openvino/frontend/exception.hpp"
#include "openvino/op/add.hpp"
-#include "openvino/op/convert.hpp"
#include "openvino/op/matmul.hpp"
-#include "openvino/op/multiply.hpp"
-#include "openvino/op/subtract.hpp"
#include "utils/common.hpp"
using namespace ov::op;
@@ -75,12 +73,7 @@ ov::OutputVector dynamic_quantize_matmul(const ov::frontend::onnx::Node& node) {
// here https://tomwildenhain-microsoft.github.io/onnxruntime/docs/performance/quantization.html B_dequantized = (B
// - b_zero_point) * b_scale
- ov::Output<ov::Node> B_dequantized = std::make_shared<v0::Convert>(B, b_scale.get_element_type());
- if (b_zero_point.get_node_shared_ptr()) {
- b_zero_point = std::make_shared<v0::Convert>(b_zero_point, b_scale.get_element_type());
- B_dequantized = std::make_shared<v1::Subtract>(B_dequantized, b_zero_point);
- }
- B_dequantized = std::make_shared<v1::Multiply>(B_dequantized, b_scale);
+ ov::Output<ov::Node> B_dequantized = ov::decomposition::low_precision_dequantize(B, b_scale, b_zero_point);
// A, B are N-dimensional matrices. According to example ONNX models for this operator, the suboperations pass input
// A/B such that B's shape is already transposed. E.g.
diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/matmul_integer_to_float.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/matmul_integer_to_float.cpp
index e18b319fe20..644fe78d122 100644
--- a/src/frontends/onnx/frontend/src/op/com.microsoft/matmul_integer_to_float.cpp
+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/matmul_integer_to_float.cpp
@@ -5,12 +5,9 @@
#include "core/null_node.hpp"
#include "core/operator_set.hpp"
#include "exceptions.hpp"
+#include "openvino/decompositions/low_precision_dequantize.hpp"
#include "openvino/op/add.hpp"
-#include "openvino/op/constant.hpp"
-#include "openvino/op/convert.hpp"
#include "openvino/op/matmul.hpp"
-#include "openvino/op/multiply.hpp"
-#include "openvino/op/subtract.hpp"
#include "utils/common.hpp"
using namespace ov::op;
@@ -31,14 +28,14 @@ ov::OutputVector matmulintegertofloat(const ov::frontend::onnx::Node& node) {
const auto& a_scale = inputs[2];
const auto& b_scale = inputs[3];
- ov::Output<ov::Node> a_zero_point =
- common::is_input_valid(node, 4)
- ? inputs[4]
- : std::make_shared<ov::op::v0::Constant>(a_int.get_element_type(), ov::Shape{}, std::vector<int8_t>{0});
- ov::Output<ov::Node> b_zero_point =
- common::is_input_valid(node, 5)
- ? inputs[5]
- : std::make_shared<ov::op::v0::Constant>(b_int.get_element_type(), ov::Shape{}, std::vector<int8_t>{0});
+ ov::Output<ov::Node> a_zero_point;
+ if (common::is_input_valid(node, 4)) {
+ a_zero_point = inputs[4];
+ }
+ ov::Output<ov::Node> b_zero_point;
+ if (common::is_input_valid(node, 5)) {
+ b_zero_point = inputs[5];
+ }
CHECK_VALID_NODE(node,
a_int.get_element_type() == ov::element::i8 || a_int.get_element_type() == ov::element::u8,
@@ -50,16 +47,8 @@ ov::OutputVector matmulintegertofloat(const ov::frontend::onnx::Node& node) {
"Unsupported input B type. Expected int8 or uint8, got: ",
b_int.get_element_type());
- const auto a_dequantized = std::make_shared<ov::op::v1::Subtract>(a_int, a_zero_point);
- const auto b_dequantized = std::make_shared<ov::op::v1::Subtract>(b_int, b_zero_point);
-
- const auto a_dequantized_converted =
- std::make_shared<ov::op::v0::Convert>(a_dequantized, a_scale.get_element_type());
- const auto b_dequantized_converted =
- std::make_shared<ov::op::v0::Convert>(b_dequantized, b_scale.get_element_type());
-
- const auto a_scaled = std::make_shared<ov::op::v1::Multiply>(a_dequantized_converted, a_scale);
- const auto b_scaled = std::make_shared<ov::op::v1::Multiply>(b_dequantized_converted, b_scale);
+ auto a_scaled = ov::decomposition::low_precision_dequantize(a_int, a_scale, a_zero_point);
+ auto b_scaled = ov::decomposition::low_precision_dequantize(b_int, b_scale, b_zero_point);
const auto matmul_result = std::make_shared<ov::op::v0::MatMul>(a_scaled, b_scaled);
diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/matmulnbits.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/matmulnbits.cpp
index 22b10612099..22e4750bac3 100644
--- a/src/frontends/onnx/frontend/src/op/com.microsoft/matmulnbits.cpp
+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/matmulnbits.cpp
@@ -8,6 +8,7 @@
#include "core/null_node.hpp"
#include "core/operator_set.hpp"
#include "exceptions.hpp"
+#include "openvino/decompositions/low_precision_dequantize.hpp"
#include "openvino/frontend/exception.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/constant.hpp"
@@ -254,15 +255,12 @@ ov::OutputVector matmulnbits(const ov::frontend::onnx::Node& node) {
// use fp16 for compute
- // convert b to fp16
- auto converted_b = std::make_shared<v0::Convert>(casted_b, a.get_element_type());
-
- // sub and scale
- const auto sub_b = std::make_shared<v1::Subtract>(converted_b, converted_zero_points);
+ // sub and scale via the shared low-precision dequantization helper
const auto scales_fp16 = std::make_shared<v0::Convert>(scales, a.get_element_type());
const auto scales_reshaped =
op::util::reshape(scales_fp16, ov::Shape{static_cast<size_t>(N), static_cast<size_t>(n_blocks_per_col), 1});
- const auto scaled_b = std::make_shared<v1::Multiply>(sub_b, scales_reshaped);
+
+ auto scaled_b = ov::decomposition::low_precision_dequantize(casted_b, scales_reshaped, converted_zero_points);
// reshape b to [N, K]
auto shape_b = v0::Constant::create(ov::element::i32, ov::Shape{2}, {0, -1});
diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_activation.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_activation.cpp
index ed01fda7947..bd9ad77006e 100644
--- a/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_activation.cpp
+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_activation.cpp
@@ -5,6 +5,7 @@
#include "core/null_node.hpp"
#include "core/operator_set.hpp"
#include "exceptions.hpp"
+#include "openvino/decompositions/low_precision_dequantize.hpp"
#include "openvino/frontend/exception.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/avg_pool.hpp"
@@ -49,12 +50,9 @@ ov::OutputVector qlinear_activation(const ov::frontend::onnx::Node& node, const
"Input tensor must be either int8 or uint8. Got: ",
input_tensor.get_element_type());
- auto input_subtracted = std::make_shared<v1::Subtract>(input_tensor, input_zero_point);
- auto input_dequantized =
- std::make_shared<v1::Multiply>(std::make_shared<v0::Convert>(input_subtracted, input_scale.get_element_type()),
- input_scale);
+ auto input_dequantized = ov::decomposition::low_precision_dequantize(input_tensor, input_scale, input_zero_point);
- auto activation_result = activation_fn(input_dequantized);
+ auto activation_result = activation_fn(input_dequantized.get_node_shared_ptr());
auto scaled_result_float = std::make_shared<v1::Divide>(activation_result, output_scale);
auto quantized_result =
diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_concat.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_concat.cpp
index 984a36262e8..e2ac3654e3d 100644
--- a/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_concat.cpp
+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_concat.cpp
@@ -1,16 +1,16 @@
// Copyright (C) 2018-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
+//
#include "core/null_node.hpp"
#include "core/operator_set.hpp"
#include "exceptions.hpp"
+#include "openvino/decompositions/low_precision_dequantize.hpp"
#include "openvino/frontend/exception.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/concat.hpp"
#include "openvino/op/convert.hpp"
#include "openvino/op/divide.hpp"
-#include "openvino/op/multiply.hpp"
-#include "openvino/op/subtract.hpp"
#include "openvino/op/util/op_types.hpp"
#include "utils/common.hpp"
@@ -33,23 +33,18 @@ ov::OutputVector qlinear_concat(const ov::frontend::onnx::Node& node) {
auto Y_zero_point =
ov::op::util::is_null(inputs[1]) ? v0::Constant::create(Y_scale.get_element_type(), {}, {0}) : inputs[1];
- std::vector<std::shared_ptr<ov::Node>> dequantized_inputs;
+ ov::OutputVector dequantized_inputs;
for (size_t i = 2; i < inputs.size(); i += 3) {
auto X = inputs[i];
auto X_scale = inputs[i + 1];
auto X_zero_point =
ov::op::util::is_null(inputs[i + 2]) ? v0::Constant::create(X.get_element_type(), {}, {0}) : inputs[i + 2];
- auto X_minus_zero_point = std::make_shared<v1::Subtract>(X, X_zero_point);
- auto X_minus_zero_point_float = std::make_shared<v0::Convert>(X_minus_zero_point, X_scale.get_element_type());
- auto dequantized_X = std::make_shared<v1::Multiply>(X_scale, X_minus_zero_point_float);
-
- dequantized_inputs.push_back(dequantized_X);
+ dequantized_inputs.push_back(ov::decomposition::low_precision_dequantize(X, X_scale, X_zero_point));
}
auto axis = node.get_attribute_value<int64_t>("axis");
- auto concatenated =
- std::make_shared<v0::Concat>(ov::OutputVector(dequantized_inputs.begin(), dequantized_inputs.end()), axis);
+ auto concatenated = std::make_shared<v0::Concat>(dequantized_inputs, axis);
auto requantized = std::make_shared<v1::Divide>(concatenated, Y_scale);
auto Y_zero_point_float = std::make_shared<v0::Convert>(Y_zero_point, Y_scale.get_element_type());
diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_ops.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_ops.cpp
index 5998b65f78d..ed3b62a1f7e 100644
--- a/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_ops.cpp
+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_ops.cpp
@@ -5,14 +5,13 @@
#include "core/null_node.hpp"
#include "core/operator_set.hpp"
#include "exceptions.hpp"
+#include "openvino/decompositions/low_precision_dequantize.hpp"
#include "openvino/frontend/exception.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convert.hpp"
#include "openvino/op/divide.hpp"
#include "openvino/op/multiply.hpp"
-#include "openvino/op/reshape.hpp"
-#include "openvino/op/subtract.hpp"
#include "openvino/op/util/op_types.hpp"
#include "utils/common.hpp"
@@ -59,14 +58,8 @@ ov::OutputVector qlinear_op(const ov::frontend::onnx::Node& node, BinaryOp binar
", B_zero_point: ",
B_zero_point.get_element_type());
- auto A_minus_zero_point = std::make_shared<v1::Subtract>(A, A_zero_point);
- auto B_minus_zero_point = std::make_shared<v1::Subtract>(B, B_zero_point);
-
- auto A_minus_zero_point_float = std::make_shared<v0::Convert>(A_minus_zero_point, A_scale.get_element_type());
- auto B_minus_zero_point_float = std::make_shared<v0::Convert>(B_minus_zero_point, B_scale.get_element_type());
-
- auto A_scaled = std::make_shared<v1::Multiply>(A_scale, A_minus_zero_point_float);
- auto B_scaled = std::make_shared<v1::Multiply>(B_scale, B_minus_zero_point_float);
+ auto A_scaled = ov::decomposition::low_precision_dequantize(A, A_scale, A_zero_point);
+ auto B_scaled = ov::decomposition::low_precision_dequantize(B, B_scale, B_zero_point);
auto result_scaled = binary_op(A_scaled, B_scaled);
diff --git a/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_where.cpp b/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_where.cpp
index 744e5729292..411ec4131f2 100644
--- a/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_where.cpp
+++ b/src/frontends/onnx/frontend/src/op/com.microsoft/qlinear_where.cpp
@@ -1,15 +1,15 @@
// Copyright (C) 2018-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
+//
#include "core/operator_set.hpp"
#include "exceptions.hpp"
+#include "openvino/decompositions/low_precision_dequantize.hpp"
#include "openvino/frontend/exception.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/convert.hpp"
#include "openvino/op/divide.hpp"
-#include "openvino/op/multiply.hpp"
#include "openvino/op/select.hpp"
-#include "openvino/op/subtract.hpp"
#include "utils/common.hpp"
using namespace ov::op;
@@ -33,14 +33,8 @@ ov::OutputVector qlinear_where(const ov::frontend::onnx::Node& node) {
auto z_scale = node.get_ov_inputs().at(7);
auto z_zero_point = node.get_ov_inputs().at(8);
- auto x_minus_zero_point = std::make_shared<v1::Subtract>(x, x_zero_point);
- auto y_minus_zero_point = std::make_shared<v1::Subtract>(y, y_zero_point);
-
- auto x_minus_zero_point_float = std::make_shared<v0::Convert>(x_minus_zero_point, x_scale.get_element_type());
- auto y_minus_zero_point_float = std::make_shared<v0::Convert>(y_minus_zero_point, y_scale.get_element_type());
-
- auto x_dequant = std::make_shared<v1::Multiply>(x_scale, x_minus_zero_point_float);
- auto y_dequant = std::make_shared<v1::Multiply>(y_scale, y_minus_zero_point_float);
+ auto x_dequant = ov::decomposition::low_precision_dequantize(x, x_scale, x_zero_point);
+ auto y_dequant = ov::decomposition::low_precision_dequantize(y, y_scale, y_zero_point);
auto selected = std::make_shared<v1::Select>(condition, x_dequant, y_dequant);
diff --git a/src/frontends/onnx/frontend/src/op/dequantize_linear.cpp b/src/frontends/onnx/frontend/src/op/dequantize_linear.cpp
index 3d472c2d4f0..5efcf089839 100644
--- a/src/frontends/onnx/frontend/src/op/dequantize_linear.cpp
+++ b/src/frontends/onnx/frontend/src/op/dequantize_linear.cpp
@@ -8,6 +8,7 @@
#include "core/null_node.hpp"
#include "core/operator_set.hpp"
#include "openvino/core/validation_util.hpp"
+#include "openvino/decompositions/low_precision_dequantize.hpp"
#include "openvino/frontend/exception.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convert.hpp"
@@ -18,7 +19,6 @@
#include "openvino/op/subtract.hpp"
#include "openvino/op/transpose.hpp"
#include "openvino/op/unsqueeze.hpp"
-#include "transformations/rt_info/disable_constant_folding.hpp"
#include "utils/common.hpp"
#include "utils/reshape.hpp"
using namespace ov::op;
@@ -58,14 +58,12 @@ ov::OutputVector dequantize_linear(const ov::frontend::onnx::Node& node, int64_t
common::validate_scalar_input("Dequantization scale", scale.get_node_shared_ptr(), valid_types);
- const auto converted_x = std::make_shared<v0::Convert>(x, scale.get_element_type());
-
if (zero_point) {
common::validate_scalar_input("Zero point", zero_point);
- return {std::make_shared<v1::Multiply>(std::make_shared<v1::Subtract>(converted_x, zero_point), scale)};
- } else {
- return {std::make_shared<v1::Multiply>(converted_x, scale)};
}
+
+ auto result = ov::decomposition::low_precision_dequantize(x, scale, zero_point);
+ return {result};
}
} // namespace detail
@@ -165,16 +163,15 @@ ov::OutputVector dequantize_linear(const ov::Output<ov::Node>& x,
validate_scale(scale, x, axis);
const auto scale_reshaped = reshape_input(scale, axis, x_shape);
- const auto converted_x = std::make_shared<v0::Convert>(x, scale.get_element_type());
+ ov::Output<ov::Node> zp;
if (zero_point) {
validate_zero_point(zero_point, x, axis);
- return {std::make_shared<v1::Multiply>(
- std::make_shared<v1::Subtract>(converted_x, reshape_input(zero_point, axis, x_shape)),
- scale_reshaped)};
- } else {
- return {std::make_shared<v1::Multiply>(converted_x, scale_reshaped)};
+ zp = reshape_input(zero_point, axis, x_shape);
}
+
+ auto result = ov::decomposition::low_precision_dequantize(x, scale_reshaped, zp);
+ return {result};
}
} // namespace detail
@@ -252,13 +249,10 @@ ov::OutputVector dequantize_linear(const ov::frontend::onnx::Node& node) {
// Check if this is channel-wise quantization (block_size equals dimension size at axis)
bool is_cw_quantize = (src_x.get_shape()[axis] == block_size);
if (is_cw_quantize) {
- ov::Output<ov::Node> converted_x = std::make_shared<v0::Convert>(src_x, scale.get_element_type());
if (inputs.size() > 2) {
zp = inputs[2];
- zp = std::make_shared<v0::Convert>(zp, scale.get_element_type());
- converted_x = std::make_shared<v1::Subtract>(converted_x, zp);
}
- auto scaled_x = std::make_shared<v1::Multiply>(converted_x, scale);
+ auto scaled_x = ov::decomposition::low_precision_dequantize(src_x, scale, zp);
return {scaled_x};
}
@@ -286,34 +280,18 @@ ov::OutputVector dequantize_linear(const ov::frontend::onnx::Node& node) {
const auto& unsqueezed_axes =
std::make_shared<v0::Constant>(ov::element::i64, Shape{1}, std::vector<int64_t>{unsqueeze_axis});
- const auto scale_type = scale.get_element_type();
if (inputs.size() > 2) {
- zp = inputs[2];
- zp = std::make_shared<v0::Unsqueeze>(zp, unsqueezed_axes);
- if (zp.get_element_type() != scale.get_element_type()) {
- zp = std::make_shared<v0::Convert>(zp, scale_type);
- }
+ zp = std::make_shared<v0::Unsqueeze>(inputs[2], unsqueezed_axes);
}
- const auto& x = src_x.get_element_type() == scale_type ? broadcastable_x
- : std::make_shared<v0::Convert>(broadcastable_x, scale_type);
-
// Adding additional dimension for broadcasting
scale = std::make_shared<v0::Unsqueeze>(scale, unsqueezed_axes);
- if (zp.get_node_shared_ptr()) {
- broadcastable_x = std::make_shared<v1::Subtract>(x, zp);
- } else {
- broadcastable_x = x;
- }
-
- const auto& scaled_x = std::make_shared<v1::Multiply>(broadcastable_x, scale);
+ auto out_shape = std::make_shared<v0::ShapeOf>(src_x);
- // Returning back a shape
- const auto& reshaped_scaled_x =
- std::make_shared<v1::Reshape>(scaled_x, std::make_shared<v0::ShapeOf>(src_x), false);
+ auto reshaped_scaled_x = ov::decomposition::low_precision_dequantize(broadcastable_x, scale, zp, out_shape);
- reshaped_scaled_x->set_friendly_name(node.get_name());
+ reshaped_scaled_x.get_node_shared_ptr()->set_friendly_name(node.get_name());
return {reshaped_scaled_x};
}
diff --git a/src/frontends/onnx/tests/tests_python/test_backend.py b/src/frontends/onnx/tests/tests_python/test_backend.py
index 55e747620ef..30d134ce8be 100644
--- a/src/frontends/onnx/tests/tests_python/test_backend.py
+++ b/src/frontends/onnx/tests/tests_python/test_backend.py
@@ -616,7 +616,6 @@ tests_expected_to_fail = [
(
xfail_issue_139938,
"OnnxBackendNodeModelTest.test_qlinearmatmul_2D_int8_float32_cpu",
- "OnnxBackendNodeModelTest.test_qlinearmatmul_2D_uint8_float16_cpu",
),
(
xfail_issue_171767,
diff --git a/src/frontends/paddle/src/op/dequantize_linear.cpp b/src/frontends/paddle/src/op/dequantize_linear.cpp
index 65c67c9f2fd..334569ac9c5 100644
--- a/src/frontends/paddle/src/op/dequantize_linear.cpp
+++ b/src/frontends/paddle/src/op/dequantize_linear.cpp
@@ -3,6 +3,7 @@
//
#include "default_opset.hpp"
+#include "openvino/decompositions/low_precision_dequantize.hpp"
#include "openvino/frontend/paddle/node_context.hpp"
namespace ov {
@@ -35,9 +36,8 @@ NamedOutputs dequantize_linear(const NodeContext& node) {
const auto bit_length = node.get_attribute<int32_t>("bit_length");
const auto range = (1 << (bit_length - 1)) - 1;
const auto range_node = std::make_shared<default_opset::Constant>(element::f32, Shape{1}, (1.0 / range));
- const auto real_scale = std::make_shared<default_opset::Multiply>(scale, range_node);
+ ov::Output<ov::Node> real_scale = std::make_shared<default_opset::Multiply>(scale, range_node);
- auto q_node = std::make_shared<default_opset::Convert>(x, element::f32);
// extract the ATTRIBUTES and explanation for quant_axis:
// / [-1] --- per-tensor, scale is always 1-D
// quant_axis - [0 or 1] --- per-channel, scale may be 1-D or 2-D, needing to reshape for input shape.
@@ -51,13 +51,8 @@ NamedOutputs dequantize_linear(const NodeContext& node) {
return quant_axis == value;
}),
"dequantize_linear quant_axis is NOT in the range of [-1, 0, 1].");
- if (quant_axis == -1) {
- const auto zp_node = std::make_shared<default_opset::Convert>(zero_point, element::f32);
- const auto out_node =
- std::make_shared<default_opset::Multiply>(std::make_shared<default_opset::Subtract>(q_node, zp_node),
- real_scale);
- return node.default_single_output_mapping({out_node}, {"Y"});
- } else {
+ ov::Output<ov::Node> zp_input = zero_point;
+ if (quant_axis != -1) {
// But for per-channel scenario, the shape of scale is NOT stable.
// Sometimes scale is 1-D and sometimes scale is 2-D. But the last dim(e.g. s[len-1]) really makes sense.
// Let's prepare a pattern to reshape operation according to the scale shape.
@@ -65,15 +60,11 @@ NamedOutputs dequantize_linear(const NodeContext& node) {
reshape_pattern.at(quant_axis) = scale_shape[scale_shape_length - 1].get_length();
const auto reshape_node =
std::make_shared<default_opset::Constant>(element::i32, Shape{reshape_pattern.size()}, reshape_pattern);
- const auto reshape_scale = std::make_shared<default_opset::Reshape>(real_scale, reshape_node, true);
- const auto zp_node = std::make_shared<default_opset::Convert>(
- std::make_shared<default_opset::Reshape>(zero_point, reshape_node, true),
- element::f32);
- const auto out_node =
- std::make_shared<default_opset::Multiply>(std::make_shared<default_opset::Subtract>(q_node, zp_node),
- reshape_scale);
- return node.default_single_output_mapping({out_node}, {"Y"});
+ real_scale = std::make_shared<default_opset::Reshape>(real_scale, reshape_node, true);
+ zp_input = std::make_shared<default_opset::Reshape>(zero_point, reshape_node, true);
}
+ auto out_node = ov::decomposition::low_precision_dequantize(x, real_scale, zp_input);
+ return node.default_single_output_mapping({out_node.get_node_shared_ptr()}, {"Y"});
}
} // namespace op
diff --git a/src/frontends/pytorch/src/op/linear.cpp b/src/frontends/pytorch/src/op/linear.cpp
index 81370973a03..73bdbe51b52 100644
--- a/src/frontends/pytorch/src/op/linear.cpp
+++ b/src/frontends/pytorch/src/op/linear.cpp
@@ -2,13 +2,12 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "openvino/decompositions/low_precision_dequantize.hpp"
#include "openvino/frontend/pytorch/node_context.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/matmul.hpp"
-#include "openvino/op/multiply.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/shape_of.hpp"
-#include "openvino/op/subtract.hpp"
#include "utils.hpp"
namespace ov {
@@ -80,16 +79,10 @@ Output<Node> low_precision_subgraph(const NodeContext& context,
const Output<Node>& zero_points,
const Output<Node>& scales,
const Output<Node>& out_shape) {
- auto new_qweight = context.mark_node(std::make_shared<v0::Convert>(weights, scales.get_element_type()));
- auto new_qzeros = context.mark_node(std::make_shared<v0::Convert>(zero_points, scales.get_element_type()));
-
- auto w_s = context.mark_node(std::make_shared<v1::Subtract>(new_qweight, new_qzeros));
- auto weight = context.mark_node(std::make_shared<v1::Multiply>(w_s, scales));
- auto weight_shape = weights.get_shape();
- if (out_shape.get_node() != nullptr) {
- weight = context.mark_node(std::make_shared<v1::Reshape>(weight, out_shape, false));
- }
- weight = context.mark_node(std::make_shared<v1::ConvertLike>(weight, x));
+ ov::pass::NodeRegistry reg;
+ auto weight = ov::decomposition::low_precision_dequantize(reg, weights, scales, zero_points, out_shape);
+ weight = reg.make<v1::ConvertLike>(weight, x);
+ context.mark_nodes(reg.get());
return weight;
}
diff --git a/src/frontends/tensorflow_lite/src/tflite_transformations/tflite_quantize_resolver.cpp b/src/frontends/tensorflow_lite/src/tflite_transformations/tflite_quantize_resolver.cpp
index 6304fceeaf9..48b8ffbd911 100644
--- a/src/frontends/tensorflow_lite/src/tflite_transformations/tflite_quantize_resolver.cpp
+++ b/src/frontends/tensorflow_lite/src/tflite_transformations/tflite_quantize_resolver.cpp
@@ -8,6 +8,7 @@
#include "openvino/core/rt_info.hpp"
#include "openvino/core/validation_util.hpp"
+#include "openvino/decompositions/low_precision_dequantize.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convert.hpp"
#include "openvino/op/fake_quantize.hpp"
@@ -20,7 +21,6 @@
#include "openvino/pass/pattern/op/optional.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "tflite_ops/tflite_quantize.hpp"
-#include "transformations/rt_info/disable_constant_folding.hpp"
#include "utils.hpp"
using namespace std;
@@ -196,13 +196,13 @@ pass::TFLQuantizeReplacer::TFLQuantizeReplacer() {
if (is_constant) {
fuse_zp_to_weights(output, zp, zp_shape);
- output = make_shared<v0::Convert>(output, element::f32);
- disable_constant_folding(output.get_node_shared_ptr());
+ ov::Output<ov::Node> zp_input;
if (std::any_of(zp.begin(), zp.end(), [](const int64_t& i) {
return i != 0;
- }))
- output = std::make_shared<v1::Subtract>(output, zp_node);
- output = std::make_shared<v1::Multiply>(output, scale_node);
+ })) {
+ zp_input = zp_node;
+ }
+ output = ov::decomposition::low_precision_dequantize(output, scale_node, zp_input);
tfl_quantize->output(0).replace(output);
return true;
}