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
[CPU] Introduce FullyConnected, FCQuantized, FCCompressed, Placeholder (#26239)
Egor Duplenskii6a4ba4695191
diff --git a/src/common/transformations/include/ov_ops/fully_connected.hpp b/src/common/transformations/include/ov_ops/fully_connected.hppnew file mode 100644index 00000000000..6f33b5963ff--- /dev/null+++ b/src/common/transformations/include/ov_ops/fully_connected.hpp@@ -0,0 +1,46 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/core/node.hpp"+#include "openvino/op/op.hpp"+#include "transformations_visibility.hpp"++namespace ov {+namespace op {+namespace internal {++class TRANSFORMATIONS_API FullyConnected : public ov::op::Op {+public:+ OPENVINO_OP("FullyConnected", "ie_internal_opset");++ FullyConnected() = default;++ FullyConnected(const ov::Output<Node>& A,+ const ov::Output<Node>& B,+ const ov::Output<Node>& bias,+ const ov::element::Type output_type = ov::element::undefined);++ FullyConnected(const ov::Output<Node>& A,+ const ov::Output<Node>& B,+ const ov::element::Type output_type = ov::element::undefined);++ bool visit_attributes(ov::AttributeVisitor& visitor) override;++ ov::element::Type get_output_type() const {+ return m_output_type;+ }++ std::shared_ptr<Node> clone_with_new_inputs(const ov::OutputVector& new_args) const override;++ void validate_and_infer_types() override;++protected:+ ov::element::Type m_output_type;+};++} // namespace internal+} // namespace op+} // namespace ovdiff --git a/src/common/transformations/include/ov_ops/fully_connected_compressed.hpp b/src/common/transformations/include/ov_ops/fully_connected_compressed.hppnew file mode 100644index 00000000000..d363a339406--- /dev/null+++ b/src/common/transformations/include/ov_ops/fully_connected_compressed.hpp@@ -0,0 +1,41 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/core/node.hpp"+#include "openvino/op/op.hpp"+#include "ov_ops/fully_connected.hpp"++namespace ov {+namespace op {+namespace internal {++class TRANSFORMATIONS_API FullyConnectedCompressed : public FullyConnected {+public:+ OPENVINO_OP("FullyConnectedCompressed", "ie_internal_opset", FullyConnected);++ FullyConnectedCompressed() = default;++ FullyConnectedCompressed(const ov::Output<Node>& X,+ const ov::Output<Node>& W,+ const ov::Output<Node>& bias,+ const ov::Output<Node>& weight_scales,+ const ov::Output<Node>& weight_zero_points,+ const ov::element::Type output_type = ov::element::undefined);++ FullyConnectedCompressed(const ov::Output<Node>& X,+ const ov::Output<Node>& W,+ const ov::Output<Node>& bias,+ const ov::Output<Node>& weight_scales,+ const ov::element::Type output_type = ov::element::undefined);++ std::shared_ptr<Node> clone_with_new_inputs(const ov::OutputVector& new_args) const override;++ void validate_and_infer_types() override;+};++} // namespace internal+} // namespace op+} // namespace ovdiff --git a/src/common/transformations/include/ov_ops/fully_connected_quantized.hpp b/src/common/transformations/include/ov_ops/fully_connected_quantized.hppnew file mode 100644index 00000000000..6eceed0abde--- /dev/null+++ b/src/common/transformations/include/ov_ops/fully_connected_quantized.hpp@@ -0,0 +1,39 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/core/node.hpp"+#include "openvino/op/op.hpp"+#include "ov_ops/fully_connected.hpp"++namespace ov {+namespace op {+namespace internal {++class TRANSFORMATIONS_API FullyConnectedQuantized : public FullyConnected {+public:+ OPENVINO_OP("FullyConnectedQuantized", "ie_internal_opset", FullyConnected);++ FullyConnectedQuantized() = default;++ FullyConnectedQuantized(const ov::Output<Node>& X,+ const ov::Output<Node>& W,+ const ov::Output<Node>& bias,+ const ov::Output<Node>& weight_scales,+ const ov::Output<Node>& weight_zero_points,+ const ov::Output<Node>& input_scales,+ const ov::Output<Node>& input_zero_points,+ const ov::Output<Node>& output_scales,+ const ov::Output<Node>& output_zero_points,+ const ov::element::Type output_type = ov::element::undefined);++ void validate_and_infer_types() override;++ std::shared_ptr<Node> clone_with_new_inputs(const ov::OutputVector& new_args) const override;+};++} // namespace internal+} // namespace op+} // namespace ovdiff --git a/src/common/transformations/include/ov_ops/fully_connected_quantized_legacy.hpp b/src/common/transformations/include/ov_ops/fully_connected_quantized_legacy.hppnew file mode 100644index 00000000000..2c68ec4dc36--- /dev/null+++ b/src/common/transformations/include/ov_ops/fully_connected_quantized_legacy.hpp@@ -0,0 +1,41 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/core/node.hpp"+#include "openvino/op/op.hpp"+#include "ov_ops/fully_connected.hpp"++namespace ov {+namespace op {+namespace internal {++class TRANSFORMATIONS_API FullyConnectedQuantizedLegacy : public FullyConnected {+public:+ OPENVINO_OP("FullyConnectedQuantizedLegacy", "ie_internal_opset", FullyConnected);++ FullyConnectedQuantizedLegacy() = default;++ FullyConnectedQuantizedLegacy(const ov::Output<Node>& X,+ const ov::Output<Node>& W,+ const ov::Output<Node>& bias,+ const ov::Output<Node>& deq_scales,+ const ov::Output<Node>& deq_zero_points,+ const ov::element::Type output_type = ov::element::undefined);++ FullyConnectedQuantizedLegacy(const ov::Output<Node>& X,+ const ov::Output<Node>& W,+ const ov::Output<Node>& bias,+ const ov::Output<Node>& deq_scales,+ const ov::element::Type output_type = ov::element::undefined);++ std::shared_ptr<Node> clone_with_new_inputs(const ov::OutputVector& new_args) const override;++ void validate_and_infer_types() override;+};++} // namespace internal+} // namespace op+} // namespace ovdiff --git a/src/common/transformations/include/transformations/op_conversions/convert_fc_to_compressed.hpp b/src/common/transformations/include/transformations/op_conversions/convert_fc_to_compressed.hppnew file mode 100644index 00000000000..1b6fcfb2bb3--- /dev/null+++ b/src/common/transformations/include/transformations/op_conversions/convert_fc_to_compressed.hpp@@ -0,0 +1,29 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/pass/matcher_pass.hpp"+#include "ov_ops/fully_connected.hpp"+#include "transformations_visibility.hpp"++namespace ov {+namespace pass {++class TRANSFORMATIONS_API ConvertFullyConnectedToFullyConnectedCompressed;++} // namespace pass+} // namespace ov++class ov::pass::ConvertFullyConnectedToFullyConnectedCompressed : public ov::pass::MatcherPass {+public:+ using SupportsPredicate =+ std::function<bool(const std::shared_ptr<ov::op::internal::FullyConnected>&, size_t, size_t, size_t)>;++ OPENVINO_RTTI("ConvertFullyConnectedToFullyConnectedCompressed", "0");+ ConvertFullyConnectedToFullyConnectedCompressed(const std::vector<ov::element::Type>& supported_activation_types,+ const std::vector<ov::element::Type>& supported_weights_types,+ SupportsPredicate supports_config = nullptr,+ bool convert_u4zp_to_u8 = false);+};diff --git a/src/common/transformations/include/transformations/op_conversions/convert_fc_to_quantized_legacy.hpp b/src/common/transformations/include/transformations/op_conversions/convert_fc_to_quantized_legacy.hppnew file mode 100644index 00000000000..88990f92cb5--- /dev/null+++ b/src/common/transformations/include/transformations/op_conversions/convert_fc_to_quantized_legacy.hpp@@ -0,0 +1,22 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/pass/matcher_pass.hpp"+#include "transformations_visibility.hpp"++namespace ov {+namespace pass {++class TRANSFORMATIONS_API ConvertFCToFCQuantizedLegacy;++} // namespace pass+} // namespace ov++class ov::pass::ConvertFCToFCQuantizedLegacy : public ov::pass::MatcherPass {+public:+ OPENVINO_RTTI("ConvertFullyConnectedToFullyConnectedQuantized", "0");+ ConvertFCToFCQuantizedLegacy();+};diff --git a/src/common/transformations/src/ov_ops/fully_connected.cpp b/src/common/transformations/src/ov_ops/fully_connected.cppnew file mode 100644index 00000000000..3fa609362b9--- /dev/null+++ b/src/common/transformations/src/ov_ops/fully_connected.cpp@@ -0,0 +1,62 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "ov_ops/fully_connected.hpp"++#include <memory>++#include "matmul_shape_inference.hpp"++namespace ov {+namespace op {+namespace internal {++FullyConnected::FullyConnected(const ov::Output<Node>& A,+ const ov::Output<Node>& B,+ const ov::Output<Node>& bias,+ const ov::element::Type output_type)+ : Op({A, B, bias}),+ m_output_type(output_type) {+ validate_and_infer_types();+}++FullyConnected::FullyConnected(const ov::Output<Node>& A,+ const ov::Output<Node>& B,+ const ov::element::Type output_type)+ : FullyConnected(A, B, std::make_shared<v0::Constant>(element::undefined, Shape{0}), output_type) {}++bool FullyConnected::visit_attributes(ov::AttributeVisitor& visitor) {+ visitor.on_attribute("output_type", m_output_type);+ return true;+}++std::shared_ptr<ov::Node> FullyConnected::clone_with_new_inputs(const ov::OutputVector& new_args) const {+ check_new_args_count(this, new_args);++ return std::make_shared<FullyConnected>(new_args.at(0), new_args.at(1), new_args.at(2), m_output_type);+}++void FullyConnected::validate_and_infer_types() {+ const auto input_size = get_input_size();+ NODE_VALIDATION_CHECK(this,+ input_size >= 3,+ "Number of inputs is incorrect. Current value is: ",+ input_size,+ ", expected at least 3.");++ ov::op::v0::MatMul op;+ op.set_transpose_a(false);+ op.set_transpose_b(true);++ auto out_shapes =+ ov::op::v0::shape_infer(&op,+ std::vector<ov::PartialShape>{get_input_partial_shape(0), get_input_partial_shape(1)});++ auto output_type = m_output_type == ov::element::undefined ? get_input_element_type(0) : m_output_type;+ set_output_type(0, output_type, out_shapes[0]);+}++} // namespace internal+} // namespace op+} // namespace ovdiff --git a/src/common/transformations/src/ov_ops/fully_connected_compressed.cpp b/src/common/transformations/src/ov_ops/fully_connected_compressed.cppnew file mode 100644index 00000000000..e0bb13042ea--- /dev/null+++ b/src/common/transformations/src/ov_ops/fully_connected_compressed.cpp@@ -0,0 +1,63 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "ov_ops/fully_connected_compressed.hpp"++#include <memory>++#include "openvino/core/type/element_type.hpp"+#include "openvino/op/constant.hpp"+#include "ov_ops/fully_connected.hpp"++namespace ov {+namespace op {+namespace internal {++FullyConnectedCompressed::FullyConnectedCompressed(const ov::Output<Node>& X,+ const ov::Output<Node>& W,+ const ov::Output<Node>& bias,+ const ov::Output<Node>& weight_scales,+ const ov::Output<Node>& weight_zero_points,+ const ov::element::Type output_type)+ : FullyConnected(X, W, bias, output_type) {+ set_argument(3, weight_scales);+ set_argument(4, weight_zero_points);+ validate_and_infer_types();+}++FullyConnectedCompressed::FullyConnectedCompressed(const ov::Output<Node>& X,+ const ov::Output<Node>& W,+ const ov::Output<Node>& bias,+ const ov::Output<Node>& weight_scales,+ const ov::element::Type output_type)+ : FullyConnectedCompressed(X,+ W,+ bias,+ weight_scales,+ std::make_shared<v0::Constant>(element::undefined, Shape{0}),+ output_type) {}++std::shared_ptr<ov::Node> FullyConnectedCompressed::clone_with_new_inputs(const ov::OutputVector& new_args) const {+ check_new_args_count(this, new_args);++ return std::make_shared<FullyConnectedCompressed>(new_args.at(0),+ new_args.at(1),+ new_args.at(2),+ new_args.at(3),+ new_args.at(4),+ m_output_type);+}++// @todo finalize validate_and_infer_types+void FullyConnectedCompressed::validate_and_infer_types() {+ const auto input_size = get_input_size();++ NODE_VALIDATION_CHECK(this, input_size == 5, "Number of inputs is incorrect. Current value is: ", input_size);++ FullyConnected::validate_and_infer_types();+}++} // namespace internal+} // namespace op+} // namespace ovdiff --git a/src/common/transformations/src/ov_ops/fully_connected_quantized.cpp b/src/common/transformations/src/ov_ops/fully_connected_quantized.cppnew file mode 100644index 00000000000..3f06e14834f--- /dev/null+++ b/src/common/transformations/src/ov_ops/fully_connected_quantized.cpp@@ -0,0 +1,59 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "ov_ops/fully_connected_quantized.hpp"++#include "openvino/core/type/element_type.hpp"+#include "ov_ops/fully_connected.hpp"++namespace ov {+namespace op {+namespace internal {++FullyConnectedQuantized::FullyConnectedQuantized(const ov::Output<Node>& X,+ const ov::Output<Node>& W,+ const ov::Output<Node>& bias,+ const ov::Output<Node>& weight_scales,+ const ov::Output<Node>& weight_zero_points,+ const ov::Output<Node>& input_scales,+ const ov::Output<Node>& input_zero_points,+ const ov::Output<Node>& output_scales,+ const ov::Output<Node>& output_zero_points,+ const ov::element::Type output_type)+ : FullyConnected(X, W, bias, output_type) {+ set_argument(3, weight_scales);+ set_argument(4, weight_zero_points);+ set_argument(5, input_scales);+ set_argument(6, input_zero_points);+ set_argument(7, output_scales);+ set_argument(8, output_zero_points);+ validate_and_infer_types();+}++std::shared_ptr<ov::Node> FullyConnectedQuantized::clone_with_new_inputs(const ov::OutputVector& new_args) const {+ check_new_args_count(this, new_args);++ return std::make_shared<FullyConnectedQuantized>(new_args.at(0),+ new_args.at(1),+ new_args.at(2),+ new_args.at(3),+ new_args.at(4),+ new_args.at(5),+ new_args.at(6),+ new_args.at(7),+ new_args.at(8),+ m_output_type);+}++// @todo finalize validate_and_infer_types+void FullyConnectedQuantized::validate_and_infer_types() {+ const auto input_size = get_input_size();+ NODE_VALIDATION_CHECK(this, input_size == 9, "Number of inputs is incorrect. Current value is: ", input_size);++ FullyConnected::validate_and_infer_types();+}++} // namespace internal+} // namespace op+} // namespace ovdiff --git a/src/common/transformations/src/ov_ops/fully_connected_quantized_legacy.cpp b/src/common/transformations/src/ov_ops/fully_connected_quantized_legacy.cppnew file mode 100644index 00000000000..42df0980086--- /dev/null+++ b/src/common/transformations/src/ov_ops/fully_connected_quantized_legacy.cpp@@ -0,0 +1,71 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "ov_ops/fully_connected_quantized_legacy.hpp"++#include <memory>++#include "matmul_shape_inference.hpp"+#include "openvino/core/type/element_type.hpp"++namespace ov {+namespace op {+namespace internal {++FullyConnectedQuantizedLegacy::FullyConnectedQuantizedLegacy(const ov::Output<Node>& X,+ const ov::Output<Node>& W,+ const ov::Output<Node>& bias,+ const ov::Output<Node>& deq_scales,+ const ov::Output<Node>& deq_zero_points,+ const ov::element::Type output_type)+ : FullyConnected(X, W, bias, output_type) {+ set_argument(3, deq_scales);+ set_argument(4, deq_zero_points);+ validate_and_infer_types();+}++FullyConnectedQuantizedLegacy::FullyConnectedQuantizedLegacy(const ov::Output<Node>& X,+ const ov::Output<Node>& W,+ const ov::Output<Node>& bias,+ const ov::Output<Node>& deq_scales,+ const ov::element::Type output_type)+ : FullyConnectedQuantizedLegacy(X,+ W,+ bias,+ deq_scales,+ std::make_shared<v0::Constant>(element::undefined, Shape{0}),+ output_type) {}++std::shared_ptr<ov::Node> FullyConnectedQuantizedLegacy::clone_with_new_inputs(const ov::OutputVector& new_args) const {+ check_new_args_count(this, new_args);++ return std::make_shared<FullyConnectedQuantizedLegacy>(new_args.at(0),+ new_args.at(1),+ new_args.at(2),+ new_args.at(3),+ new_args.at(4),+ m_output_type);+}++// @todo finalize validate_and_infer_types+void FullyConnectedQuantizedLegacy::validate_and_infer_types() {+ const auto input_size = get_input_size();++ NODE_VALIDATION_CHECK(this, input_size == 5, "Number of inputs is incorrect. Current value is: ", input_size);++ ov::op::v0::MatMul op;+ op.set_transpose_a(false);+ op.set_transpose_b(true);++ auto out_shapes =+ ov::op::v0::shape_infer(&op,+ std::vector<ov::PartialShape>{get_input_partial_shape(0), get_input_partial_shape(1)});++ auto output_type = m_output_type == ov::element::undefined ? get_input_element_type(0) : m_output_type;+ set_output_type(0, output_type, out_shapes[0]);+}++} // namespace internal+} // namespace op+} // namespace ovdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cppnew file mode 100644index 00000000000..87c3b669d98--- /dev/null+++ b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp@@ -0,0 +1,181 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "transformations/op_conversions/convert_fc_to_compressed.hpp"++#include <algorithm>+#include <memory>++#include "openvino/core/rt_info.hpp"+#include "openvino/core/type/element_type.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/op/transpose.hpp"+#include "openvino/pass/pattern/op/or.hpp"+#include "openvino/pass/pattern/op/pattern.hpp"+#include "openvino/pass/pattern/op/wrap_type.hpp"+#include "ov_ops/fully_connected.hpp"+#include "ov_ops/fully_connected_compressed.hpp"+#include "transformations/utils/utils.hpp"++ov::pass::ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyConnectedCompressed(+ const std::vector<ov::element::Type>& supported_activation_types,+ const std::vector<ov::element::Type>& supported_weights_types,+ SupportsPredicate supports_config,+ bool convert_u4zp_to_u8) {+ using namespace ov::pass::pattern;++ auto reshape_3d_to_2d = [](const ov::Output<ov::Node>& output) {+ auto in_ps = output.get_node()->get_input_partial_shape(0);+ auto out_ps = output.get_node()->get_output_partial_shape(0);+ return in_ps.rank().is_static() && out_ps.rank().is_static() && in_ps.size() == 3 && out_ps.size() == 2;+ };++ auto activation_m = any_input(ov::pass::pattern::type_matches_any(supported_activation_types));+ auto weights_m = wrap_type<ov::op::v0::Constant>(ov::pass::pattern::type_matches_any(supported_weights_types));+ auto convert_m = wrap_type<ov::op::v0::Convert>({weights_m});++ auto sub_const_m = wrap_type<ov::op::v0::Constant>();+ auto sub_convert_const_m = wrap_type<ov::op::v0::Convert>({sub_const_m});+ auto sub_with_convert_m = wrap_type<ov::op::v1::Subtract>({convert_m, sub_convert_const_m});+ auto sub_no_convert_m = wrap_type<ov::op::v1::Subtract>({convert_m, sub_const_m});+ auto subtract_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{sub_with_convert_m, sub_no_convert_m});++ auto mul_const_m = wrap_type<ov::op::v0::Constant>();+ auto mul_convert_const_m = wrap_type<ov::op::v0::Convert>({mul_const_m});+ auto mul_scale_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{mul_const_m, mul_convert_const_m});++ auto mul_with_sub_m = wrap_type<ov::op::v1::Multiply>({subtract_m, mul_scale_m});+ auto mul_no_sub_m = wrap_type<ov::op::v1::Multiply>({convert_m, mul_scale_m});+ auto mul_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{mul_with_sub_m, mul_no_sub_m});++ auto reshape_const_m = wrap_type<ov::op::v0::Constant>();+ auto reshape_m = wrap_type<ov::op::v1::Reshape>({mul_m, reshape_const_m}, reshape_3d_to_2d);++ auto transpose_input = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{reshape_m, mul_m});+ auto transpose_const_m = wrap_type<ov::op::v0::Constant>();+ auto transpose_m = wrap_type<ov::op::v1::Transpose>({transpose_input, transpose_const_m});++ auto bias_m = any_input();+ auto weights_input_m = std::make_shared<ov::pass::pattern::op::Or>(ov::OutputVector{reshape_m, transpose_m, mul_m});+ auto fully_connected_m = wrap_type<ov::op::internal::FullyConnected>({activation_m, weights_input_m, bias_m});++ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ const auto& pattern_map = m.get_pattern_value_map();+ OPENVINO_ASSERT(pattern_map.count(fully_connected_m));+ OPENVINO_ASSERT(pattern_map.count(mul_const_m));+ OPENVINO_ASSERT(pattern_map.count(weights_m));+ OPENVINO_ASSERT(pattern_map.count(bias_m));+ OPENVINO_ASSERT(pattern_map.count(convert_m));+ auto fc = std::dynamic_pointer_cast<ov::op::internal::FullyConnected>(+ pattern_map.at(fully_connected_m).get_node_shared_ptr());+ if (!fc || transformation_callback(fc)) {+ return false;+ }++ bool has_transpose = pattern_map.count(transpose_m);+ auto scale_shape = pattern_map.at(mul_const_m).get_shape();+ bool grouped = std::count_if(scale_shape.begin(), scale_shape.end(), [](size_t d) {+ return d > 1;+ }) > 1;++ auto weights_shape = fc->get_input_shape(1);+ const size_t IC = *(weights_shape.rbegin());+ const size_t OC = *(weights_shape.rbegin() + 1);++ const size_t G = grouped ? (has_transpose ? *(scale_shape.rbegin() + 2) : *(scale_shape.rbegin() + 1)) : 1;++ if (supports_config && !supports_config(fc, IC, OC, G))+ return false;++ auto reshape_const_to_2d = [has_transpose, grouped](std::shared_ptr<ov::Node> node) {+ auto constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(node);+ OPENVINO_ASSERT(constant != nullptr);+ ov::Shape current_shape = constant->get_shape();+ if (current_shape.size() <= 2)+ return constant;++ OPENVINO_ASSERT(current_shape.size() == 3);++ auto new_shape = (has_transpose || !grouped)+ ? ov::Shape{current_shape[0] * current_shape[1], current_shape[2]}+ : ov::Shape{current_shape[0], current_shape[1] * current_shape[2]};++ return std::make_shared<ov::op::v0::Constant>(*constant, new_shape);+ };++ auto convert_u4const_to_u8 = [convert_u4zp_to_u8](std::shared_ptr<ov::Node> node) -> std::shared_ptr<ov::Node> {+ auto constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(node);+ if (constant->get_element_type() != ov::element::u4 || !convert_u4zp_to_u8)+ return std::dynamic_pointer_cast<ov::Node>(constant);+ return std::make_shared<ov::op::v0::Convert>(node, ov::element::u8);+ };++ const ov::Output<Node>& fc_input_a = fc->input_value(0);+ const auto& scale = reshape_const_to_2d(pattern_map.at(mul_const_m).get_node_shared_ptr());+ std::shared_ptr<ov::Node> optional_zero_point = nullptr;++ const bool with_zero_point =+ pattern_map.count(sub_no_convert_m) > 0 || pattern_map.count(sub_with_convert_m) > 0;+ if (with_zero_point) {+ // WA: Convert ZP to u8 for OneDNN case to avoid u4 reorder+ optional_zero_point =+ convert_u4const_to_u8(reshape_const_to_2d(pattern_map.at(sub_const_m).get_node_shared_ptr()));+ }++ std::shared_ptr<ov::Node> fc_input_b = reshape_const_to_2d(pattern_map.at(weights_m).get_node_shared_ptr());+ std::shared_ptr<ov::Node> fc_input_scale = scale;+ std::shared_ptr<ov::Node> fc_input_zp = optional_zero_point;+ std::shared_ptr<ov::Node> fc_input_bias = pattern_map.at(bias_m).get_node_shared_ptr();+ std::vector<std::shared_ptr<ov::Node>> result_nodes = {};+ if (has_transpose) {+ const auto& transpose = pattern_map.at(transpose_m).get_node_shared_ptr();+ std::shared_ptr<ov::Node> transpose_const = pattern_map.at(transpose_const_m).get_node_shared_ptr();+ if (ov::shape_size(transpose_const->get_shape()) != fc_input_b->get_output_partial_shape(0).size()) {+ std::vector<int32_t> new_order(fc_input_b->get_output_partial_shape(0).size());+ std::iota(new_order.begin(), new_order.end(), 0);+ std::swap(new_order[new_order.size() - 1], new_order[new_order.size() - 2]);+ transpose_const =+ std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{new_order.size()}, new_order);+ }++ fc_input_b = transpose->clone_with_new_inputs({fc_input_b->output(0), transpose_const});+ ov::disable_constant_folding(fc_input_b);+ result_nodes.push_back(fc_input_b);+ fc_input_scale = transpose->clone_with_new_inputs({scale->output(0), transpose_const});+ ov::disable_constant_folding(fc_input_scale);+ result_nodes.push_back(fc_input_scale);+ if (with_zero_point && ov::shape_size(optional_zero_point->output(0).get_shape()) > 1) {+ fc_input_zp = transpose->clone_with_new_inputs({optional_zero_point->output(0), transpose_const});+ ov::disable_constant_folding(fc_input_zp);+ result_nodes.push_back(fc_input_zp);+ }+ }++ fc_input_zp =+ with_zero_point ? fc_input_zp : std::make_shared<ov::op::v0::Constant>(element::undefined, Shape{0});+ ov::disable_constant_folding(fc_input_zp);+ result_nodes.push_back(fc_input_zp);++ auto new_fc = std::make_shared<ov::op::internal::FullyConnectedCompressed>(fc_input_a,+ fc_input_b,+ fc_input_bias,+ fc_input_scale,+ fc_input_zp,+ fc->get_output_type());++ result_nodes.push_back(new_fc);+ new_fc->set_friendly_name(fc->get_friendly_name());+ ov::copy_runtime_info(m.get_matched_nodes(), result_nodes);+ ov::replace_node(fc, new_fc);+ return true;+ };++ auto m = std::make_shared<ov::pass::pattern::Matcher>(fully_connected_m,+ "ConvertFullyConnectedToFullyConnectedCompressed");+ this->register_matcher(m, callback);+}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cppnew file mode 100644index 00000000000..908e36a51a7--- /dev/null+++ b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp@@ -0,0 +1,77 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "transformations/op_conversions/convert_fc_to_quantized_legacy.hpp"++#include <memory>++#include "openvino/core/rt_info.hpp"+#include "openvino/core/type/element_type.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/multiply.hpp"+#include "openvino/pass/pattern/op/label.hpp"+#include "openvino/pass/pattern/op/pattern.hpp"+#include "openvino/pass/pattern/op/wrap_type.hpp"+#include "ov_ops/fully_connected.hpp"+#include "ov_ops/fully_connected_quantized_legacy.hpp"+#include "transformations/utils/utils.hpp"++ov::pass::ConvertFCToFCQuantizedLegacy::ConvertFCToFCQuantizedLegacy() {+ using namespace ov::pass::pattern;++ std::vector<element::Type> activation_types{ov::element::u8, ov::element::i8};+ std::vector<element::Type> weights_types{ov::element::i8};++ auto activations_m = pattern::any_input(ov::pass::pattern::type_matches_any(activation_types));+ auto weights_m = wrap_type<ov::op::v0::Constant>(ov::pass::pattern::type_matches_any(weights_types));+ auto bias_m = pattern::any_input();++ auto fully_connected_m = wrap_type<ov::op::internal::FullyConnected>({activations_m, weights_m, bias_m});+ auto dequantization_scales_m = wrap_type<ov::op::v0::Constant>();+ auto multiply_m = wrap_type<ov::op::v1::Multiply>({fully_connected_m, dequantization_scales_m});++ ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ const auto& pattern_map = m.get_pattern_value_map();++ auto fc_output = pattern_map.at(fully_connected_m);+ auto activations = pattern_map.at(activations_m);+ auto weights = pattern_map.at(weights_m);+ auto bias = pattern_map.at(bias_m);+ auto multiply = pattern_map.at(multiply_m);+ auto dequantization_scales = pattern_map.at(dequantization_scales_m);+ const auto& fc_output_shape = fc_output.get_partial_shape();+ const auto& multiply_output_shape = multiply.get_partial_shape();++ if (*fc_output_shape.rbegin() != *multiply_output_shape.rbegin()) {+ return false;+ }++ auto fc_node = std::dynamic_pointer_cast<ov::op::internal::FullyConnected>(+ pattern_map.at(fully_connected_m).get_node_shared_ptr());++ ov::NodeVector new_ops;+ auto zp = std::make_shared<ov::op::v0::Constant>(element::undefined, Shape{0});+ new_ops.push_back(zp);++ auto fc_quantized =+ std::make_shared<ov::op::internal::FullyConnectedQuantizedLegacy>(activations,+ weights,+ bias,+ dequantization_scales,+ zp,+ fc_node->get_output_type());+ new_ops.push_back(fc_quantized);++ const auto& multiply_node = multiply.get_node_shared_ptr();+ fc_quantized->set_friendly_name(multiply_node->get_friendly_name());++ ov::copy_runtime_info({multiply_node, fc_node}, new_ops);+ ov::replace_node(multiply_node, fc_quantized);++ return true;+ };++ auto m = std::make_shared<ov::pass::pattern::Matcher>(multiply_m, "ConvertFullyConnectedToFullyConnectedQuantized");+ this->register_matcher(m, callback);+}diff --git a/src/frontends/ir/src/ir_deserializer.cpp b/src/frontends/ir/src/ir_deserializer.cppindex 7c8b6e9d4b9..2d1dfba956e 100644--- a/src/frontends/ir/src/ir_deserializer.cpp+++ b/src/frontends/ir/src/ir_deserializer.cpp@@ -10,6 +10,7 @@#include "openvino/core/except.hpp"#include "openvino/core/meta_data.hpp"#include "openvino/core/rt_info/weightless_caching_attributes.hpp"+#include "openvino/core/type.hpp"#include "openvino/core/type/element_type.hpp"#include "openvino/op/constant.hpp"#include "openvino/op/loop.hpp"@@ -831,7 +832,9 @@ std::shared_ptr<ov::Node> ov::XmlDeserializer::create_node(const std::vector<ov:" has incorrect input with index ",i,"!");- if (ov::element::Type_t::undefined == inputs[i].get_element_type())++ if (is_type<op::v0::Parameter>(inputs[i].get_node_shared_ptr()) &&+ ov::element::Type_t::undefined == inputs[i].get_element_type())OPENVINO_THROW(params.type," layer ",params.name,diff --git a/src/plugins/intel_cpu/src/cpu_types.cpp b/src/plugins/intel_cpu/src/cpu_types.cppindex 3b6440e56c3..30884bbe649 100644--- a/src/plugins/intel_cpu/src/cpu_types.cpp+++ b/src/plugins/intel_cpu/src/cpu_types.cpp@@ -41,6 +41,9 @@ static const TypeToNameMap& get_type_to_name_tbl() {{"GroupConvolution", Type::Convolution},{"MatMul", Type::MatMul},{"FullyConnected", Type::FullyConnected},+ {"FullyConnectedCompressed", Type::FullyConnected},+ {"FullyConnectedQuantizedLegacy", Type::FullyConnected},+ {"FullyConnectedQuantized", Type::FullyConnected},{"MaxPool", Type::Pooling},{"AvgPool", Type::Pooling},{"AdaptiveMaxPool", Type::AdaptivePooling},@@ -469,6 +472,10 @@ std::string algToString(const Algorithm alg) {CASE(FQCommon);CASE(FQQuantization);CASE(FQBinarization);+ CASE(FullyConnectedCommon);+ CASE(FullyConnectedCompressed);+ CASE(FullyConnectedQuantized);+ CASE(FullyConnectedQuantizedLegacy);CASE(ROIPoolingMax);CASE(ROIPoolingBilinear);CASE(ROIAlignMax);diff --git a/src/plugins/intel_cpu/src/cpu_types.h b/src/plugins/intel_cpu/src/cpu_types.hindex 9461526184b..71088c22af8 100644--- a/src/plugins/intel_cpu/src/cpu_types.h+++ b/src/plugins/intel_cpu/src/cpu_types.h@@ -213,6 +213,12 @@ enum class Algorithm {EltwiseBitwiseLeftShift,EltwiseBitwiseRightShift,+ // FullyConnected algorithms+ FullyConnectedCommon,+ FullyConnectedCompressed,+ FullyConnectedQuantized,+ FullyConnectedQuantizedLegacy,+// FakeQuantize algorithmsFQCommon,FQQuantization,diff --git a/src/plugins/intel_cpu/src/dnnl_postops_composer.cpp b/src/plugins/intel_cpu/src/dnnl_postops_composer.cppindex 2f82fbe553a..70d28f1f4ac 100644--- a/src/plugins/intel_cpu/src/dnnl_postops_composer.cpp+++ b/src/plugins/intel_cpu/src/dnnl_postops_composer.cpp@@ -11,21 +11,69 @@#include <memory>#include <oneapi/dnnl/dnnl.hpp>+#include "cpu_types.h"#include "memory_desc/dnnl_blocked_memory_desc.h"+#include "nodes/executors/memory_arguments.hpp"#include "openvino/core/type/element_type.hpp"+#include "utils/cpu_utils.hpp"#include "utils/debug_capabilities.h"namespace ov {namespace intel_cpu {+static std::vector<float> getDeQuantizedScales(const MemoryArgs& memory) {+ if (!memory.count(ARG_DST_DEQ_SCALE))+ return {};++ auto scalesMemory = memory.at(ARG_DST_DEQ_SCALE);++ auto scalesData = static_cast<const float*>(scalesMemory->getData());++ if (!scalesData)+ return {};++ auto dstShape = memory.at(ARG_DST)->getShape();+ auto dqScalesShape = scalesMemory->getShape();++ auto scalesDims = getNormalizedDimsBySize(dqScalesShape.getDims(), dstShape.getDims().size());++ auto scaleSize = std::accumulate(scalesDims.begin(), scalesDims.end(), std::size_t(1), std::multiplies<size_t>());++ std::vector<float> DQScales(scaleSize, 1.0);++ OPENVINO_ASSERT(scaleSize == 1 || DQScales.size() == 1 || DQScales.size() == scaleSize,+ "set invalid scales size , DQScales vector size: ",+ DQScales.size(),+ ", scale data size: ",+ scaleSize);++ // @todo do we really need to broadcast dq scales and then resize them back?+ if (scaleSize > DQScales.size())+ DQScales.resize(scaleSize, DQScales[0]);+ if (1 == scaleSize) {+ std::transform(DQScales.begin(), DQScales.end(), DQScales.begin(), [=](float val) {+ return (scalesData[0] * val);+ });+ } else {+ for (size_t i = 0; i < DQScales.size(); i++) {+ DQScales[i] *= scalesData[i];+ }+ }+ if (std::all_of(DQScales.begin(), DQScales.end(), [&](float val) {+ return (val == DQScales[0]);+ }))+ DQScales.resize(1);++ return DQScales;+}+DnnlPostOpsComposer::DnnlPostOpsComposer(const PostOps& postOps,const dnnl::engine& engine,const VectorDims& outputDims,const size_t indexOfOutputChannelDim,const bool isInt8,const int weiScaleMaskPerChannel,- const std::vector<float>& DQScales,- const bool hasBias,+ const MemoryArgs& memory,const dnnl::memory::data_type outDataType): engine(engine),postOps(postOps),@@ -39,6 +87,7 @@ DnnlPostOpsComposer::DnnlPostOpsComposer(const PostOps& postOps,dimsPerOC = dimsPerTensor = VectorDims(outputDims.size(), 1);dimsPerOC[idxOC] = OC;+ const auto& DQScales = getDeQuantizedScales(memory);// generalise dq scales, so extra logic is necessary here.if (isINT8) {wei_scale_values = DQScales.empty() ? std::vector<float>{1.0} : DQScales;@@ -49,6 +98,7 @@ DnnlPostOpsComposer::DnnlPostOpsComposer(const PostOps& postOps,updateWeiScales();// If having the bias, attr weight scale can't be updated for further ops-ops optimization.// ONEDNN 3.x quantization for scheme: QuantizedInput * QuantizedWeight * DQScale + Bias.+ const bool hasBias = !memory.at(ARG_BIAS)->getDesc().empty();weightScaleAvailable = !hasBias;} else if (!DQScales.empty()) {// DQ scale is fused but swiching back to non-INT8 for execution in some cases.@@ -325,9 +375,9 @@ static OptimizedFormula updateOptimizedFormula(const FakeQuantizePostOp& postOp,}bool DnnlPostOpsComposer::appendAttrPostOps(const FakeQuantizePostOp& postOp,- bool isLastPostOp,- bool doRounding,- bool allowBinary) {+ bool isLastPostOp,+ bool doRounding,+ bool allowBinary) {DEBUG_LOG("isLastPostOp=",isLastPostOp,", outDataType=",@@ -541,9 +591,9 @@ bool DnnlPostOpsComposer::appendShift(const std::vector<float>& shift, bool allo}bool DnnlPostOpsComposer::appendLinear(const std::vector<float>& scale,- const std::vector<float>& shift,- bool isLastPostOp,- bool allowBinary) {+ const std::vector<float>& shift,+ bool isLastPostOp,+ bool allowBinary) {if (scale.size() == 1 && shift.size() == 1) {if (shift[0] == 0.0f)return appendScale(scale, isLastPostOp, allowBinary);@@ -599,15 +649,27 @@ static MemoryPtr prepackDecompressionParams(const MemoryCPtr& paramsPtr,if (shape.size() == 1 && shape[0] == 1) {shape.push_back(1);}+if (shape.size() != 2 && shape.size() != 3)- OPENVINO_THROW("DnnlPostOpsComposer cannot prepack decompression params with invalid shape");+ OPENVINO_THROW("DnnlPostOpsComposer cannot prepack decompression params with invalid shape");- Shape dstShape = needTranspose ? Shape({shape[0], shape[1]}) : Shape({shape[shape.size() - 1], shape[0]});- DnnlBlockedMemoryDesc dstMemoryDesc(dstShape, DnnlExtensionUtils::ElementTypeToDataType(dstPrc), dnnl::memory::format_tag::io);- auto dstMem = std::make_shared<Memory>(engine, dstMemoryDesc);+ // weights without batch: (OC, G)+ // weights with batch: (B, OC, G)+ const size_t OC = shape[shape.size() - 2];+ const size_t G = shape[shape.size() - 1];++ Shape dstShape = Shape({OC, G});+ DnnlBlockedMemoryDesc dstMemoryDesc(dstShape,+ DnnlExtensionUtils::ElementTypeToDataType(dstPrc),+ dnnl::memory::format_tag::io);+ auto dstMem = std::make_shared<Memory>(engine, dstMemoryDesc);auto srcFormat = needTranspose ? dnnl::memory::format_tag::oi : dnnl::memory::format_tag::io;- DnnlBlockedMemoryDesc srcMemoryDesc(dstShape, DnnlExtensionUtils::ElementTypeToDataType(paramsPtr->getDescPtr()->getPrecision()), srcFormat);++ DnnlBlockedMemoryDesc srcMemoryDesc(+ dstShape,+ DnnlExtensionUtils::ElementTypeToDataType(paramsPtr->getDescPtr()->getPrecision()),+ srcFormat);auto srcMem = std::make_shared<Memory>(engine, srcMemoryDesc, paramsPtr->getData());dstMem->load(*srcMem);@@ -615,25 +677,32 @@ static MemoryPtr prepackDecompressionParams(const MemoryCPtr& paramsPtr,return dstMem;}-void DnnlPostOpsComposer::appendDecompressionScales(const MemoryCPtr& scales_ptr, bool needTranspose, ov::element::Type dstPrecision) {+void DnnlPostOpsComposer::appendDecompressionScales(const MemoryCPtr& scales_ptr,+ bool needTranspose,+ ov::element::Type dstPrecision) {if (scales_ptr == nullptr)return;auto scalesMem = prepackDecompressionParams(scales_ptr, needTranspose, dstPrecision, engine);attr.set_scales_dims(DNNL_ARG_WEIGHTS,- DnnlExtensionUtils::convertToDnnlDims(scalesMem->getStaticDims()), DnnlExtensionUtils::ElementTypeToDataType(dstPrecision));+ DnnlExtensionUtils::convertToDnnlDims(scalesMem->getStaticDims()),+ DnnlExtensionUtils::ElementTypeToDataType(dstPrecision));cpuArgs[DNNL_ARG_ATTR_SCALES | DNNL_ARG_WEIGHTS] = std::move(scalesMem);dnnlArgs[DNNL_ARG_ATTR_SCALES | DNNL_ARG_WEIGHTS] =cpuArgs[DNNL_ARG_ATTR_SCALES | DNNL_ARG_WEIGHTS]->getPrimitive();}-void DnnlPostOpsComposer::appendDecompressionZeroPoints(const MemoryCPtr& zero_points_ptr, bool needTranspose, ov::element::Type dstPrecision) {+void DnnlPostOpsComposer::appendDecompressionZeroPoints(const MemoryCPtr& zero_points_ptr,+ bool needTranspose,+ ov::element::Type dstPrecision) {if (zero_points_ptr == nullptr)return;- auto zeroPointsMem = prepackDecompressionParams(zero_points_ptr, needTranspose, dstPrecision, engine);+ auto zeroPointsMem =+ prepackDecompressionParams(zero_points_ptr, needTranspose, dstPrecision, engine);attr.set_zero_points_dims(DNNL_ARG_WEIGHTS,- DnnlExtensionUtils::convertToDnnlDims(zeroPointsMem->getStaticDims()), DnnlExtensionUtils::ElementTypeToDataType(dstPrecision));+ DnnlExtensionUtils::convertToDnnlDims(zeroPointsMem->getStaticDims()),+ DnnlExtensionUtils::ElementTypeToDataType(dstPrecision));cpuArgs[DNNL_ARG_ATTR_ZERO_POINTS | DNNL_ARG_WEIGHTS] = zeroPointsMem;dnnlArgs[DNNL_ARG_ATTR_ZERO_POINTS | DNNL_ARG_WEIGHTS] = zeroPointsMem->getPrimitive();}diff --git a/src/plugins/intel_cpu/src/dnnl_postops_composer.h b/src/plugins/intel_cpu/src/dnnl_postops_composer.hindex c07ec0f608b..8c2718aaaed 100644--- a/src/plugins/intel_cpu/src/dnnl_postops_composer.h+++ b/src/plugins/intel_cpu/src/dnnl_postops_composer.h@@ -27,8 +27,7 @@ public:const size_t indexOfOutputChannelDim,const bool isINT8,const int weiScaleMaskPerChannel,- const std::vector<float>& DQScales,- const bool hasBias,+ const MemoryArgs& memory,const dnnl::memory::data_type outDataType);DnnlPrimitiveAttrs compose();void appendDecompressionScales(const MemoryCPtr& scales_ptr, bool needTranspose, ov::element::Type dstPrecision);diff --git a/src/plugins/intel_cpu/src/edge.cpp b/src/plugins/intel_cpu/src/edge.cppindex 82bde8edae2..c49b924477f 100644--- a/src/plugins/intel_cpu/src/edge.cpp+++ b/src/plugins/intel_cpu/src/edge.cpp@@ -5,6 +5,7 @@#include "edge.h"#include "node.h"#include "dnnl_extension_utils.h"+#include "openvino/core/type/element_type.hpp"#include "openvino/util/pp.hpp"using namespace dnnl;@@ -212,6 +213,10 @@ Edge::ReorderStatus Edge::needReorder() {bool optimized = false;auto inputPortDesc = getInputPortDesc();auto outPortDesc = getOutputPortDesc();++ if (inputPortDesc->getMemDesc()->getPrecision() == element::undefined)+ return ReorderStatus::No;+// Check whether the child node may accept the parent produced tensorif (!outPortDesc->isCompatible(*inputPortDesc)) {// Performance optimization which exploit the fact that some tensors do not need actual data reordering to be read using different descriptors@@ -410,6 +415,9 @@ const MemoryDesc& Edge::getOutputDesc() const {}const MemoryDesc& Edge::getDesc() const {+ if (getInputDesc().getPrecision() == element::undefined)+ return getInputDesc();+if (!getInputDesc().isCompatible(getOutputDesc()))OPENVINO_THROW("Cannot get descriptor for edge: ", getParent()->getName(), "->", getChild()->getName());diff --git a/src/plugins/intel_cpu/src/extension.cpp b/src/plugins/intel_cpu/src/extension.cppindex a29282d4af3..e6dbc04b0ca 100644--- a/src/plugins/intel_cpu/src/extension.cpp+++ b/src/plugins/intel_cpu/src/extension.cpp@@ -7,6 +7,10 @@#include "openvino/core/op_extension.hpp"#include "ov_ops/augru_cell.hpp"#include "ov_ops/augru_sequence.hpp"+#include "ov_ops/fully_connected.hpp"+#include "ov_ops/fully_connected_compressed.hpp"+#include "ov_ops/fully_connected_quantized_legacy.hpp"+#include "ov_ops/fully_connected_quantized.hpp"#include "ov_ops/gather_compressed.hpp"#include "ov_ops/multiclass_nms_ie_internal.hpp"#include "ov_ops/nms_ie_internal.hpp"@@ -16,7 +20,6 @@#include "ov_ops/type_relaxed.hpp"#include "snippets/op/subgraph.hpp"#include "transformations/cpu_opset/common/op/causal_mask_preprocess.hpp"-#include "transformations/cpu_opset/common/op/fully_connected.hpp"#include "transformations/cpu_opset/common/op/leaky_relu.hpp"#include "transformations/cpu_opset/common/op/ngram.hpp"#include "transformations/cpu_opset/common/op/power_static.hpp"@@ -70,7 +73,6 @@ private:#endif#define CPU_EXTENSIONS \- OP_EXTENSION(ov::intel_cpu::FullyConnectedNode) \OP_EXTENSION(ov::intel_cpu::LeakyReluNode) \OP_EXTENSION(ov::intel_cpu::PowerStaticNode) \OP_EXTENSION(ov::intel_cpu::CausalMaskPreprocessNode) \@@ -85,6 +87,10 @@ private:OP_EXTENSION(ov::op::internal::NmsStaticShapeIE<ov::op::v8::MatrixNms>) \OP_EXTENSION(ov::op::internal::RMS) \OP_EXTENSION(ov::op::internal::RoPE) \+ OP_EXTENSION(ov::op::internal::FullyConnected) \+ OP_EXTENSION(ov::op::internal::FullyConnectedCompressed) \+ OP_EXTENSION(ov::op::internal::FullyConnectedQuantizedLegacy) \+ OP_EXTENSION(ov::op::internal::FullyConnectedQuantized) \OP_EXTENSION_X64(ov::intel_cpu::MHANode) \OP_EXTENSION_X64(ov::intel_cpu::InteractionNode) \OP_EXTENSION_X64(ov::intel_cpu::LLMMLPNode) \diff --git a/src/plugins/intel_cpu/src/graph_optimizer.cpp b/src/plugins/intel_cpu/src/graph_optimizer.cppindex 61590b8691f..94f54fc4c59 100644--- a/src/plugins/intel_cpu/src/graph_optimizer.cpp+++ b/src/plugins/intel_cpu/src/graph_optimizer.cpp@@ -67,10 +67,6 @@ void GraphOptimizer::ApplyCommonGraphOptimizations(Graph &graph) {FuseConvMatmulFCDeconvAndDQScales(graph);graph.RemoveDroppedNodes();- OV_ITT_SCOPE_NEXT(FIRST_INFERENCE, taskChain, "FuseFCAndWeightsDecompression");- FuseFCAndWeightsDecompression(graph);- graph.RemoveDroppedNodes();-OV_ITT_SCOPE_NEXT(FIRST_INFERENCE, taskChain, "FuseConvolutionAndBias");FuseConvolutionMatMulDeconvAndBias(graph);graph.RemoveDroppedNodes();@@ -217,8 +213,7 @@ void GraphOptimizer::FuseConvMatmulFCDeconvAndDQScales(Graph &graph) {auto scaleNode = node->getParentEdgeAt(1)->getParent();if (!(parentNode->getType() == Type::Convolution|| parentNode->getType() == Type::MatMul- || parentNode->getType() == Type::Deconvolution- || parentNode->getType() == Type::FullyConnected))+ || parentNode->getType() == Type::Deconvolution))return false;if (!scaleNode->isConstant())return false;@@ -292,257 +287,6 @@ void GraphOptimizer::FuseConvMatmulFCDeconvAndDQScales(Graph &graph) {}}-void GraphOptimizer::FuseFCAndWeightsDecompression(Graph &graph) {- std::set<ov::element::Type> supportedWeightsPrecisions{- ov::element::u8, ov::element::i8, ov::element::nf4, ov::element::u4, ov::element::i4, ov::element::f4e2m1};- const std::set<ov::element::Type> supportedDataPrecisions{ov::element::f32, ov::element::bf16};- auto expectedNode = [](NodePtr node, Type expectedType) {- return node->getType() == expectedType && node->getChildEdges().size() == 1;- };--#define SKIP_FUSION_FOR_NODE(node) \- DEBUG_LOG("FuseFCAndWeightsDecompression can't be applied for node ", node->getName()); \- continue-- if (!impl::cpu::x64::mayiuse(impl::cpu::x64::avx2))- return;-- auto& graphNodes = graph.GetNodes();- for (size_t i = 0; i < graphNodes.size(); i++) {- const auto fcNode = std::dynamic_pointer_cast<node::FullyConnected>(graphNodes[i]);- if (fcNode == nullptr)- continue;-- auto parent = fcNode->getParentEdgeAt(1)->getParent();- const bool withTranspose = parent->getType() == Type::Transpose;- const NodePtr transposeNode = withTranspose ? parent : nullptr;- if (transposeNode)- parent = transposeNode->getParentEdgeAt(0)->getParent();- // Compressed weights can be shared between several FC layers- const bool is_shared_decompression = parent->getChildEdges().size() > 1;-- const bool withReshape = parent->getType() == Type::Reshape;- const auto reshapeNode = withReshape ? parent : nullptr;- if (reshapeNode) {- parent = reshapeNode->getParentEdgeAt(0)->getParent();- }-- const auto multiplyNode = parent;- if (multiplyNode->getType() != Type::Eltwise || multiplyNode->getAlgorithm() != Algorithm::EltwiseMultiply ||- !multiplyNode->isConstant()) {- SKIP_FUSION_FOR_NODE(fcNode);- }-- CPU_GRAPH_OPTIMIZER_SCOPE(FuseFCAndWeightsDecompression);- const auto mulParent1 = multiplyNode->getParentEdgeAt(1)->getParent();- NodePtr multiplyParent, multiplyConvertNode, multiplyConstNode;- multiplyParent = mulParent1;- if (multiplyParent->getType() == Type::Convert) {- multiplyConvertNode = multiplyParent;- multiplyParent = multiplyConvertNode->getParentEdgeAt(0)->getParent();- }- multiplyConstNode = multiplyParent;- if (multiplyConstNode->getType() != Type::Input) {- SKIP_FUSION_FOR_NODE(fcNode);- }- const bool withMultiplyConvert = multiplyConvertNode != nullptr;-- const auto mulParent0 = multiplyNode->getParentEdgeAt(0)->getParent();- const bool withSubtract = mulParent0->getAlgorithm() == Algorithm::EltwiseSubtract;- NodePtr subtractNode, subtractConvertNode, subtractConstNode;- if (withSubtract) {- subtractNode = mulParent0;- if (!expectedNode(subtractNode, Type::Eltwise)) {- SKIP_FUSION_FOR_NODE(fcNode);- }- auto subtractParent = subtractNode->getParentEdgeAt(1)->getParent();- if (subtractParent->getType() == Type::Convert) {- subtractConvertNode = subtractParent;- subtractParent = subtractConvertNode->getParentEdgeAt(0)->getParent();- }- subtractConstNode = subtractParent;- if (subtractConstNode->getType() != Type::Input) {- SKIP_FUSION_FOR_NODE(fcNode);- }- }-- const bool withSubtractConvert = subtractConvertNode != nullptr;- const auto convertNode = withSubtract ? subtractNode->getParentEdgeAt(0)->getParent() : mulParent0;- if (!expectedNode(convertNode, Type::Convert)) {- SKIP_FUSION_FOR_NODE(fcNode);- }- const auto weightsNode = convertNode->getParentEdgeAt(0)->getParent();- if (weightsNode->getType() != Type::Input) {- SKIP_FUSION_FOR_NODE(fcNode);- }-- // Precision limitations- if (supportedDataPrecisions.find(fcNode->getOriginalInputPrecisionAtPort(0)) == supportedDataPrecisions.end()) {- SKIP_FUSION_FOR_NODE(fcNode);- }- if (supportedWeightsPrecisions.find(weightsNode->getOriginalOutputPrecisionAtPort(0)) == supportedWeightsPrecisions.end()) {- SKIP_FUSION_FOR_NODE(fcNode);- }- if (withSubtract &&- !one_of(subtractConstNode->getOriginalOutputPrecisionAtPort(0), weightsNode->getOriginalOutputPrecisionAtPort(0), ov::element::f32)) {- SKIP_FUSION_FOR_NODE(fcNode);- }-- // Shape limitations- const auto weightsShape = weightsNode->getOutputShapeAtPort(0);- if (weightsShape != multiplyNode->getOutputShapeAtPort(0)) {- SKIP_FUSION_FOR_NODE(fcNode);- }- if (reshapeNode && (reshapeNode->getInputShapeAtPort(0).getRank() != 3 || reshapeNode->getOutputShapeAtPort(0).getRank() != 2)) {- SKIP_FUSION_FOR_NODE(fcNode);- }-- VectorDims decompressionConstShape;- const auto fcInputWeightsShape = fcNode->getInputShapeAtPort(1);- int groupNum = 1;- // Ordinary case: one decompression group- if (fcInputWeightsShape.getRank() == weightsShape.getRank()) {- const auto& out_channels = fcInputWeightsShape.getDims()[0];- decompressionConstShape = withTranspose ? VectorDims{1, out_channels} : VectorDims{out_channels, 1};- } else {- // Group decompression case: last 3 dimension (there could be also prepending '1's in the beginning) of weights shape must be:- // [N, G, O], if transpose = true- // [O, N, G], otherwise.- // O - output channels- // N - number of groups- // G - group size- const auto& weights_dims = weightsShape.getStaticDims();- const auto& N = withTranspose ? *(weights_dims.rbegin() + 2) : *(weights_dims.rbegin() + 1);- const auto& O = withTranspose ? *weights_dims.rbegin() : *(weights_dims.rbegin() + 2);- // Group decompression is applied by O and N dims- decompressionConstShape = withTranspose ? VectorDims{N, 1, O} : VectorDims{O, N, 1};- groupNum = N;- }-- auto check_decompression_shape = [&decompressionConstShape](const VectorDims& shape_to_check) {- if (shape_to_check.size() > decompressionConstShape.size())- return false;- if (std::all_of(shape_to_check.begin(), shape_to_check.end(), [](Dim x) { return x == 1; }))- return true;- const auto comparison_start_pos = decompressionConstShape.size() - shape_to_check.size();- // in case of different ranks shapes are compared taking into account ranks numpy broadcasting- return std::equal(shape_to_check.begin(), shape_to_check.end(), decompressionConstShape.begin() + comparison_start_pos);- };- if (!check_decompression_shape(multiplyConstNode->getOutputShapeAtPort(0).getDims())) {- SKIP_FUSION_FOR_NODE(fcNode);- }- if (withSubtract && !check_decompression_shape(subtractConstNode->getOutputShapeAtPort(0).getDims())) {- SKIP_FUSION_FOR_NODE(fcNode);- }-- const size_t OC = fcInputWeightsShape.getDims()[0];- const size_t IC = fcInputWeightsShape.getDims()[1];- // HW specific shape limitations- if (impl::cpu::x64::mayiuse(impl::cpu::x64::avx512_core_amx) &&- fcNode->getOriginalInputPrecisionAtPort(0) == ov::element::bf16) {- // OneDNN AMX IP implementation has limited shapes support due to performance considerations. As a current solution conditions below are copied- // from OneDNN to make sure correct IP impl will be used since fallback one doesn't support weights decompression feature.- size_t simdWidth = 16;- size_t vnniFactor = 2;- size_t maxSize = 512;- auto amxRow = vnniFactor * simdWidth;-- if ((IC <= amxRow && OC <= amxRow) || (IC <= maxSize && OC <= maxSize && IC % amxRow != 0)) {- SKIP_FUSION_FOR_NODE(fcNode);- }- }-- // OneDNN IP primitive provides limited decompression params support- if (IC % groupNum != 0 || IC / groupNum < 4 || OC == 1) {- SKIP_FUSION_FOR_NODE(fcNode);- }-- // Fusion processing- auto *multiplyInputNode = dynamic_cast<node::Input *>(multiplyConstNode.get());- OPENVINO_ASSERT(multiplyInputNode, "Cannot cast ", multiplyConstNode->getName(), " to Input node.");- fcNode->fuseDecompressionMultiply(multiplyInputNode->getMemoryPtr());-- if (withSubtract) {- auto *subtractInputNode = dynamic_cast<node::Input *>(subtractConstNode.get());- OPENVINO_ASSERT(multiplyInputNode, "Cannot cast ", subtractConstNode->getName(), " to Input node.");- fcNode->fuseDecompressionSubtract(subtractInputNode->getMemoryPtr());- }-- fcNode->addOriginalLayer(multiplyNode->getOriginalLayers());- fcNode->addOriginalLayer(convertNode->getOriginalLayers());- if (withSubtract)- fcNode->addOriginalLayer(subtractNode->getOriginalLayers());- if (withSubtractConvert)- fcNode->addOriginalLayer(subtractConvertNode->getOriginalLayers());- if (withMultiplyConvert)- fcNode->addOriginalLayer(multiplyConvertNode->getOriginalLayers());-- const auto& weightsPrecision = weightsNode->getOriginalOutputPrecisionAtPort(0);- if (withTranspose) {- transposeNode->setOriginalInputPrecisionAtPort(0, weightsPrecision);- transposeNode->setOriginalOutputPrecisionAtPort(0, weightsPrecision);- }- if (withReshape) {- reshapeNode->setOriginalInputPrecisionAtPort(0, weightsPrecision);- reshapeNode->setOriginalOutputPrecisionAtPort(0, weightsPrecision);- }- fcNode->setOriginalInputPrecisionAtPort(1, weightsPrecision);-- // If decompression subgraph is shared with other nodes, it mustn't be removed.- // In this case, the current FC is reconnected to the weights- if (is_shared_decompression) {- const auto weights_out_edge = weightsNode->getChildEdges()[0].lock();- const auto fc_weights_path_edge = withTranspose ? transposeNode->getParentEdgeAt(0)- : fcNode->getParentEdgeAt(1);- const auto inNum = weights_out_edge->getInputNum();- const auto outNum = fc_weights_path_edge->getOutputNum();- graph.RemoveEdge(fc_weights_path_edge);- // In case of shared group decompression, Reshape node has to be copied for the current FC- if (withReshape) {- const auto& reshapeOutShape = reshapeNode->getOutputShapeAtPort(0).getStaticDims();- auto reshapeConst = std::make_shared<ov::opset1::Constant>(ov::element::i32,- ov::Shape{reshapeOutShape.size()},- reshapeOutShape);- auto reshapeDummyInput = std::make_shared<ov::opset1::Parameter>(reshapeNode->getOriginalInputPrecisionAtPort(0),- reshapeNode->getInputShapeAtPort(0).toPartialShape());- const auto reshape = std::make_shared<ov::opset1::Reshape>(reshapeDummyInput, reshapeConst, false);- reshape->set_friendly_name(reshapeNode->getName() + "_copy");- const auto cpuReshape = std::make_shared<ov::intel_cpu::node::Reshape>(reshape, graph.getGraphContext());- graph.InsertNode(weightsNode, withTranspose ? transposeNode : fcNode, cpuReshape, inNum, outNum, false);- const auto cpuReshapeConst = std::make_shared<node::Input>(reshapeConst, graph.getGraphContext());- graph.AddNode(cpuReshapeConst);- graph.CreateEdge(cpuReshapeConst, cpuReshape, 0, 1);- } else {- graph.CreateEdge(weightsNode, withTranspose ? transposeNode : fcNode, inNum, outNum);- }- } else {- // If decompression subgraph is not shared with other nodes, it can be removed- if (withSubtract)- graph.RemoveEdge(subtractNode->getParentEdgeAt(1));- if (withSubtractConvert) {- // SubtractConvert is removed only if there are no other consumers (e.g. CompressedGather)- const auto& restChilds = subtractConvertNode->getChildEdges();- if (restChilds.empty())- graph.RemoveEdge(subtractConvertNode->getParentEdgeAt(0));- }- graph.RemoveEdge(multiplyNode->getParentEdgeAt(1));- if (withMultiplyConvert) {- // MultiplyConvert is removed only if there are no other consumers (e.g. CompressedGather)- const auto& restChilds = multiplyConvertNode->getChildEdges();- if (restChilds.empty())- graph.RemoveEdge(multiplyConvertNode->getParentEdgeAt(0));- }-- graph.DropNode(convertNode);- if (withSubtract)- graph.DropNode(subtractNode);- graph.DropNode(multiplyNode);- }- DEBUG_LOG("FuseFCAndWeightsDecompression finished for node ", fcNode->getName());- }-#undef SKIP_FUSION_FOR_NODE-}-void GraphOptimizer::FuseConvolutionMatMulDeconvAndBias(Graph &graph) {auto& graphNodes = graph.GetNodes();@@ -556,7 +300,7 @@ void GraphOptimizer::FuseConvolutionMatMulDeconvAndBias(Graph &graph) {return false;if (!deconv)- return (one_of(node->getType(), Type::Convolution, Type::MatMul, Type::FullyConnected) &&+ return (one_of(node->getType(), Type::Convolution, Type::MatMul) &&node->getParentEdges().size() == 2);elsereturn deconv->canFuseBias();@@ -984,9 +728,7 @@ void GraphOptimizer::FuseFCAndTransposeOnWeights(Graph& graph) {auto isSuitablePattern = [](NodePtr parent) {bool res = true && parent->getType() == Type::Transpose&& parent->getChildEdges().size() == 1- && parent->getChildEdgeAt(0)->getOutputNum() == 1&& parent->getChildEdgeAt(0)->getChild()->getType() == Type::FullyConnected- && parent->getOutputShapeAtPort(0).getRank() == 2&& parent->isConstant();return res;};diff --git a/src/plugins/intel_cpu/src/graph_optimizer.h b/src/plugins/intel_cpu/src/graph_optimizer.hindex 886296a7c00..536ef468a09 100644--- a/src/plugins/intel_cpu/src/graph_optimizer.h+++ b/src/plugins/intel_cpu/src/graph_optimizer.h@@ -20,7 +20,6 @@ public:private:void FuseConvMatmulFCDeconvAndDQScales(Graph &graph);- void FuseFCAndWeightsDecompression(Graph &graph);void FuseConvolutionMatMulDeconvAndBias(Graph &graph);void FuseDeconvolutionAndSimpleOperation(Graph &graph);void FuseMultiplyAndAdd(Graph &graph);diff --git a/src/plugins/intel_cpu/src/memory_desc/empty_memory_desc.h b/src/plugins/intel_cpu/src/memory_desc/empty_memory_desc.hindex 4b641669262..1575841cb2b 100644--- a/src/plugins/intel_cpu/src/memory_desc/empty_memory_desc.h+++ b/src/plugins/intel_cpu/src/memory_desc/empty_memory_desc.h@@ -59,7 +59,9 @@ public:}MemoryDescPtr cloneWithNewPrecision(const ov::element::Type prec) const override {- OPENVINO_THROW("Clone an empty memory desc with any precision (", prec, ") is prohibited");+ OPENVINO_ASSERT(prec == ov::element::undefined,+ "Clone an empty memory desc with defined precision: ", prec, " is prohibited");+ return clone();}private:diff --git a/src/plugins/intel_cpu/src/node.cpp b/src/plugins/intel_cpu/src/node.cppindex de5c5342913..ee0a99c3bba 100644--- a/src/plugins/intel_cpu/src/node.cpp+++ b/src/plugins/intel_cpu/src/node.cpp@@ -6,6 +6,7 @@#include "cpu_types.h"#include "edge.h"#include "partitioned_mem_blk.h"+#include "openvino/core/type/element_type.hpp"#include <memory>#include <oneapi/dnnl/dnnl.hpp>@@ -1673,7 +1674,7 @@ bool Node::isInputTensorAtPortEmpty(size_t port) const {auto edge = getParentEdgeAt(port);if (one_of(edge->getStatus(), Edge::Status::Allocated, Edge::Status::Validated)) {auto&& mem = edge->getMemory();- if (mem.isDefined()) {+ if (mem.isDefined() && !mem.getDesc().empty()) {return mem.getShape().hasZeroDims();}}diff --git a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_fullyconnected.cpp b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_fullyconnected.cppindex cc42691950a..9660178e1af 100644--- a/src/plugins/intel_cpu/src/nodes/executors/acl/acl_fullyconnected.cpp+++ b/src/plugins/intel_cpu/src/nodes/executors/acl/acl_fullyconnected.cpp@@ -11,6 +11,7 @@#include "nodes/executors/executor.hpp"#include "nodes/executors/memory_arguments.hpp"#include "utils/debug_capabilities.h"+#include "utils/cpu_utils.hpp"#include "nodes/executors/debug_messages.hpp"#include "nodes/executors/implementation_utils.hpp"#include "nodes/convert.h"@@ -201,9 +202,22 @@ static MemoryPtr prepareWeightMemory(const MemoryArgs &memory,MemoryArgs memoryArgs;memoryArgs[ARG_BIAS] = memory.at(ARG_BIAS);memoryArgs[ARG_WEI] = memory.at(ARG_WEI);++ auto originalWeightsDesc = memory.at(ARG_WEI)->getDescPtr();++ // normalize weights to 2D+ const auto& wgtDims = originalWeightsDesc->getShape().getStaticDims();+ const VectorDims wgtDims2D = reshapeDownToRank<2>(wgtDims);++ originalWeightsDesc = std::make_shared<CpuBlockedMemoryDesc>(originalWeightsDesc->getPrecision(), Shape{wgtDims2D});++ auto dnnlSrcDesc = MemoryDescUtils::convertToDnnlMemoryDesc(originalWeightsDesc);+ auto dstDesc = originalWeightsDesc->cloneWithNewPrecision(aclfcAttrs.inputPrecision);+ auto dnnlDstDesc = MemoryDescUtils::convertToDnnlMemoryDesc(dstDesc);+if (memory.at(ARG_SRC_0)->getShape().isDynamic()) {const auto& inShape = memory.at(ARG_SRC_0)->getShape();- const auto& wShape = memory.at(ARG_WEI)->getShape();+ const auto& wShape = originalWeightsDesc->getShape();const auto& inDymmyDims = makeDummyInputDims(inShape, wShape);const auto& outDymmyDims = makeDummyOutputDims(inDymmyDims, wShape.getStaticDims(), memory.at(ARG_DST)->getShape().getRank());memoryArgs[ARG_SRC_0] = std::make_shared<Memory>(context->getEngine(),@@ -214,6 +228,7 @@ static MemoryPtr prepareWeightMemory(const MemoryArgs &memory,memoryArgs[ARG_SRC_0] = memory.at(ARG_SRC_0);memoryArgs[ARG_DST] = memory.at(ARG_DST);}+// TODO: ACLWeightFormatGenerator should be replaced with Reorder executor// that calls ACL NEReorder + NETranspose or dnnl::reorder depending on backend availabilityauto aclWeightsRepack = std::make_shared<acl_fc_executor::ACLWeightFormatGenerator>(attrs, postOps, memoryArgs);@@ -221,13 +236,6 @@ static MemoryPtr prepareWeightMemory(const MemoryArgs &memory,expectedWeightFormat = isNeededReorder ? aclWeightsRepack->getOptImplWeightFormat() : arm_compute::WeightFormat::UNSPECIFIED;weiTensorInfo = aclWeightsRepack->getTensorInfo(ACLArgs::ACL_WEI);- MemoryPtr dstMemPtr = std::make_shared<Memory>(context->getEngine(),- memory.at(ARG_WEI)->getDescPtr()->cloneWithNewPrecision(aclfcAttrs.inputPrecision));- auto dstDesc = dstMemPtr->getDescPtr();- auto dnnlDstDesc = MemoryDescUtils::convertToDnnlMemoryDesc(dstDesc);- auto weiDesc = memory.at(ARG_WEI)->getDescPtr();- auto dnnlSrcDesc = MemoryDescUtils::convertToDnnlMemoryDesc(weiDesc);-if (isNeededReorder) {dnnl::impl::dim_t o_dim = 0;dnnl::impl::dim_t inner_dim = 1;diff --git a/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_convolution_primitive.cpp b/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_convolution_primitive.cppindex 8f9d7ad0805..61aca683a37 100644--- a/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_convolution_primitive.cpp+++ b/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_convolution_primitive.cpp@@ -157,8 +157,7 @@ static DnnlPrimitiveAttrs createPrimitiveAttrs(const ConvAttrs& attrs,one_of(srcDesc->getPrecision(), ov::element::u8, ov::element::i8) && weiDesc->getPrecision() == ov::element::i8;auto outputDataType = DnnlExtensionUtils::ElementTypeToDataType(dstDesc->getPrecision());- DnnlPostOpsComposer- dnnlpoc(postOps, context->getEngine(), dims, 1, isINT8, 1 << 0, {}, attrs.withBias, outputDataType);+ DnnlPostOpsComposer dnnlpoc(postOps, context->getEngine(), dims, 1, isINT8, 1 << 0, memory, outputDataType);return dnnlpoc.compose();}diff --git a/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_fullyconnected_primitive.cpp b/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_fullyconnected_primitive.cppindex fcb70d4753b..780dbb6f2f3 100644--- a/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_fullyconnected_primitive.cpp+++ b/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_fullyconnected_primitive.cpp@@ -9,6 +9,7 @@#include <common/primitive_attr.hpp>#include <common/primitive_desc_iface.hpp>#include <common/primitive_iface.hpp>+#include <cstddef>#include <memory>#include <oneapi/dnnl/dnnl.hpp>#include <oneapi/dnnl/dnnl_common.hpp>@@ -27,6 +28,7 @@#include "nodes/executors/executor.hpp"#include "nodes/executors/fullyconnected_config.hpp"#include "nodes/executors/memory_arguments.hpp"+#include "utils/cpu_utils.hpp"#include "utils/debug_capabilities.h"namespace ov {@@ -115,9 +117,10 @@ DnnlMemoryDescPtr DnnlFCPrimitive::makeTransposedWeightDescriptor(const DnnlMemoreturn srcDesc;const auto& weiDesc = srcDesc->getDnnlDesc();- const auto reorderedWeiDesc =- dnnl::memory::desc{weiDesc.get_dims(), weiDesc.get_data_type(), dnnl::memory::format_tag::ba};- const auto transposedWeiDesc = reorderedWeiDesc.reshape(dstDesc->getDnnlDesc().get_dims());+ auto wDims = weiDesc.get_dims();+ dnnl::memory::dims wDims2D = reshapeDownToRank<2>(wDims);++ const auto transposedWeiDesc = dnnl::memory::desc{wDims2D, weiDesc.get_data_type(), dnnl::memory::format_tag::ba};return DnnlExtensionUtils::makeDescriptor(transposedWeiDesc);}@@ -140,12 +143,11 @@ bool DnnlFCPrimitive::useWeightsDecompressionImpl(const ov::element::Type inputTreturn false;}-bool DnnlFCPrimitive::useDynamicQuantizationImpl(size_t dqGroupSize,- const MemoryDescPtr srcDesc,- const MemoryDescPtr weightsDesc,- MemoryCPtr scalesPtr,- MemoryCPtr zpPtr,- bool needTranspose) {+static bool useDynamicQuantizationImpl(size_t dqGroupSize,+ const MemoryDescPtr srcDesc,+ const MemoryDescPtr weightsDesc,+ const MemoryArgs& memory,+ bool needTranspose) {if (dqGroupSize == 0)return false;@@ -155,6 +157,8 @@ bool DnnlFCPrimitive::useDynamicQuantizationImpl(size_t dqGroupSize,if (srcDesc->getPrecision() != ov::element::f32)return false;++ MemoryCPtr zpPtr = memory.count(ARG_WEI | ARG_ATTR_ZERO_POINTS) ? memory.at(ARG_WEI | ARG_ATTR_ZERO_POINTS) : nullptr;// For dynamic quantization, VNNI accumulation requires weight to be unsigned.// To support dynamic quantization with weights symmetrically quantized as i8/i4// w/o zero-point, we will transform weight to u8/u4 weight with zp 128/8.@@ -177,11 +181,15 @@ bool DnnlFCPrimitive::useDynamicQuantizationImpl(size_t dqGroupSize,if (weightsDesc->getPrecision() == ov::element::u4) {int ic = weightsDesc->getShape().getStaticDims()[1];int minGroupSize = INT_MAX;++ MemoryCPtr scalesPtr = memory.count(ARG_WEI | ARG_ATTR_SCALES) ? memory.at(ARG_WEI | ARG_ATTR_SCALES) : nullptr;+if (scalesPtr && scalesPtr->getShape().getRank() == 3) {auto scalesDims = scalesPtr->getShape().getStaticDims();auto groupsNum = needTranspose ? scalesDims[1] : scalesDims[0];minGroupSize = ic / groupsNum;}+if (zpPtr && zpPtr->getShape().getRank() == 3) {auto zpDims = zpPtr->getShape().getStaticDims();int groupsNum = needTranspose ? zpDims[1] : zpDims[0];@@ -196,11 +204,6 @@ bool DnnlFCPrimitive::useDynamicQuantizationImpl(size_t dqGroupSize,return true;}-template <typename T>-static std::vector<T> normalizeDimsTo2D(const std::vector<T>& dims) {- return {std::accumulate(dims.begin(), dims.end() - 1, (T)1, std::multiplies<T>()), dims[dims.size() - 1]};-}-static DnnlPrimitiveAttrs createPrimitiveAttrs(const FCAttrs& attrs,const PostOps& postOps,const MemoryArgs& memory,@@ -211,7 +214,7 @@ static DnnlPrimitiveAttrs createPrimitiveAttrs(const FCAttrs& attrs,const auto& dstDesc = memory.at(ARG_DST)->getDescPtr();const auto& originalDims = dstDesc->getShape().getMinDims();- const auto& dims = normalizeDimsTo2D(originalDims);+ const auto& dims = reshapeDownToRank<2>(originalDims);auto isINT8 =one_of(srcDesc->getPrecision(), ov::element::u8, ov::element::i8) && weiDesc->getPrecision() == ov::element::i8;@@ -223,21 +226,22 @@ static DnnlPrimitiveAttrs createPrimitiveAttrs(const FCAttrs& attrs,dims.size() - 1,isINT8,1 << 0,- attrs.dequantizationScales,- !memory.at(ARG_BIAS)->getDesc().empty(),+ memory,outputDataType);- if (attrs.decompressionMultiplyPtr) {- auto dstPrc = attrs.decompressionMultiplyPtr->getPrecision();+ if (memory.count(ARG_WEI | ARG_ATTR_SCALES)) {+ auto dstPrc = memory.at(ARG_WEI | ARG_ATTR_SCALES)->getPrecision();if (dstPrc != f8e8m0 || useDynamicQuantization)dstPrc = ov::element::f32;- dnnlpoc.appendDecompressionScales(attrs.decompressionMultiplyPtr, !attrs.weightsNonTransposed, dstPrc);+ dnnlpoc.appendDecompressionScales(memory.at(ARG_WEI | ARG_ATTR_SCALES), !attrs.weightsNonTransposed, dstPrc);}- if (attrs.decompressionSubtractPtr) {++ if (memory.count(ARG_WEI | ARG_ATTR_ZERO_POINTS)) {auto dstPrc = useDynamicQuantization ? ov::element::u8 : ov::element::f32;- dnnlpoc.appendDecompressionZeroPoints(attrs.decompressionSubtractPtr, !attrs.weightsNonTransposed, dstPrc);+ dnnlpoc.appendDecompressionZeroPoints(memory.at(ARG_WEI | ARG_ATTR_ZERO_POINTS), !attrs.weightsNonTransposed, dstPrc);}+if (useDynamicQuantization) {auto wei_precision = weiDesc->getPrecision();bool is_symmetric_weights = (wei_precision == ov::element::i8) || (wei_precision == ov::element::i4);@@ -261,7 +265,7 @@ static dnnl::memory::desc normalizeDescriptor(const dnnl::memory::desc& desc) {const auto& dims = desc.get_dims();if (dims.size() > 2)- return desc.reshape(normalizeDimsTo2D(dims));+ return desc.reshape(reshapeDownToRank<2>(dims));return desc;}@@ -276,12 +280,13 @@ static dnnl::inner_product_forward::primitive_desc createDescriptorInternal(consconst bool useWeightsDecompression) {const auto normalizedInputDesc = normalizeDescriptor(inputDesc);const auto normalizedOutputDesc = normalizeDescriptor(outputDesc);+ const auto normalizedWeightDesc = normalizeDescriptor(weightDesc);const auto indt = normalizedInputDesc.get_data_type();auto wdt = indt;if (useWeightsDecompression) {- wdt = weightDesc.get_data_type();+ wdt = normalizedWeightDesc.get_data_type();// dynamic quantization with symmetric quantized weights needs unsigned weightsuint64_t dynQuantGroupSize = 0;@@ -297,8 +302,8 @@ static dnnl::inner_product_forward::primitive_desc createDescriptorInternal(cons}const dnnl::memory::desc weightsDesc =- useSparseWeights ? dnnl::memory::desc().sparse_desc(weightDesc.get_dims(), wdt)- : dnnl::memory::desc(weightDesc.get_dims(), wdt, memory::format_tag::any);+ useSparseWeights ? dnnl::memory::desc().sparse_desc(normalizedWeightDesc.get_dims(), wdt)+ : dnnl::memory::desc(normalizedWeightDesc.get_dims(), wdt, memory::format_tag::any);return dnnl::inner_product_forward::primitive_desc(engine,dnnl::prop_kind::forward_inference,@@ -387,8 +392,7 @@ DnnlShapeAgnosticDataPtr DnnlFCPrimitive::createShapeAgnosticData(const FCAttrs&useWeightsDecompression && useDynamicQuantizationImpl(attrs.dynamicQuantizationGroupSize,srcDesc,weiDesc,- attrs.decompressionMultiplyPtr,- attrs.decompressionSubtractPtr,+ memory,!attrs.weightsNonTransposed);const auto postOpData = createPrimitiveAttrs(attrs, postOps, memory, context, useDynamicQuantization);diff --git a/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_fullyconnected_primitive.hpp b/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_fullyconnected_primitive.hppindex 5295b965506..21247f149ca 100644--- a/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_fullyconnected_primitive.hpp+++ b/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_fullyconnected_primitive.hpp@@ -75,13 +75,6 @@ public:const DnnlShapeAgnosticDataPtr& shapeAgnosticData);private:- static bool useDynamicQuantizationImpl(size_t dqGroupSize,- const MemoryDescPtr srcDesc,- const MemoryDescPtr weightsDesc,- MemoryCPtr scalesPtr,- MemoryCPtr zpPtr,- bool needTranspose);-dnnl::stream m_stream;dnnl::primitive_desc m_primDesc;impl_desc_type m_implType;diff --git a/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_matmul_primitive.cpp b/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_matmul_primitive.cppindex 1b8646c858e..40c365ee5f4 100644--- a/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_matmul_primitive.cpp+++ b/src/plugins/intel_cpu/src/nodes/executors/dnnl/dnnl_matmul_primitive.cpp@@ -27,6 +27,7 @@#include "nodes/executors/fullyconnected_config.hpp"#include "nodes/executors/matmul_config.hpp"#include "nodes/executors/memory_arguments.hpp"+#include "utils/cpu_utils.hpp"#include "utils/debug_capabilities.h"namespace ov {@@ -104,10 +105,10 @@ DnnlMemoryDescPtr DnnlMatMulPrimitive::makeTransposedWeightDescriptor(const Dnnlconst auto& weiDesc = srcDesc->getDnnlDesc();auto wDims = weiDesc.get_dims();auto wDataType = weiDesc.get_data_type();- std::swap(wDims[wDims.size() - 1], wDims[wDims.size() - 2]);+ dnnl::memory::dims wDims2D = reshapeDownToRank<2>(wDims);const auto format = weightsNonTransposed ? dnnl::memory::format_tag::ab : dnnl::memory::format_tag::ba;- const auto transposedWeiDesc = dnnl::memory::desc{wDims, wDataType, format};+ const auto transposedWeiDesc = dnnl::memory::desc{wDims2D, wDataType, format};return DnnlExtensionUtils::makeDescriptor(transposedWeiDesc);}@@ -134,8 +135,7 @@ static DnnlPrimitiveAttrs createPrimitiveAttrs(const MatMulAttrs& attrs,dims.size() - 1,isINT8,1 << 0,- attrs.dequantizationScales,- !memory.at(ARG_BIAS)->getDesc().empty(),+ memory,outputDataType);return dnnlpoc.compose();@@ -262,7 +262,7 @@ DnnlShapeAgnosticDataPtr DnnlMatMulPrimitive::createShapeAgnosticData(const FCAtconst auto& weiDesc = memory.at(ARG_WEI)->getDescPtr();const auto& biasDesc = memory.at(ARG_BIAS)->getDescPtr();auto dstDesc = memory.at(ARG_DST)->getDescPtr();- MatMulAttrs mmAttrs{false, false, attrs.dequantizationScales};+ MatMulAttrs mmAttrs{false, false};const auto postOpData = createPrimitiveAttrs(mmAttrs, postOps, memory, context, false);diff --git a/src/plugins/intel_cpu/src/nodes/executors/executor_config.hpp b/src/plugins/intel_cpu/src/nodes/executors/executor_config.hppindex 09b3b33cfe6..d08c4ad8127 100644--- a/src/plugins/intel_cpu/src/nodes/executors/executor_config.hpp+++ b/src/plugins/intel_cpu/src/nodes/executors/executor_config.hpp@@ -6,7 +6,6 @@#include "post_ops.hpp"#include "memory_arguments.hpp"-#include "printers.hpp"namespace ov {namespace intel_cpu {diff --git a/src/plugins/intel_cpu/src/nodes/executors/executor_factory.hpp b/src/plugins/intel_cpu/src/nodes/executors/executor_factory.hppindex f12795d5d1e..dd05cc58d43 100644--- a/src/plugins/intel_cpu/src/nodes/executors/executor_factory.hpp+++ b/src/plugins/intel_cpu/src/nodes/executors/executor_factory.hpp@@ -19,7 +19,6 @@namespace ov {namespace intel_cpu {-using namespace executor;template <typename Attrs>class ExecutorFactory {diff --git a/src/plugins/intel_cpu/src/nodes/executors/fullyconnected_config.hpp b/src/plugins/intel_cpu/src/nodes/executors/fullyconnected_config.hppindex ad6479597c6..1699a845a33 100644--- a/src/plugins/intel_cpu/src/nodes/executors/fullyconnected_config.hpp+++ b/src/plugins/intel_cpu/src/nodes/executors/fullyconnected_config.hpp@@ -19,13 +19,8 @@ struct FCAttrs {bool withBias = false;bool weightsNonTransposed = false;bool sparseWeights = false;- // @todo only memory descriptors should be a part of attributes- // actual memory should be passed into "execute" or "prepareMemory" calls- std::vector<float> dequantizationScales;- // @todo should be passed as an additional memory input?- MemoryCPtr decompressionSubtractPtr;- MemoryCPtr decompressionMultiplyPtr;uint64_t dynamicQuantizationGroupSize;+ov::intel_cpu::Config::ModelType modelType = ov::intel_cpu::Config::ModelType::Unknown;};diff --git a/src/plugins/intel_cpu/src/nodes/executors/fullyconnected_implementations.cpp b/src/plugins/intel_cpu/src/nodes/executors/fullyconnected_implementations.cppindex 4cf6992985e..10f472ddcd7 100644--- a/src/plugins/intel_cpu/src/nodes/executors/fullyconnected_implementations.cpp+++ b/src/plugins/intel_cpu/src/nodes/executors/fullyconnected_implementations.cpp@@ -441,8 +441,7 @@ const std::vector<ExecutorImplementation<FCAttrs>>& getImplementations() {const ExecutorContext::CPtr context,std::shared_ptr<DnnlShapeAgnosticData> shareAgnosticData) const {MatMulAttrs matMulAttrs{false,- false,- attrs.dequantizationScales};+ false};auto primitive =DefaultInstantiator<DnnlMatMulPrimitive, MatMulAttrs, DnnlShapeAgnosticData>{}(memory,diff --git a/src/plugins/intel_cpu/src/nodes/executors/matmul_config.hpp b/src/plugins/intel_cpu/src/nodes/executors/matmul_config.hppindex 9e484b24a29..e42bf3138bc 100644--- a/src/plugins/intel_cpu/src/nodes/executors/matmul_config.hpp+++ b/src/plugins/intel_cpu/src/nodes/executors/matmul_config.hpp@@ -12,7 +12,6 @@ namespace intel_cpu {struct MatMulAttrs {bool transposeA;bool transposeB;- std::vector<float> dequantizationScales;};using MatMulConfig = executor::Config<MatMulAttrs>;diff --git a/src/plugins/intel_cpu/src/nodes/executors/memory_arguments.hpp b/src/plugins/intel_cpu/src/nodes/executors/memory_arguments.hppindex c04ca39e845..7150226d27c 100644--- a/src/plugins/intel_cpu/src/nodes/executors/memory_arguments.hpp+++ b/src/plugins/intel_cpu/src/nodes/executors/memory_arguments.hpp@@ -14,7 +14,7 @@ namespace intel_cpu {using MemoryDescArgs = std::unordered_map<int, MemoryDescPtr>;using MemoryArgs = std::unordered_map<int, MemoryPtr>;-// @todo add more options+// basic inputs#define ARG_SRC_0 1#define ARG_SRC ARG_SRC_0#define ARG_SRC_1 2@@ -24,6 +24,12 @@ using MemoryArgs = std::unordered_map<int, MemoryPtr>;#define ARG_WEI_0 33#define ARG_WEI ARG_WEI_0#define ARG_BIAS 41+// legacy dequantization scale+#define ARG_DST_DEQ_SCALE 53+// scaling factors provided at execution time+#define ARG_ATTR_SCALES 4096+// zero points provided at execution time+#define ARG_ATTR_ZERO_POINTS 8192} // namespace intel_cpu} // namespace ovdiff --git a/src/plugins/intel_cpu/src/nodes/executors/mlas/mlas_gemm.cpp b/src/plugins/intel_cpu/src/nodes/executors/mlas/mlas_gemm.cppindex a03bfe26494..8fd945b773f 100644--- a/src/plugins/intel_cpu/src/nodes/executors/mlas/mlas_gemm.cpp+++ b/src/plugins/intel_cpu/src/nodes/executors/mlas/mlas_gemm.cpp@@ -23,6 +23,10 @@ using namespace executor;using namespace dnnl;using namespace ov::element;+static Dim batchDim(const VectorDims& dims) {+ return std::accumulate(dims.begin(), dims.end() - 1, 1, std::multiplies<Dim>());+}+static MemoryPtr prepareWeightMemory(const MemoryPtr weightsMemory,const ExecutorContext::CPtr context,const bool weightsTransposed) {@@ -31,14 +35,15 @@ static MemoryPtr prepareWeightMemory(const MemoryPtr weightsMemory,// Weights are transposed by MatMulConstTransposesExtraction// K is the IC of weight// the weight is reshaped to [-1, K] in ConvertMatMulToFC- const auto K = wgtDims[1];- const auto N = wgtDims[0];+ Dim K = wgtDims.back();+ Dim N = batchDim(wgtDims);auto packedBsize = mlas_sgemm_pack_get_size(N, K);auto create = [&]() {float* weightPtr = weightsMemory->getDataAs<float>();size_t ldb = weightsTransposed ? K : N;+MemoryPtr _ptr = std::make_shared<Memory>(context->getEngine(),intel_cpu::CpuBlockedMemoryDesc(i8, intel_cpu::Shape{packedBsize}));float* prepackedDst = _ptr->getDataAs<float>();@@ -66,21 +71,10 @@ bool MlasGemmExecutor::supports(const FCConfig& config) {DEBUG_LOG("MlasGemmExecutor: PostOps are not supported");return false;}- const auto& weiDesc = config.descs.at(ARG_WEI);- const auto& dstDesc = config.descs.at(ARG_DST);- // MLAS cannot support weight dims > 2, e.g. [1,64,9,9] * [10,64,9,9]- const auto& weightsDims = weiDesc->getShape().getStaticDims();- if (weightsDims.size() > 2) {- if (!std::all_of(weightsDims.begin() + 2, weightsDims.end(), [](const Dim dim) {- return dim == 1;- })) {- DEBUG_LOG("MlasGemmExecutor: weights dims > 2 are not supported");- return false;- }- }+ const auto& dstDesc = config.descs.at(ARG_DST);- if (config.attrs.withBias) {+ if (!config.descs.at(ARG_BIAS)->empty()) {const auto& biaDesc = config.descs.at(ARG_BIAS);const auto& biasDims = biaDesc->getShape().getStaticDims();const auto& outDims = dstDesc->getShape().getDims();@@ -108,24 +102,17 @@ MlasGemmExecutor::MlasGemmExecutor(const FCAttrs& attrs,const ExecutorContext::CPtr context): m_attrs(attrs),m_memoryArgs(memory),- packedWeights(prepareWeightMemory(memory.at(ARG_WEI), context, !attrs.weightsNonTransposed)) {}+ packedWeights(prepareWeightMemory(memory.at(ARG_WEI), context, !attrs.weightsNonTransposed)),+ N(batchDim(memory.at(ARG_WEI)->getStaticDims())),+ K(memory.at(ARG_WEI)->getStaticDims().back())+{}bool MlasGemmExecutor::update(const MemoryArgs& memory) {- const auto& weiDesc = memory.at(ARG_WEI)->getDescPtr();const auto& dstDesc = memory.at(ARG_DST)->getDescPtr();- const auto& wgtDims = weiDesc->getShape().getStaticDims();- // Weights are transposed by MatMulConstTransposesExtraction- // K is the IC of weight- // the weight is reshaped to [-1, K] in ConvertMatMulToFC- K = wgtDims[1];- N = wgtDims[0];const auto& outDims = dstDesc->getShape().getStaticDims();- if (outDims.size() > 2) {- M = std::accumulate(outDims.begin(), outDims.end() - 1, 1, std::multiplies<size_t>());- } else {- M = outDims[0];- }+ M = outDims.size() > 2 ? batchDim(outDims) : outDims[0];+return true;}diff --git a/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp b/src/plugins/intel_cpu/src/nodes/fullyconnected.cppindex 31ae4f26cc0..0f5c46e8bcd 100644--- a/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp+++ b/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp@@ -10,6 +10,7 @@#include "common/cpu_convert.h"#include "common/cpu_memcpy.h"+#include "cpu_types.h"#include "dnnl_extension_utils.h"#include "executors/memory_arguments.hpp"#include "graph_context.h"@@ -19,11 +20,16 @@#include "memory_desc/cpu_memory_desc_utils.h"#include "nodes/executors/executor.hpp"#include "nodes/executors/fullyconnected_config.hpp"+#include "openvino/core/type.hpp"#include "openvino/core/type/element_type.hpp"#include "openvino/runtime/threading/cpu_message.hpp"+#include "ov_ops/fully_connected.hpp"+#include "ov_ops/fully_connected_quantized.hpp"+#include "ov_ops/fully_connected_quantized_legacy.hpp"+#include "ov_ops/fully_connected_compressed.hpp"#include "post_ops.hpp"#include "shape_inference/custom/fullyconnected.hpp"-#include "transformations/cpu_opset/common/op/fully_connected.hpp"+#include "transformations/utils/utils.hpp"#include "utils/debug_capabilities.h"#include "utils/general_utils.h"@@ -39,25 +45,76 @@ namespace node {bool FullyConnected::isSupportedOperation(const std::shared_ptr<const ov::Node>& op,std::string& errorMessage) noexcept {try {- const auto fc = std::dynamic_pointer_cast<const FullyConnectedNode>(op);- if (!fc) {- errorMessage = "Only legacy FullyConnected operation is supported";+ if (!ov::is_type<const ov::op::internal::FullyConnected>(op) &&+ !ov::is_type<const ov::op::internal::FullyConnectedQuantizedLegacy>(op) &&+ !ov::is_type<const ov::op::internal::FullyConnectedCompressed>(op)) {return false;}- if (fc->get_input_size() == 3 &&- std::dynamic_pointer_cast<const ov::op::v0::Constant>(fc->get_input_node_shared_ptr(BIAS_ID)) == nullptr) {- errorMessage = "Only Constant operation on 'bias' input is supported";++ if (ov::is_type<const ov::op::internal::FullyConnected>(op)) {+ if (!ov::op::util::is_on_constant_path(op->input_value(BIAS))) {+ errorMessage = "Only Constant operation on 'bias' input is supported";+ return false;+ }+ }++ if (ov::is_type<const ov::op::internal::FullyConnectedCompressed>(op)) {+ if (!ov::op::util::is_on_constant_path(op->input_value(WEIGHT_SCALES)) ||+ !ov::op::util::is_on_constant_path(op->input_value(WEIGHT_ZERO_POINTS))) {+ errorMessage = "Only Constant operation on 'weight scales', and 'weight zero points' inputs is supported";+ return false;+ }+ }+ } catch (...) {+ return false;+ }++ return true;+}++// @todo replace 'inferencePrecision' check with 'fc->get_input_element_type(0) == ov::element::bf16'+// after bf16 pipeline is moved to ConvertPrecision+bool FullyConnected::isSupportedCompressedOperation(const std::shared_ptr<ov::Node>& op,+ size_t IC,+ size_t OC,+ size_t G,+ ov::element::Type inferencePrecision) noexcept {+#if defined(OPENVINO_ARCH_X86_64)+ try {+ std::string errorMessage;+ if (!isSupportedOperation(op, errorMessage))return false;++ if (!dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx2))+ return false;++ if (dnnl::impl::cpu::x64::mayiuse(dnnl::impl::cpu::x64::avx512_core_amx) &&+ inferencePrecision == ov::element::bf16) {+ // OneDNN AMX IP implementation has limited shapes support due to performance considerations. As a+ // current solution conditions below are copied from OneDNN to make sure correct IP impl will be+ // used since fallback one doesn't support weights decompression feature.+ size_t simdWidth = 16;+ size_t vnniFactor = 2;+ size_t maxSize = 512;+ auto amxRow = vnniFactor * simdWidth;++ if ((IC <= amxRow && OC <= amxRow) || (IC <= maxSize && OC <= maxSize && IC % amxRow != 0)) {+ return false;+ }}- const auto weightRank = fc->get_input_partial_shape(WEIGHTS_ID).size();- if (weightRank != 2) {- errorMessage = "Doesn't support 'weight' input with rank: " + std::to_string(weightRank);++ if (IC % G != 0 || IC / G < 4 || OC == 1) {return false;}++ return true;} catch (...) {return false;}return true;+#else+ return false;+#endif}void FullyConnected::initTensorParallelConfig(const GraphContext::CPtr context) {@@ -79,6 +136,31 @@ FullyConnected::FullyConnected(const std::shared_ptr<ov::Node>& op, const GraphCinitTensorParallelConfig(context);if (!isSupportedOperation(op, errorMessage))OPENVINO_THROW_NOT_IMPLEMENTED(errorMessage);++ m_atoi[ARG_SRC] = DATA;+ m_atoi[ARG_WEI] = WEIGHTS;+ m_atoi[ARG_BIAS] = BIAS;++ auto mapArgToInput = [&op](std::unordered_map<size_t, size_t>& argToInput, size_t argId, size_t inputId) {+ if (op->get_input_size() > inputId &&+ op->input(inputId).get_element_type() != ov::element::undefined) {+ argToInput[argId] = inputId;+ }+ };++ if (ov::is_type<const ov::op::internal::FullyConnectedCompressed>(op)) {+ mapArgToInput(m_atoi, ARG_WEI | ARG_ATTR_SCALES, WEIGHT_SCALES);+ mapArgToInput(m_atoi, ARG_WEI | ARG_ATTR_ZERO_POINTS, WEIGHT_ZERO_POINTS);+ algorithm = Algorithm::FullyConnectedCompressed;+ } else if (ov::is_type<const ov::op::internal::FullyConnectedQuantizedLegacy>(op)) {+ mapArgToInput(m_atoi, ARG_DST_DEQ_SCALE, 3);+ algorithm = Algorithm::FullyConnectedQuantizedLegacy;+ } else if (ov::is_type<const ov::op::internal::FullyConnectedQuantized>(op)) {+ algorithm = Algorithm::FullyConnectedQuantized;+ OPENVINO_THROW_NOT_IMPLEMENTED("FullyConnectedQuantized is not implemented yet");+ } else {+ algorithm = Algorithm::FullyConnectedCommon;+ }}bool FullyConnected::canBeExecutedInInt8() const {@@ -220,6 +302,7 @@ void FullyConnected::execTensorParallelSync() {}}}+void FullyConnected::execute(dnnl::stream strm) {initTensorParallelSync();@@ -366,31 +449,11 @@ static bool useSparseWeightsDecompression(const NodePtr& weightsInput,return sparseRate >= minSparseRate;}-void FullyConnected::needUpdateDQScaleForTensorParallel(std::vector<float>& dequantizationScales) {- if (tp_cfg.enable_tensor_parallel) {- auto split_parts = [](int len, int n) {- int average = len / n;- std::vector<int> parts(n, average);- parts.back() = len - average * (n - 1);- return parts;- };- auto DQScales = getDQScales();- auto split_lens = split_parts(DQScales.size(), tp_cfg.w_size);- auto split_offset = tp_cfg.w_rank * split_lens[0];- std::vector<float> newDQScales(split_lens[tp_cfg.w_rank]);- std::copy(DQScales.begin() + split_offset, DQScales.begin() + split_offset + split_lens[tp_cfg.w_rank], newDQScales.begin());- dequantizationScales = std::move(newDQScales);- }-}-void FullyConnected::initSupportedPrimitiveDescriptors() {- attrs.withBias = getOriginalInputsNumber() == 3;-- attrs.dequantizationScales = getDQScales();- needUpdateDQScaleForTensorParallel(attrs.dequantizationScales);+ attrs.withBias = getOriginalInputPrecisionAtPort(BIAS) != ov::element::undefined;- attrs.sparseWeights = useSparseWeightsDecompression(getParentEdgeAt(WEIGHTS_ID)->getParent(),- getOriginalInputPrecisionAtPort(DATA_ID),+ attrs.sparseWeights = useSparseWeightsDecompression(getParentEdgeAt(WEIGHTS)->getParent(),+ getOriginalInputPrecisionAtPort(DATA),context->getConfig().fcSparseWeiDecompressionRate);attrs.dynamicQuantizationGroupSize = context->getConfig().fcDynamicQuantizationGroupSize;attrs.modelType = context->getConfig().modelType;@@ -406,6 +469,10 @@ void FullyConnected::initSupportedPrimitiveDescriptors() {VecMemoryDescs srcDescs;const auto& creatorsMap = BlockedDescCreator::getCommonCreators();for (size_t i = 0; i < srcTypes.size(); i++) {+ if (srcTypes[i] == element::undefined) {+ srcDescs.push_back(MemoryDescUtils::makeEmptyDesc());+ continue;+ }const auto srcDesc = creatorsMap.at(LayoutType::ncsp)->createSharedDesc(srcTypes[i], getInputShapeAtPort(i));srcDescs.push_back(srcDesc);}@@ -417,23 +484,31 @@ void FullyConnected::initSupportedPrimitiveDescriptors() {}MemoryDescArgs descs{- {ARG_SRC, srcDescs[0]},- {ARG_WEI, srcDescs[1]},- {ARG_BIAS, attrs.withBias ? srcDescs[2] : MemoryDescUtils::makeEmptyDesc()},+ {ARG_SRC, srcDescs[DATA]},+ {ARG_WEI, srcDescs[WEIGHTS]},+ {ARG_BIAS, srcDescs[BIAS]},{ARG_DST, dstDescs[0]},};- needUpdateScaleForTensorParallel();- needUpdateZeroPointForTensorParallel();-auto executionContext = std::make_shared<ExecutorContext>(context, getImplPriority(), privateWeightCache);factory = std::make_shared<ExecutorFactory<FCAttrs>>(attrs, postOps, executionContext, descs);const auto nodeDescriptors = factory->getProperMemoryDescriptors(descs);NodeConfig nodeConfig;- nodeConfig.inConfs.emplace_back(nodeDescriptors.at(ARG_SRC));- nodeConfig.inConfs.emplace_back(nodeDescriptors.at(ARG_WEI));- if (attrs.withBias) nodeConfig.inConfs.emplace_back(nodeDescriptors.at(ARG_BIAS));+ nodeConfig.inConfs.resize(srcDescs.size());++ for (const auto& desc : nodeDescriptors) {+ if (m_atoi.count(desc.first)) {+ nodeConfig.inConfs[m_atoi[desc.first]] = desc.second;+ }+ }++ // add extra inputs bypassing proper memory descriptors+ // @todo pass all the input descriptors to getProperMemoryDescriptors and allow+ // to ignore extra input descriptors if necessery+ for (size_t i = 3; i < srcDescs.size(); i++) {+ nodeConfig.inConfs[i] = srcDescs[i];+ }const int inPlace = canBeInPlace() ? 0 : -1;nodeConfig.outConfs.emplace_back(nodeDescriptors.at(ARG_DST), BlockedMemoryDesc::FULL_MASK, inPlace);@@ -443,11 +518,11 @@ void FullyConnected::initSupportedPrimitiveDescriptors() {void FullyConnected::needSplitMemoryForTensorParallel() {if (tp_cfg.enable_tensor_parallel) {- auto src = getSrcMemoryAtPort(DATA_ID);- auto wgt = getSrcMemoryAtPort(WEIGHTS_ID);+ auto src = getSrcMemoryAtPort(DATA);+ auto wgt = getSrcMemoryAtPort(WEIGHTS);auto dst = getDstMemoryAtPort(0);// src- memory[ARG_SRC] = getSrcMemoryAtPort(DATA_ID);+ memory[ARG_SRC] = getSrcMemoryAtPort(DATA);// wgt// split N directiontp_cfg.cached_splited_weight = attrs.weightsNonTransposed ? split_vertical(context->getEngine(), std::move(wgt), 0, tp_cfg.w_rank, tp_cfg.w_size)@@ -455,7 +530,7 @@ void FullyConnected::needSplitMemoryForTensorParallel() {memory[ARG_WEI] = tp_cfg.cached_splited_weight;// biasif (attrs.withBias) {- auto bias = getSrcMemoryAtPort(BIAS_ID);+ auto bias = getSrcMemoryAtPort(BIAS);auto select_bias = split_horizontal(context->getEngine(), std::move(bias), 0, tp_cfg.w_rank, tp_cfg.w_size);tp_cfg.cached_splited_bias = std::move(select_bias);} else {@@ -465,6 +540,21 @@ void FullyConnected::needSplitMemoryForTensorParallel() {// dstmemory[ARG_DST] = getDstMemoryAtPort(0);tp_cfg.cached_dst = split_horizontal(context->getEngine(), std::move(dst), -1, tp_cfg.w_rank, tp_cfg.w_size, false);++ memory[ARG_DST | ARG_ATTR_SCALES] = split_horizontal(context->getEngine(), memory[ARG_DST | ARG_ATTR_SCALES], 0, tp_cfg.w_rank, tp_cfg.w_size);++ auto scale_mem = std::const_pointer_cast<IMemory>(memory[ARG_WEI | ARG_ATTR_SCALES]);+ memory[ARG_WEI | ARG_ATTR_SCALES] = attrs.weightsNonTransposed ? split_vertical(context->getEngine(), scale_mem, 0, tp_cfg.w_rank, tp_cfg.w_size)+ : split_horizontal(context->getEngine(), scale_mem, 0, tp_cfg.w_rank, tp_cfg.w_size);++ auto zeropoint_mem = std::const_pointer_cast<IMemory>(memory[ARG_WEI | ARG_ATTR_ZERO_POINTS]);+ auto element_num = zeropoint_mem->getSize() / zeropoint_mem->getPrecision().size();+ if (element_num == 1) {+ tp_cfg.cached_zeropoint = zeropoint_mem;+ } else {+ tp_cfg.cached_zeropoint = attrs.weightsNonTransposed ? split_vertical(context->getEngine(), zeropoint_mem, 0, tp_cfg.w_rank, tp_cfg.w_size)+ : split_horizontal(context->getEngine(), zeropoint_mem, 0, tp_cfg.w_rank, tp_cfg.w_size);+ }}}@@ -473,7 +563,7 @@ void FullyConnected::needUpdateTensorParalelConfig() {// 1. weight shape is dynamic// 2. last dim can be splited.if (tp_cfg.enable_tensor_parallel) {- auto& shape = getSrcMemoryAtPort(WEIGHTS_ID)->getShape();+ auto& shape = getSrcMemoryAtPort(WEIGHTS)->getShape();if (shape.isDynamic()) {tp_cfg.enable_tensor_parallel = false;} else if (shape.getDims()[0] < static_cast<size_t>(tp_cfg.w_size)) {@@ -481,12 +571,16 @@ void FullyConnected::needUpdateTensorParalelConfig() {}}}+void FullyConnected::createPrimitive() {needUpdateTensorParalelConfig();- memory[ARG_SRC] = getSrcMemoryAtPort(DATA_ID);- memory[ARG_WEI] = getSrcMemoryAtPort(WEIGHTS_ID);- memory[ARG_BIAS] = attrs.withBias ? getSrcMemoryAtPort(BIAS_ID) : MemoryDescUtils::makeEmptyMemory(context);+ for (const auto& entry : m_atoi) {+ const auto argumentId = entry.first;+ const auto inputId = entry.second;+ memory[argumentId] = getSrcMemoryAtPort(inputId);+ }+memory[ARG_DST] = getDstMemoryAtPort(0);needSplitMemoryForTensorParallel();@@ -513,49 +607,6 @@ ov::element::Type FullyConnected::getRuntimePrecision() const {return getMaxPrecision(srcTypes);}-void FullyConnected::needUpdateScaleForTensorParallel() {- if (tp_cfg.enable_tensor_parallel && tp_cfg.cached_scale) {- attrs.decompressionMultiplyPtr = tp_cfg.cached_scale;- }-}--void FullyConnected::needSplitScaleForTensorParallel(const MemoryCPtr& memory) {- if (tp_cfg.enable_tensor_parallel && !tp_cfg.cached_scale) {- auto scale_mem = std::const_pointer_cast<IMemory>(memory);- tp_cfg.cached_scale = attrs.weightsNonTransposed ? split_vertical(context->getEngine(), std::move(scale_mem), 0, tp_cfg.w_rank, tp_cfg.w_size)- : split_horizontal(context->getEngine(), std::move(scale_mem), 0, tp_cfg.w_rank, tp_cfg.w_size);- }-}--void FullyConnected::needUpdateZeroPointForTensorParallel() {- if (tp_cfg.enable_tensor_parallel && tp_cfg.cached_zeropoint) {- attrs.decompressionSubtractPtr = tp_cfg.cached_zeropoint;- }-}--void FullyConnected::needSplitZeroPointForTensorParallel(const MemoryCPtr& memory) {- if (tp_cfg.enable_tensor_parallel && !tp_cfg.cached_zeropoint) {- auto zeropoint_mem = std::const_pointer_cast<IMemory>(memory);- auto element_num = memory->getSize() / memory->getPrecision().size();- if (element_num == 1) {- tp_cfg.cached_zeropoint = std::move(zeropoint_mem);- } else {- tp_cfg.cached_zeropoint = attrs.weightsNonTransposed ? split_vertical(context->getEngine(), zeropoint_mem, 0, tp_cfg.w_rank, tp_cfg.w_size)- : split_horizontal(context->getEngine(), zeropoint_mem, 0, tp_cfg.w_rank, tp_cfg.w_size);- }- }-}--void FullyConnected::fuseDecompressionMultiply(const MemoryCPtr& memory) {- attrs.decompressionMultiplyPtr = memory;- needSplitScaleForTensorParallel(memory);-}--void FullyConnected::fuseDecompressionSubtract(const MemoryCPtr& memory) {- attrs.decompressionSubtractPtr = memory;- needSplitZeroPointForTensorParallel(memory);-}-} // namespace node} // namespace intel_cpu} // namespace ovdiff --git a/src/plugins/intel_cpu/src/nodes/fullyconnected.h b/src/plugins/intel_cpu/src/nodes/fullyconnected.hindex 8c17228e365..177edd3d426 100644--- a/src/plugins/intel_cpu/src/nodes/fullyconnected.h+++ b/src/plugins/intel_cpu/src/nodes/fullyconnected.h@@ -6,9 +6,11 @@#include <node.h>+#include <cstddef>#include <memory>#include <oneapi/dnnl/dnnl.hpp>#include <string>+#include <unordered_set>#include <vector>#include "cpu_memory.h"@@ -65,6 +67,15 @@ public:bool canFuse(const NodePtr& node) const override;static bool isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& errorMessage) noexcept;+ static bool isSupportedCompressedOperation(const std::shared_ptr<ov::Node>& op,+ size_t IC,+ size_t OC,+ size_t G,+ ov::element::Type inferencePrecision) noexcept;++ bool isExecutable() const override {+ return !isInputTensorAtPortEmpty(0);+ }void prepareParams() override;void executeDynamicImpl(dnnl::stream strm) override;@@ -80,9 +91,21 @@ protected:void toNumaNodeImpl(int numaID) override;private:- static const size_t DATA_ID = 0;- static const size_t WEIGHTS_ID = 1;- static const size_t BIAS_ID = 2;+ enum InputId : size_t {+ DATA = 0,+ WEIGHTS,+ BIAS,+ WEIGHT_SCALES,+ WEIGHT_ZERO_POINTS,+ INPUT_SCALES,+ INPUT_ZERO_POINTS,+ OUTPUT_SCALES,+ OUTPUT_ZERO_POINTS,+ };++ static bool isConstantInput(const std::shared_ptr<const ov::Node>& op, InputId port);++ std::unordered_map<size_t, size_t> m_atoi; // memory argument id to input idvoid fuseDecompressionConstant(const MemoryCPtr& memory, MemoryCPtr& decompressionValuesPtr);@@ -92,11 +115,6 @@ private:void initTensorParallelSync();void execTensorParallelSync();void needSplitMemoryForTensorParallel();- void needSplitScaleForTensorParallel(const MemoryCPtr& memory);- void needUpdateScaleForTensorParallel();- void needSplitZeroPointForTensorParallel(const MemoryCPtr& memory);- void needUpdateZeroPointForTensorParallel();- void needUpdateDQScaleForTensorParallel(std::vector<float>& dequantizationScales);FCAttrs attrs;PostOps postOps;diff --git a/src/plugins/intel_cpu/src/nodes/input.cpp b/src/plugins/intel_cpu/src/nodes/input.cppindex 1f650bd8c5d..4ccdc87ada2 100644--- a/src/plugins/intel_cpu/src/nodes/input.cpp+++ b/src/plugins/intel_cpu/src/nodes/input.cpp@@ -7,7 +7,10 @@#include "cpu/x64/jit_generator.hpp"#include "nodes/node_config.h"#include "openvino/core/parallel.hpp"+#include "openvino/core/shape.hpp"+#include "openvino/core/type/element_type.hpp"#include "shape_inference/shape_inference_pass_through.hpp"+#include "memory_desc/cpu_memory_desc_utils.h"using namespace dnnl;using namespace dnnl::impl::cpu::x64;@@ -228,9 +231,9 @@ Input::Input(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr conteop->get_type_name()," with name ",op->get_friendly_name());- constOp = ov::as_type_ptr<op::v0::Constant>(op);- if (constOp) {+ if (auto constOp = ov::as_type_ptr<op::v0::Constant>(op)) {constant = ConstantType::Const;+ m_constOp = constOp;cloneBlobIfRequired();} else {constant = ConstantType::StrictNoConst;@@ -238,8 +241,14 @@ Input::Input(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr conte}void Input::cloneBlobIfRequired() {- Shape shape(constOp->get_shape().empty() ? ov::Shape(1, 1) : constOp->get_shape());- const auto prec = constOp->get_element_type();+ const auto prec = m_constOp->get_element_type();++ if (prec == ov::element::undefined && shape_size(m_constOp->get_shape()) == 0) {+ memoryPtr = MemoryDescUtils::makeEmptyMemory(context);+ return;+ }++ Shape shape(m_constOp->get_shape().empty() ? ov::Shape(1, 1) : m_constOp->get_shape());const size_t size = shape.getElementsCount();CpuBlockedMemoryDesc memDesc(prec, shape);@@ -258,21 +267,21 @@ void Input::cloneBlobIfRequired() {// oneDNN always allocate 1byte for element type with bitWidth < 8 (u4,u1...)// but ngraph Constant uses actual bitWidth for data storage allocation// in that case we make a copy to avoid overflow- if (constOp->get_byte_size() >= memDesc.getCurrentMemSize()) {- if (constOp->get_element_type() == element::string) {- memory = std::make_shared<StringMemory>(getEngine(), memDesc, constOp->get_data_ptr<element::string>());+ if (m_constOp->get_byte_size() >= memDesc.getCurrentMemSize()) {+ if (m_constOp->get_element_type() == element::string) {+ memory = std::make_shared<StringMemory>(getEngine(), memDesc, m_constOp->get_data_ptr<element::string>());} else {- memory = std::make_shared<Memory>(getEngine(), memDesc, constOp->get_data_ptr());+ memory = std::make_shared<Memory>(getEngine(), memDesc, m_constOp->get_data_ptr());}} else {- if (constOp->get_element_type() == element::string) {+ if (m_constOp->get_element_type() == element::string) {memory = std::make_shared<StringMemory>(getEngine(), memDesc);- auto src = constOp->get_data_ptr<StringMemory::OvString>();+ auto src = m_constOp->get_data_ptr<StringMemory::OvString>();auto dst = memory->getDataAs<StringMemory::OvString>();std::copy(src, src + size, dst);} else {memory = std::make_shared<Memory>(getEngine(), memDesc);- memcpy(memory->getData(), constOp->get_data_ptr(), constOp->get_byte_size());+ memcpy(memory->getData(), m_constOp->get_data_ptr(), m_constOp->get_byte_size());}}@@ -287,22 +296,22 @@ void Input::cloneBlobIfRequired() {return ptr;};- auto isBlobAligned = [&] () {- bool blobAlignedOnSSE = true;+ auto isBlobAligned = [] (const std::shared_ptr<ov::op::v0::Constant>& constant) {#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)// Majority of arithmetic and data processing instructions in legacy SSE isa requires// the memory address in the operands must be aligned on 16-byte boundary. To ensure// safely reusing ngraph const blob memory, need to check address alignment.- const void *ptr = constOp->get_data_ptr();- blobAlignedOnSSE = mayiuse(cpu_isa_t::avx2) || ((reinterpret_cast<uintptr_t>(ptr) & 15) == 0);+ const void *ptr = constant->get_data_ptr();+ return mayiuse(cpu_isa_t::avx2) || ((reinterpret_cast<uintptr_t>(ptr) & 15) == 0);+#else+ return true;#endif- return blobAlignedOnSSE;};// The presence of subnormals is better to determined at IR read time.auto hasSubnormals = [&] () {if (prec == ov::element::f32) {- uint32_t const *u32data = constOp->get_data_ptr<uint32_t>();+ uint32_t const *u32data = m_constOp->get_data_ptr<uint32_t>();if (!size)return false;@@ -345,7 +354,7 @@ void Input::cloneBlobIfRequired() {auto blobKey = [&] () {char ptr[32];- snprintf(ptr, sizeof ptr, "%p", constOp->get_data_ptr());+ snprintf(ptr, sizeof ptr, "%p", m_constOp->get_data_ptr());return getName()+ "_" + std::to_string(size * prec.size())+ "_" + ptr;@@ -356,12 +365,13 @@ void Input::cloneBlobIfRequired() {prec != element::string &&// IRs already have all subnormals flushed to zero, but in// read_model scenario with directly loaded original model still can have subnormals- isBlobAligned() && (!needFlushDenormalsToZero || !hasSubnormals()) &&+ isBlobAligned(m_constOp) && (!needFlushDenormalsToZero || !hasSubnormals()) &&// Blob should be cloned in cache only if original weights are stored on other numa node.// This is possible only in multistream case on multisocket machine.// TODO: don't clone blob for multisocket + multistream case if current stream is run on the numa node where original weights are stored.(!weightCache || context->getNumNumaNodes() == 1 || context->getCPUStreamExecutor()->get_streams_num() == 1);- memoryPtr = clone_is_not_needed ? std::make_shared<Memory>(getEngine(), memDesc, constOp->get_data_ptr())++ memoryPtr = clone_is_not_needed ? std::make_shared<Memory>(getEngine(), memDesc, m_constOp->get_data_ptr()): std::const_pointer_cast<const IMemory>(weightCache ? *weightCache->findOrCreate(blobKey(), cloneBlob) : cloneBlob());}diff --git a/src/plugins/intel_cpu/src/nodes/input.h b/src/plugins/intel_cpu/src/nodes/input.hindex 4d7febb17ad..e659ea2359a 100644--- a/src/plugins/intel_cpu/src/nodes/input.h+++ b/src/plugins/intel_cpu/src/nodes/input.h@@ -75,7 +75,7 @@ private:void initSupportedPdFromMemDesc();private:- std::shared_ptr<ov::op::v0::Constant> constOp;+ std::shared_ptr<ov::op::v0::Constant> m_constOp;MemoryCPtr memoryPtr;bool isMeanImage = false;MemoryDescPtr extMemDesc = nullptr;diff --git a/src/plugins/intel_cpu/src/nodes/reference.cpp b/src/plugins/intel_cpu/src/nodes/reference.cppindex 5dc7c8818dd..b84836c869d 100644--- a/src/plugins/intel_cpu/src/nodes/reference.cpp+++ b/src/plugins/intel_cpu/src/nodes/reference.cpp@@ -29,7 +29,7 @@ Reference::Reference(const std::shared_ptr<ov::Node>& op,: Node(op, context, ReferenceShapeInferFactory(op)), ovCoreNode(op), additionalErrorMessage(errorMessage) {if (!op->has_evaluate()) {OPENVINO_THROW_NOT_IMPLEMENTED(- "Cannot fallback on ngraph reference implementation (Ngraph::Node::evaluate() is not implemented)");+ "Cannot fallback on ngraph reference implementation. Ngraph::Node::evaluate() is not implemented for op: ", *op);}setType(Type::Reference);diff --git a/src/plugins/intel_cpu/src/shape_inference/custom/fullyconnected.cpp b/src/plugins/intel_cpu/src/shape_inference/custom/fullyconnected.cppindex 5aef73df194..048b413b61a 100644--- a/src/plugins/intel_cpu/src/shape_inference/custom/fullyconnected.cpp+++ b/src/plugins/intel_cpu/src/shape_inference/custom/fullyconnected.cpp@@ -15,7 +15,7 @@ Result FCShapeInfer::infer(const VectorDims& activationShape = input_shapes[0].get();const VectorDims& weightShape = input_shapes[1].get();size_t activationRank = activationShape.size();- size_t channelRank = weightShape.size() - 1;+ size_t channelRank = 1;// activation weight output_shape// NCHW CoCHW NCo@@ -23,7 +23,7 @@ Result FCShapeInfer::infer(// NC CoC NCoVectorDims outputShape(out_rank, 1);// set Co- outputShape.back() = weightShape[0];+ outputShape.back() = std::accumulate(weightShape.begin(), weightShape.end() - 1, 1, std::multiplies<Dim>());// set batch dimssize_t batchRank = activationRank - channelRank;size_t startIdx = out_rank - batchRank - 1;diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/fully_connected.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/fully_connected.cppdeleted file mode 100644index a6d97b6a84b..00000000000--- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/fully_connected.cpp+++ /dev/null@@ -1,79 +0,0 @@-// Copyright (C) 2018-2024 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#include "fully_connected.hpp"-#include "transformations/itt.hpp"--ov::intel_cpu::FullyConnectedNode::FullyConnectedNode(const ov::Output<Node>& A,- const ov::Output<Node>& B,- const ov::Rank& output_rank,- const ov::element::Type output_type)- : Op({A, B}), m_output_rank(output_rank), m_output_type(output_type) {- validate_and_infer_types();-}--std::shared_ptr<ov::Node> ov::intel_cpu::FullyConnectedNode::clone_with_new_inputs(const ov::OutputVector& new_args) const {- INTERNAL_OP_SCOPE(FullyConnectedNode_clone_with_new_inputs);- check_new_args_count(this, new_args);-- return std::make_shared<ov::intel_cpu::FullyConnectedNode>(new_args.at(0), new_args.at(1), m_output_rank, m_output_type);-}--void ov::intel_cpu::FullyConnectedNode::validate_and_infer_types() {- INTERNAL_OP_SCOPE(FullyConnectedNode_validate_and_infer_types);- const auto input_size = get_input_size();- NODE_VALIDATION_CHECK(this,- input_size == 2,- "Number of inputs is incorrect. Current value is: ",- input_size,- ", expected: 2.");-- // Weights shape: [O, I1, ..., Im];- // O - output channels dimensions, Ik - input channels dimensions- const auto weights_pshape = get_input_partial_shape(1);- NODE_VALIDATION_CHECK(this,- weights_pshape.is_static(),- "Weights pshape must be static");- const auto weights_shape = weights_pshape.to_shape();-- NODE_VALIDATION_CHECK(this,- weights_pshape.size() > 0,- "Weights rank must be greater than 0");-- const auto o_channels = weights_pshape[0];-- // Activations shape: [B1, ..., Bn, I1, ..., Im];- // Bi - batch dimensions, Ik - input channels dimensions- const auto activations_pshape = get_input_partial_shape(0);-- // Result shape: [B1, ..., Bn, O]- ov::PartialShape output_pshape;- if (activations_pshape.rank().is_static()) {- size_t output_channels_dimensions_count = weights_shape.size() - 1;- for (size_t i = 0; i < activations_pshape.size() - output_channels_dimensions_count; ++i) {- output_pshape.push_back(activations_pshape[i]);- }- output_pshape.push_back(o_channels);-- NODE_VALIDATION_CHECK(this,- m_output_rank.is_static(),- "Output rank must be static if activations rank is static.");-- while (output_pshape.rank().get_length() < m_output_rank.get_length()) {- output_pshape.insert(output_pshape.begin(), 1);- }- } else {- output_pshape = ov::PartialShape::dynamic();- }-- auto output_type = m_output_type == ov::element::undefined ? get_input_element_type(0) : m_output_type;- set_output_type(0, output_type, output_pshape);-}--bool ov::intel_cpu::FullyConnectedNode::visit_attributes(ov::AttributeVisitor &visitor) {- INTERNAL_OP_SCOPE(FullyConnectedNode_visit_attributes);- visitor.on_attribute("out-rank", m_output_rank);- visitor.on_attribute("out-type", m_output_type);- return true;-}diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/fully_connected.hpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/fully_connected.hppdeleted file mode 100644index d992b76cf0b..00000000000--- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/fully_connected.hpp+++ /dev/null@@ -1,39 +0,0 @@-// Copyright (C) 2018-2024 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#pragma once--#include "openvino/core/node.hpp"-#include "openvino/op/op.hpp"--namespace ov {-namespace intel_cpu {--class FullyConnectedNode : public ov::op::Op {-public:- OPENVINO_OP("FullyConnected", "cpu_plugin_opset");-- FullyConnectedNode() = default;-- FullyConnectedNode(const ov::Output<Node> &A,- const ov::Output<Node> &B,- const ov::Rank& output_rank,- const ov::element::Type output_type = ov::element::undefined);-- bool visit_attributes(ov::AttributeVisitor &visitor) override;-- void validate_and_infer_types() override;-- std::shared_ptr<Node> clone_with_new_inputs(const ov::OutputVector& new_args) const override;-- ov::Rank get_output_rank() const { return m_output_rank; }- ov::element::Type get_output_type() const { return m_output_type; }--private:- ov::Rank m_output_rank;- ov::element::Type m_output_type;-};--} // namespace intel_cpu-} // namespace ovdiff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/convert_matmul_to_fc.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/convert_matmul_to_fc.cppindex f2861843a81..da25e9aac30 100644--- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/convert_matmul_to_fc.cpp+++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/convert_matmul_to_fc.cpp@@ -2,12 +2,12 @@// SPDX-License-Identifier: Apache-2.0//-#include "transformations/cpu_opset/common/op/fully_connected.hpp"+#include "openvino/core/type/element_type.hpp"+#include "ov_ops/fully_connected.hpp"#include "convert_matmul_to_fc.hpp"#include "openvino/op/matmul.hpp"#include "openvino/op/convert.hpp"#include "openvino/op/transpose.hpp"-#include "openvino/op/reshape.hpp"#include "openvino/core/rt_info.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"@@ -135,22 +135,6 @@ ov::intel_cpu::ConvertMatMulToFC::ConvertMatMulToFC() {OPENVINO_THROW("MatMul " + matmul->get_friendly_name() + " shapes are inconsistent.");}- // Transferring from MatMul representation: [B, I, K] * [B, K, O] = [B, I, O]- // to FullyConnected representation: [I, K] * [K, O] = [I, O]-- if (rank_b != 2) {- ov::Dimension K = *(shape_b_aligned.rbegin() + 1);- OPENVINO_ASSERT(K.is_static());- auto k_len = K.get_length();- auto reshape_shape_values = matmul->get_transpose_b() ? std::vector<int64_t>{-1, k_len} : std::vector<int64_t>{k_len, -1};- auto reshape_shape = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{ 2 }, reshape_shape_values);- fc_input_b = ov::op::util::make_try_fold<ov::op::v1::Reshape>(fc_input_b, reshape_shape, false);- if (!std::dynamic_pointer_cast<ov::op::v0::Constant>(fc_input_b.get_node_shared_ptr())) {- new_ops.push_back(reshape_shape);- }- new_ops.push_back(fc_input_b.get_node_shared_ptr());- }-// Weights normalizationif (!matmul->get_transpose_b()) {fc_input_b = create_transpose(fc_input_b, matmul->get_friendly_name() + "/transpose_b");@@ -169,10 +153,14 @@ ov::intel_cpu::ConvertMatMulToFC::ConvertMatMulToFC() {fc_input_b = convert;}- // Create FullyConnected- auto output_rank = matmul->get_output_partial_shape(0).rank();- auto fc = std::make_shared<ov::intel_cpu::FullyConnectedNode>(fc_input_a, fc_input_b, output_rank,- matmul->get_output_element_type(0));+ auto bias = std::make_shared<ov::op::v0::Constant>(element::undefined, Shape{0});+ new_ops.push_back(bias);++ auto fc = std::make_shared<ov::op::internal::FullyConnected>(fc_input_a,+ fc_input_b,+ bias,+ matmul->get_output_element_type(0));+fc->set_friendly_name(matmul->get_friendly_name());///todo: CVS-130863 Remove after fp16_compression is copyableif (ov::fp16_compression_is_disabled(matmul))diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/convert_matmul_to_fc.hpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/convert_matmul_to_fc.hppindex 69991802101..7d75fcc1917 100644--- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/convert_matmul_to_fc.hpp+++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/convert_matmul_to_fc.hpp@@ -4,7 +4,7 @@#pragma once-#include "openvino/pass/graph_rewrite.hpp"+#include "openvino/pass/matcher_pass.hpp"namespace ov {namespace intel_cpu {diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/convert_to_power_static.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/convert_to_power_static.cppindex 8079286d1e3..03d9a294bbc 100644--- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/convert_to_power_static.cpp+++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/convert_to_power_static.cpp@@ -12,7 +12,7 @@#include "openvino/pass/pattern/op/or.hpp"#include "transformations/rt_info/dequantization_node.hpp"#include "transformations/cpu_opset/common/op/power_static.hpp"-#include "transformations/cpu_opset/common/op/fully_connected.hpp"+#include "ov_ops/fully_connected.hpp"#include "utils/general_utils.h"#include "itt.hpp"@@ -47,16 +47,16 @@ bool isConvertableToPowerStatic(const std::shared_ptr<BaseOp> &node) {return ov::shape_size(const_shape) == 1 &&input_rank.get_length() >= static_cast<int64_t>(const_shape.size()) &&!ov::intel_cpu::one_of(node->get_input_node_shared_ptr(nonConstPort)->get_type_info(),- ov::opset1::NormalizeL2::get_type_info_static(),- ov::opset4::Interpolate::get_type_info_static(),- ov::opset1::Convolution::get_type_info_static(),- ov::opset1::GroupConvolution::get_type_info_static(),- ov::opset1::ConvolutionBackpropData::get_type_info_static(),- ov::opset1::GroupConvolutionBackpropData::get_type_info_static(),- ov::opset1::MatMul::get_type_info_static(),- ov::intel_cpu::FullyConnectedNode::get_type_info_static(),- ov::op::v0::MVN::get_type_info_static(),- ov::opset6::MVN::get_type_info_static());+ ov::opset1::NormalizeL2::get_type_info_static(),+ ov::opset4::Interpolate::get_type_info_static(),+ ov::opset1::Convolution::get_type_info_static(),+ ov::opset1::GroupConvolution::get_type_info_static(),+ ov::opset1::ConvolutionBackpropData::get_type_info_static(),+ ov::opset1::GroupConvolutionBackpropData::get_type_info_static(),+ ov::opset1::MatMul::get_type_info_static(),+ ov::op::internal::FullyConnected::get_type_info_static(),+ ov::op::v0::MVN::get_type_info_static(),+ ov::opset6::MVN::get_type_info_static());}template <>diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/fc_bias_fusion.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/fc_bias_fusion.cppnew file mode 100644index 00000000000..d92d2d3627b--- /dev/null+++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/fc_bias_fusion.cpp@@ -0,0 +1,79 @@+// Copyright (C) 2018-2023 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "fc_bias_fusion.hpp"++#include <cstdint>+#include <memory>++#include "itt.hpp"+#include "openvino/core/rt_info.hpp"+#include "openvino/op/add.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/reshape.hpp"+#include "openvino/pass/pattern/op/wrap_type.hpp"+#include "ov_ops/fully_connected.hpp"+#include "transformations/utils/utils.hpp"++ov::intel_cpu::FullyConnectedBiasFusion::FullyConnectedBiasFusion() {+ MATCHER_SCOPE(FullyConnectedBiasFusion);++ auto input = ov::pass::pattern::any_input(ov::pass::pattern::has_static_rank());+ auto weights = ov::pass::pattern::any_input(ov::pass::pattern::has_static_shape());+ auto bias = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();+ auto m_fc = ov::pass::pattern::wrap_type<ov::op::internal::FullyConnected>({input, weights, bias},+ ov::pass::pattern::consumers_count(1));+ auto m_bias = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();+ auto m_add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({m_fc, m_bias});++ ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ auto& pattern_to_output = m.get_pattern_value_map();++ auto add = pattern_to_output[m_add].get_node_shared_ptr();+ auto bias = pattern_to_output[m_bias].get_node_shared_ptr();++ auto fc = pattern_to_output[m_fc].get_node_shared_ptr();++ if (transformation_callback(fc)) {+ return false;+ }++ ov::Shape bias_shape(bias->get_shape());+ const ov::PartialShape& output_shape = fc->get_output_partial_shape(0);+ size_t bias_size = ov::shape_size(bias_shape);+ auto rank = output_shape.size();+ if (rank == 0 || output_shape[rank - 1].is_dynamic()) {+ return false;+ }++ if (bias_shape.empty() || static_cast<int64_t>(bias_shape.back()) != output_shape[rank - 1].get_length() ||+ bias_shape.back() != bias_size) {+ return false;+ }++ ov::NodeVector new_ops;++ std::shared_ptr<ov::Node> final_bias = bias;+ if (bias_shape.size() >= 2) {+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1});+ final_bias = ov::op::util::make_try_fold<ov::op::v1::Reshape>(final_bias, reshape_const, true);+ new_ops.push_back(final_bias);+ }++ std::shared_ptr<ov::Node> fc_with_bias;++ auto fc_node = ov::as_type_ptr<ov::op::internal::FullyConnected>(fc);+ fc_with_bias = fc_node->clone_with_new_inputs({fc_node->input_value(0), fc_node->input_value(1), final_bias});++ new_ops.push_back(fc_with_bias);++ fc_with_bias->set_friendly_name(add->get_friendly_name());+ ov::copy_runtime_info({fc, add}, new_ops);+ ov::replace_node(add, fc_with_bias);+ return true;+ };++ auto m = std::make_shared<ov::pass::pattern::Matcher>(m_add, matcher_name);+ this->register_matcher(m, callback);+}diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/fc_bias_fusion.hpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/fc_bias_fusion.hppnew file mode 100644index 00000000000..b21cf80ad32--- /dev/null+++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/fc_bias_fusion.hpp@@ -0,0 +1,19 @@+// Copyright (C) 2018-2023 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/pass/matcher_pass.hpp"++namespace ov {+namespace intel_cpu {++class FullyConnectedBiasFusion : public ov::pass::MatcherPass {+public:+ OPENVINO_RTTI("FullyConnectedBiasFusion", "0");+ FullyConnectedBiasFusion();+};++} // namespace intel_cpu+} // namespace ovdiff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/move_fc_reshape_to_weights.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/move_fc_reshape_to_weights.cppindex e681cd48ce8..18a54dc45e1 100644--- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/move_fc_reshape_to_weights.cpp+++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/move_fc_reshape_to_weights.cpp@@ -2,7 +2,7 @@// SPDX-License-Identifier: Apache-2.0//-#include "transformations/cpu_opset/common/op/fully_connected.hpp"+#include "ov_ops/fully_connected.hpp"#include "move_fc_reshape_to_weights.hpp"#include <transformations/utils/utils.hpp>#include <openvino/pass/pattern/op/wrap_type.hpp>@@ -48,7 +48,8 @@ ov::intel_cpu::MoveFCReshapeToWeights::MoveFCReshapeToWeights() {auto weights_input_m = std::make_shared<ov::pass::pattern::op::Or>(ov::OutputVector{reshape_m, transpose_m});auto data_m = any_input();- auto fully_connected_m = wrap_type<ov::intel_cpu::FullyConnectedNode>({data_m, weights_input_m});+ auto bias_m = any_input();+ auto fully_connected_m = wrap_type<ov::op::internal::FullyConnected>({data_m, weights_input_m, bias_m});ov::matcher_pass_callback callback = [&](ov::pass::pattern::Matcher& m) {const auto fully_connected = m.get_match_root();diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/split_fc.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/split_fc.cppdeleted file mode 100644index 27207b3e051..00000000000--- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/split_fc.cpp+++ /dev/null@@ -1,207 +0,0 @@-// Copyright (C) 2018-2024 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#include "openvino/core/rt_info.hpp"-#include "openvino/pass/pattern/op/wrap_type.hpp"-#include "openvino/pass/constant_folding.hpp"-#include <transformations/utils/utils.hpp>-#include "openvino/op/concat.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/op/transpose.hpp"-#include "openvino/op/variadic_split.hpp"-#include "transformations/cpu_opset/common/op/fully_connected.hpp"--#include "split_fc.hpp"--#include "itt.hpp"--ov::intel_cpu::SplitFC::SplitFC(int sub_stream_num) {- MATCHER_SCOPE(SplitFC);- auto fc_m = ov::pass::pattern::wrap_type<ov::intel_cpu::FullyConnectedNode>();-- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {- const auto& pattern_map = m.get_pattern_value_map();-- const auto& fc_node = pattern_map.at(fc_m).get_node_shared_ptr();- auto& rt_info = fc_node->get_rt_info();- if (rt_info.count("parallelDomain")) {- return false;- }-- const auto src_item = fc_node->get_input_node_shared_ptr(0);- const auto fc_weight_node = fc_node->get_input_node_shared_ptr(1);-- // split happens on the first dimension.- constexpr size_t split_dim = 0;- auto split_dim_node = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, split_dim);-- // needn't to split fc when the dim is 0.- const auto& wgt_shape = fc_weight_node->get_shape();- // weight shape size 660000 is a trade-off value, which is summarized and verified by LLMs.- if (wgt_shape[split_dim] <= 1 || ov::shape_size(wgt_shape) < 6600000) {- return false;- }-- // parts will be splited according the sub stream num.- int split_num = sub_stream_num + 1;-- auto split_parts = [](int len, int n) {- int average = len / n;- std::vector<int> parts(n, average);- parts.back() = len - average * (n - 1);- return parts;- };-- // TODO: support transpose- if (ov::is_type<ov::op::v1::Transpose>(fc_weight_node)) {- return false;- }-- // 1. If the model is INT4 format, split the INT4 pattern for the FuseFCAndWeightsDecompression.- // 2. If the model is NOT INT4 format, split the weight.- std::vector<ov::Output<ov::Node>> wgt_node_vec(split_num);- if (ov::is_type<ov::op::v1::Multiply>(fc_weight_node) || ov::is_type<ov::op::v1::Reshape>(fc_weight_node)) {- // INT4 model should consider two patterns, including with Reshape Node and without Reshape Node.- const auto reshape_node = ov::as_type_ptr<ov::op::v1::Reshape>(fc_weight_node);- const auto multiply_node = reshape_node ? reshape_node->get_input_node_shared_ptr(0) : fc_weight_node;- if (!ov::is_type<ov::op::v1::Multiply>(multiply_node)) {- return false;- }- auto multiply_pattern = multiply_node->get_input_node_shared_ptr(1);- if (!ov::is_type<ov::op::v0::Constant>(multiply_pattern)) {- return false;- }- auto subtract_node = multiply_node->get_input_node_shared_ptr(0);- if (!ov::is_type<ov::op::v1::Subtract>(subtract_node)) {- return false;- }- auto convert_node1 = subtract_node->get_input_node_shared_ptr(1);- if (!ov::is_type<ov::op::v0::Convert>(convert_node1)) {- return false;- }- auto convert_node1_const = ov::as_type_ptr<ov::op::v0::Constant>(convert_node1->get_input_node_shared_ptr(0));- if (!convert_node1_const) {- return false;- }- auto convert_node0 = subtract_node->get_input_node_shared_ptr(0);- if (!ov::is_type<ov::op::v0::Convert>(convert_node0)) {- return false;- }- auto wgt_item = convert_node0->get_input_node_shared_ptr(0);- auto cvt_prec = convert_node0->get_element_type();-- auto split_dim_range = wgt_item->get_shape()[split_dim];- const auto& convert_node1_shape = convert_node1->get_shape();- bool need_to_split_convert = ov::shape_size(convert_node1_shape) > 1 &&- split_dim < convert_node1_shape.size() &&- convert_node1_shape[split_dim] == split_dim_range;-- // We should use VariadicSplit to split the input for FC.- std::vector<std::vector<int32_t>> split_reshape_pattern_vec(split_num);- auto fc_dim_vec = split_parts(split_dim_range, split_num);- auto split_length = ov::op::v0::Constant::create<int32_t>(ov::element::i32, ov::Shape{static_cast<size_t>(split_num)}, fc_dim_vec);-- auto split_constants = [&](const std::shared_ptr<ov::Node>& constant) {- static const std::set<ov::element::Type> unsupported_by_split_element_types{ov::element::u4, ov::element::i4, ov::element::nf4};- const auto& constant_precision = constant->get_output_element_type(0);- if (unsupported_by_split_element_types.count(constant_precision) == 0) {- auto split = std::make_shared<ov::op::v1::VariadicSplit>(constant, split_dim_node, split_length);- return split->outputs();- }-- auto convert = std::make_shared<ov::op::v0::Convert>(constant, ov::element::i8);- auto split = std::make_shared<ov::op::v1::VariadicSplit>(convert, split_dim_node, split_length);- ov::OutputVector res(split->get_output_size());- for (size_t i = 0; i < split->get_output_size(); ++i) {- res[i] = std::make_shared<ov::op::v0::Convert>(split->output(i), constant_precision);- }- return res;- };-- auto split_wgts = split_constants(wgt_item);- auto split_muls = split_constants(multiply_pattern);- ov::OutputVector split_cvts;- if (need_to_split_convert) {- split_cvts = split_constants(convert_node1_const);- }-- if (reshape_node) {- auto reshape_pattern = reshape_node->get_input_node_shared_ptr(1);- auto reshape_const = ov::as_type_ptr<ov::op::v0::Constant>(reshape_pattern);- if (!reshape_const) {- return false;- }- const auto reshape_vec = reshape_const->cast_vector<int32_t>();- for (int i = 0; i < split_num; ++i) {- split_reshape_pattern_vec[i] = {fc_dim_vec[i], reshape_vec[1]};- }- }-- std::vector<ov::Output<ov::Node>> zp_const_vec(split_num);- for (int i = 0; i < split_num; ++i) {- zp_const_vec[i] = need_to_split_convert ? split_cvts[i] : convert_node1_const->clone_with_new_inputs({});- }-- for (int i = 0; i < split_num; ++i) {- auto sub_parent0 = std::make_shared<ov::op::v0::Convert>(split_wgts[i], cvt_prec);- auto sub_parent1 = std::make_shared<ov::op::v0::Convert>(zp_const_vec[i], cvt_prec);- ov::pass::disable_constant_folding(sub_parent0);- ov::pass::disable_constant_folding(sub_parent1);- auto sub_node = std::make_shared<ov::op::v1::Subtract>(sub_parent0, sub_parent1);-- auto mul_node = std::make_shared<ov::op::v1::Multiply>(sub_node, split_muls[i]);- if (reshape_node) {- auto reshape_pattern = ov::op::v0::Constant::create<int32_t>(ov::element::i32, ov::Shape{2}, split_reshape_pattern_vec[i]);- wgt_node_vec[i] = std::make_shared<ov::op::v1::Reshape>(mul_node, reshape_pattern, reshape_node->get_special_zero());- } else {- wgt_node_vec[i] = mul_node;- }- }- } else {- // get input- auto wgt_item = fc_node->get_input_node_shared_ptr(1);-- // split weight- auto split_dim_range = wgt_item->get_shape()[split_dim];-- // We should use VariadicSplit to split input for FC.- auto fc_dim_vec = split_parts(split_dim_range, split_num);- auto split_length = ov::op::v0::Constant::create<int32_t>(ov::element::i32, ov::Shape{static_cast<size_t>(split_num)}, fc_dim_vec);- auto split_wgts = std::make_shared<ov::op::v1::VariadicSplit>(wgt_item,- split_dim_node,- split_length);-- wgt_node_vec = split_wgts->outputs();- }-- // create fc Nodes according to the splited weight or splited pattern.- std::vector<std::shared_ptr<Node>> fc_node_vec(split_num);- for (int i = 0; i < split_num; ++i) {- fc_node_vec[i] = fc_node->clone_with_new_inputs(ov::OutputVector{src_item, wgt_node_vec[i]});- fc_node_vec[i]->get_rt_info()["parallelDomain"] = fc_node->get_name();- }-- // concat all small fc for result.- ov::NodeVector concat_args(std::move(fc_node_vec));- // concat happens on the latest dimension.- constexpr size_t concat_dim = -1;- auto concat_node = std::make_shared<ov::op::v0::Concat>(concat_args, concat_dim);-- // check the shape after transformation.- const auto& out_shape = fc_node->get_output_partial_shape(0);- const auto& concat_shape = concat_node->get_output_partial_shape(0);- if (concat_shape != out_shape) {- return false;- }- ov::replace_node_update_name(fc_node, concat_node);- return true;- };-- auto m = std::make_shared<ov::pass::pattern::Matcher>(fc_m, matcher_name);- this->register_matcher(m, callback);-}diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/split_fc.hpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/split_fc.hppdeleted file mode 100644index f8434770b27..00000000000--- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/split_fc.hpp+++ /dev/null@@ -1,81 +0,0 @@-// Copyright (C) 2018-2024 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#pragma once--#include "openvino/pass/graph_rewrite.hpp"--namespace ov {-namespace intel_cpu {--/*- * Description:- * SplitFC detects FC CPU operation with and without compressed weights.- * And then splits the FC into several small FCs by output channel according to sub stream number.- * The goal is that the executor can dispatch the split FCs to different numa nodes in the system.- * As a result, the split FCs can be executed at the parallel level.- *- * Before:- *- * +-------+ +-------+- * | X | | W |- * | | | |- * | | | |- * +-------+ +-------+- * | |- * | |- * +---------------v---------------------------------v--------------+- * | |- * | FullyConnected |- * | |- * +------------------------------+---------------------------------+- * |- * | Output- * v- *- * After:- *- * +-------+ +-------+- * | X | | W |- * | | | |- * | | | |- * +---+---+ +---+---+- * | |- * | |- * | +-------v-------+- * | | |- * | | VariadicSplit |- * | | |- * | +--+---------+--+- * | | |- * | +------------------------+ |- * | | |- * +---------|------------------------+ |- * | | | |- * +----------v---------v---------+ +-----------v---------v--------+- * | | | |- * | FullyConnected | | FullyConnected |- * | | | |- * +--------------+---------------+ +--------------+---------------+- * | |- * | Output | Output- * | |- * +--------------v---------------------------------v---------------+- * | |- * | Concat |- * | |- * +-------------------------------+--------------------------------+- * |- * |- * v- */--class SplitFC: public ov::pass::MatcherPass {-public:- OPENVINO_RTTI("SplitFC", "0");- SplitFC(int sub_stream_num);-};--} // namespace intel_cpu-} // namespace ovdiff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/convert_to_cpu_specific_opset.hpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/convert_to_cpu_specific_opset.hppindex 20502f67d36..87fa1291bb7 100644--- a/src/plugins/intel_cpu/src/transformations/cpu_opset/convert_to_cpu_specific_opset.hpp+++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/convert_to_cpu_specific_opset.hpp@@ -2,36 +2,67 @@// SPDX-License-Identifier: Apache-2.0//+#include "openvino/core/type/element_type.hpp"#include "openvino/pass/constant_folding.hpp"-#include "openvino/op/fake_quantize.hpp"#include "openvino/pass/manager.hpp"#include "common/pass/align_matmul_input_ranks.hpp"-#include "transformations/common_optimizations/reshape_prelu.hpp"-#include "common/pass/convert_broadcast_to_tiles.hpp"+#include "transformations/common_optimizations/nop_elimination.hpp"#include "common/pass/convert_tile_to_seq_tiles.hpp"#include "common/pass/convert_matmul_to_fc.hpp"#include "common/pass/convert_to_power_static.hpp"#include "common/pass/convert_to_leaky_relu.hpp"#include "common/pass/convert_to_swish_cpu.hpp"#include "common/pass/move_fc_reshape_to_weights.hpp"-#include "common/pass/split_fc.hpp"+#include "common/pass/fc_bias_fusion.hpp"#include "transformations/convert_precision.hpp"-#include "transformations/utils/utils.hpp"+#include "transformations/op_conversions/convert_fc_to_compressed.hpp"+#include "transformations/op_conversions/convert_fc_to_quantized_legacy.hpp"#include "common/pass/rnn_sequences_optimization.hpp"#include "transformations/common_optimizations/reshape_sequence_fusion.hpp"#include "transformations/defs.hpp"+#include "config.h"+#include "nodes/fullyconnected.h"#include "itt.hpp"namespace ov {namespace intel_cpu {-inline void ConvertToCPUSpecificOpset(std::shared_ptr<ov::Model> &model) {+inline void ConvertToCPUSpecificOpset(std::shared_ptr<ov::Model> &model, const Config& config) {RUN_ON_FUNCTION_SCOPE(ConvertToCPUSpecificOpset);ov::pass::Manager manager("CPU:ConvertToCPUSpecificOpset");manager.set_per_pass_validation(false);+CPU_REGISTER_PASS_COMMON(manager, ConvertMatMulToFC);+ CPU_REGISTER_PASS_COMMON(manager, FullyConnectedBiasFusion);++ std::vector<ov::element::Type> supported_activation_types {+ // @todo enable for bf16 as well+ // after EnforceInferencePrecision is replaced with ConvertPrecision+ ov::element::f32,+ };++ std::vector<ov::element::Type> supported_compressed_weights_types {+ ov::element::u8,+ ov::element::i8,+ ov::element::u4,+ ov::element::i4,+ ov::element::nf4,+ ov::element::f4e2m1,+ };++ CPU_REGISTER_PASS_X64(+ manager,+ pass::ConvertFullyConnectedToFullyConnectedCompressed,+ supported_activation_types,+ supported_compressed_weights_types,+ [&config](const std::shared_ptr<ov::op::internal::FullyConnected>& fc, size_t IC, size_t OC, size_t G) {+ return ov::intel_cpu::node::FullyConnected::isSupportedCompressedOperation(+ fc, IC, OC, G, config.inferencePrecision);+ });++ CPU_REGISTER_PASS_X64(manager, pass::ConvertFCToFCQuantizedLegacy);CPU_REGISTER_PASS_X64(manager, MoveFCReshapeToWeights);CPU_REGISTER_PASS_X64(manager, ov::pass::Validate);CPU_REGISTER_PASS_COMMON(manager, AlignMatMulInputRanks);diff --git a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cppindex 27afb95a73a..f9fa372030e 100644--- a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp+++ b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp@@ -21,6 +21,7 @@// Common transformations#include "transformations/common_optimizations/mark_precision_sensitive_shapeof_subgraphs.hpp"#include "transformations/common_optimizations/add_fake_quantize_fusion.hpp"+#include "transformations/common_optimizations/reshape_prelu.hpp"#include "transformations/fp16_compression/convert_compression_only_to_legacy.hpp"#include "transformations/common_optimizations/convert_quantize_dequantize.hpp"#include "transformations/common_optimizations/lstm_cell_fusion.hpp"@@ -319,7 +320,7 @@ void Transformations::UpToLpt() {void Transformations::CpuSpecificOpSet(void) {CPU_DEBUG_CAP_TRANSFORMATION_SCOPE(this, Specific);- ConvertToCPUSpecificOpset(model);+ ConvertToCPUSpecificOpset(model, config);}void Transformations::PreLpt(const std::vector<ov::element::Type>& defaultPrecisions) {diff --git a/src/plugins/intel_cpu/src/transformations/utils.cpp b/src/plugins/intel_cpu/src/transformations/utils.cppindex 3aa74f9ed9a..63871868713 100644--- a/src/plugins/intel_cpu/src/transformations/utils.cpp+++ b/src/plugins/intel_cpu/src/transformations/utils.cpp@@ -4,7 +4,7 @@#include "utils.hpp"#include "openvino/opsets/opset1.hpp"-#include "cpu_opset/common/op/fully_connected.hpp"+#include "ov_ops/fully_connected.hpp"#include "transformations/rt_info/dequantization_node.hpp"#include "transformations/utils/utils.hpp"@@ -21,7 +21,7 @@ bool has_matmul_with_compressed_weights(const std::shared_ptr<const ov::Model>&};for (const auto& op : model->get_ops()) {- if (!ov::is_type<ov::op::v0::MatMul>(op) && !ov::is_type<FullyConnectedNode>(op))+ if (!ov::is_type<ov::op::v0::MatMul>(op) && !ov::is_type<ov::op::internal::FullyConnected>(op))continue;if (!op->get_input_element_type(0).is_real())diff --git a/src/plugins/intel_cpu/src/utils/cpu_utils.hpp b/src/plugins/intel_cpu/src/utils/cpu_utils.hppindex b6bd36205f9..8ae9aa67edf 100644--- a/src/plugins/intel_cpu/src/utils/cpu_utils.hpp+++ b/src/plugins/intel_cpu/src/utils/cpu_utils.hpp@@ -9,6 +9,7 @@#include <vector>#include "general_utils.h"+#include "openvino/core/except.hpp"#include "precision_support.h"namespace ov {@@ -156,5 +157,35 @@ inline std::vector<float> makeAlignedBuffer(size_t targetSize, const std::vector}return alignedBuffer;}++/**+* @brief Reshape a tensor down to a specific rank+*+* Examples:+* - reshapeToRank<2>({1, 2, 3, 4, 5}) == {1*2*3*4, 5} == {24, 5}+* - reshapeToRank<4>({1, 2, 3, 4, 5}) == {1*2, 3, 4, 5} == {2, 3, 4, 5}+*/+template <typename T>+std::vector<T> reshapeDownToRank(const std::vector<T>& dims, size_t rank) {+ OPENVINO_ASSERT(rank > 0, "Rank greater than zero is expected");++ if (dims.size() <= rank) {+ return dims;+ }++ const auto accEnd = dims.begin() + (dims.size() - rank + 1);+ const auto acc = std::accumulate(dims.begin(), accEnd, (T)1, std::multiplies<T>());++ std::vector<T> result{acc};+ result.insert(result.end(), accEnd, dims.end());++ return result;+}++template <size_t rank, typename T>+std::vector<T> reshapeDownToRank(const std::vector<T>& dims) {+ return reshapeDownToRank(dims, rank);+}+} // namespace intel_cpu} // namespace ovdiff --git a/src/plugins/intel_cpu/src/utils/debug_capabilities.cpp b/src/plugins/intel_cpu/src/utils/debug_capabilities.cppindex fcc983d8416..195d46c70e1 100644--- a/src/plugins/intel_cpu/src/utils/debug_capabilities.cpp+++ b/src/plugins/intel_cpu/src/utils/debug_capabilities.cpp@@ -2,6 +2,7 @@// Copyright (C) 2018-2024 Intel Corporation// SPDX-License-Identifier: Apache-2.0//+#include "openvino/core/type/element_type.hpp"#ifdef CPU_DEBUG_CAPS#include "cpu_memory.h"@@ -310,7 +311,7 @@ std::ostream & operator<<(std::ostream & os, const Node &c_node) {void * data = pmem->getData();auto shape = pmem->getDesc().getShape().getDims();- if (shape_size(shape) <= 8) {+ if (shape_size(shape) <= 8 && pmem->getDesc().getPrecision() != ov::element::undefined) {auto type = pmem->getDesc().getPrecision();auto tensor = ov::Tensor(type, shape, data);auto constop = std::make_shared<ov::op::v0::Constant>(tensor);@@ -663,7 +664,7 @@ std::ostream& operator<<(std::ostream& os, const IMemory& mem) {}return os;}-// @todo remove+void print_dnnl_memory(const dnnl::memory& memory, const size_t size, const int id, const char* message) {const size_t s = memory.get_desc().get_size() / sizeof(float);std::cout << message << " " << id << " size: " << s << ", values: ";diff --git a/src/plugins/intel_cpu/src/utils/debug_capabilities.h b/src/plugins/intel_cpu/src/utils/debug_capabilities.hindex 7a1158d259a..2646ba817dc 100644--- a/src/plugins/intel_cpu/src/utils/debug_capabilities.h+++ b/src/plugins/intel_cpu/src/utils/debug_capabilities.h@@ -3,6 +3,7 @@//#pragma once+#include "cpu_types.h"#include "openvino/util/env_util.hpp"#ifdef CPU_DEBUG_CAPS@@ -94,6 +95,12 @@ public:}};+template<typename T>+std::ostream & operator<<(std::ostream & os, const std::vector<T> vec) {+ for (const auto& element : vec)+ os << element << "x";+ return os;+}std::ostream & operator<<(std::ostream & os, const PortConfig& desc);std::ostream & operator<<(std::ostream & os, const NodeConfig& desc);std::ostream & operator<<(std::ostream & os, const NodeDesc& desc);diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/matmul.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/matmul.cppindex 6d827614f80..4afdd90427b 100644--- a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/matmul.cpp+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/arm/matmul.cpp@@ -23,7 +23,6 @@ static const std::vector<CPUSpecificParams>& filterSpecificParamsFC() {std::vector<fusingSpecificParams> fusingParamsSet2D_smoke {emptyFusingSpec,fusingBias,- fusingMultiplyPerChannel,fusingRelu,fusingTanh};@@ -62,7 +61,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_f16, MatMulLayerCPUTest, testParams2D_smokestd::vector<fusingSpecificParams> fusingParamsSet3D_smoke {emptyFusingSpec,fusingBias,- fusingMultiplyPerChannel,fusingRelu,fusingTanh};@@ -106,7 +104,6 @@ const std::vector<ShapeRelatedParams> IS = {std::vector<fusingSpecificParams> fusingParamsSet4D_smoke {emptyFusingSpec,- fusingMultiplyPerChannel,fusingRelu,fusingTanh};diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/matmul_weights_decompression.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/matmul_weights_decompression.cppindex 3643427de3e..9a434943893 100644--- a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/matmul_weights_decompression.cpp+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/matmul_weights_decompression.cpp@@ -87,7 +87,7 @@ public:result << "config=(";for (const auto& configEntry : additional_config) {- result << configEntry.first << ", " << configEntry.second.as<std::string>() << ":";+ result << configEntry.first << ", " << configEntry.second.as<std::string>() << "_";}result << ")";result << CpuTestWithFusing::getTestCaseName(fusing_params);diff --git a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/fullconnect.cpp b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/fullconnect.cppindex a5b01a2c3c2..90a2fc9d0b9 100644--- a/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/fullconnect.cpp+++ b/src/plugins/intel_cpu/tests/unit/shape_inference_test/custom_shape_infer/fullconnect.cpp@@ -4,9 +4,11 @@#include <gtest/gtest.h>-#include "openvino/op/parameter.hpp"-#include "transformations/cpu_opset/common/op/fully_connected.hpp"#include "custom_shape_infer.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/parameter.hpp"+#include "ov_ops/fully_connected.hpp"+namespace ov {namespace intel_cpu {namespace unit_test {@@ -16,16 +18,66 @@ using namespace ov;using namespace ov::intel_cpu;TEST(CpuShapeInfer, FC_InputSize_2) {- auto activate = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1 });+ auto activate = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1});auto weight = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{5, 6});- auto op = std::make_shared<ov::intel_cpu::FullyConnectedNode>(activate, weight, ov::Rank(5), element::f32);+ auto op = std::make_shared<ov::op::internal::FullyConnected>(+ activate,+ weight,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));std::vector<StaticShape> static_input_shapes = {StaticShape{720, 640}, {5, 6}};- std::vector<StaticShape> static_output_shapes = {StaticShape{1, 1, 1, 720, 5}};+ std::vector<StaticShape> static_output_shapes = {StaticShape{720, 5}};+ unit_test::cpu_test_shape_infer(op.get(), static_input_shapes, static_output_shapes);+}++TEST(CpuShapeInfer, FC_broadcastWeights1) {+ auto activate = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{1, -1, -1});+ auto weight = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{5, 6});+ auto op = std::make_shared<ov::op::internal::FullyConnected>(+ activate,+ weight,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));+ std::vector<StaticShape> static_input_shapes = {StaticShape{1, 720, 6}, {5, 6}};+ std::vector<StaticShape> static_output_shapes = {StaticShape{1, 720, 5}};+ unit_test::cpu_test_shape_infer(op.get(), static_input_shapes, static_output_shapes);+}++TEST(CpuShapeInfer, FC_broadcastWeights2) {+ auto activate = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto weight = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{5, 6});+ auto op = std::make_shared<ov::op::internal::FullyConnected>(+ activate,+ weight,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));+ std::vector<StaticShape> static_input_shapes = {StaticShape{2, 3, 720, 6}, {5, 6}};+ std::vector<StaticShape> static_output_shapes = {StaticShape{2, 3, 720, 5}};+ unit_test::cpu_test_shape_infer(op.get(), static_input_shapes, static_output_shapes);+}++TEST(CpuShapeInfer, FC_broadcastActivations1) {+ auto activate = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{720, -1});+ auto weight = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{1, 5, 6});+ auto op = std::make_shared<ov::op::internal::FullyConnected>(+ activate,+ weight,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));+ std::vector<StaticShape> static_input_shapes = {StaticShape{720, 6}, {1, 5, 6}};+ std::vector<StaticShape> static_output_shapes = {StaticShape{1, 720, 5}};unit_test::cpu_test_shape_infer(op.get(), static_input_shapes, static_output_shapes);}-} // namespace cpu_shape_infer-} // namespace unit_test-} // namespace intel_cpu-} // namespace ov+TEST(CpuShapeInfer, FC_broadcastActivations2) {+ auto activate = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1});+ auto weight = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{1, 1, 5, 6});+ auto op = std::make_shared<ov::op::internal::FullyConnected>(+ activate,+ weight,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));+ std::vector<StaticShape> static_input_shapes = {StaticShape{720, 6}, {1, 1, 5, 6}};+ std::vector<StaticShape> static_output_shapes = {StaticShape{1, 1, 720, 5}};+ unit_test::cpu_test_shape_infer(op.get(), static_input_shapes, static_output_shapes);+}+} // namespace cpu_shape_infer+} // namespace unit_test+} // namespace intel_cpu+} // namespace ovdiff --git a/src/plugins/intel_cpu/tests/unit/transformations/convert_matmul_test.cpp b/src/plugins/intel_cpu/tests/unit/transformations/convert_matmul_test.cppindex cb085920d97..37df1fd6d27 100644--- a/src/plugins/intel_cpu/tests/unit/transformations/convert_matmul_test.cpp+++ b/src/plugins/intel_cpu/tests/unit/transformations/convert_matmul_test.cpp@@ -4,21 +4,20 @@#include <gtest/gtest.h>-#include <string>#include <memory>-#include <openvino/core/model.hpp>#include <openvino/opsets/opset1.hpp>#include <openvino/opsets/opset3.hpp>#include <openvino/opsets/opset7.hpp>-#include <transformations/cpu_opset/common/op/fully_connected.hpp>+#include <openvino/pass/manager.hpp>+#include <ov_ops/type_relaxed.hpp>#include <transformations/cpu_opset/common/pass/convert_matmul_to_fc.hpp>#include <transformations/init_node_info.hpp>#include <transformations/utils/utils.hpp>-#include <openvino/pass/manager.hpp>-#include <ov_ops/type_relaxed.hpp>#include "common_test_utils/ov_test_utils.hpp"+#include "openvino/op/constant.hpp"+#include "ov_ops/fully_connected.hpp"#include "transformations/rt_info/decompression.hpp"using namespace testing;@@ -26,25 +25,28 @@ using namespace ov::intel_cpu;TEST_F(TransformationTestsF, ConvertMatMulToFCTest1) {{- auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 3, 2, 2 });- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 1, 2, 2 }, { 1 });+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 2});+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 2, 2}, {1});auto matmul = std::make_shared<ov::opset1::MatMul>(input1, input2, true, false);- model = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ model = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});manager.register_pass<ConvertMatMulToFC>();}{- auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 3, 2, 2 });- auto transpose_constant1 = ov::opset1::Constant::create(ov::element::i32, ov::Shape{ 3 }, { 0, 2, 1 });+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 2});+ auto transpose_constant1 = ov::opset1::Constant::create(ov::element::i32, ov::Shape{3}, {0, 2, 1});auto transpose1 = std::make_shared<ov::opset1::Transpose>(input1, transpose_constant1);- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 2, 2 }, { 1 });- auto transpose_constant2 = ov::opset1::Constant::create(ov::element::i32, ov::Shape{ 2 }, { 1, 0 });+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 2, 2}, {1});+ auto transpose_constant2 = ov::opset1::Constant::create(ov::element::i32, ov::Shape{3}, {0, 2, 1});auto transpose2 = std::make_shared<ov::opset1::Transpose>(input2, transpose_constant2);- auto matmul = std::make_shared<FullyConnectedNode>(transpose1, transpose2, ov::Rank(3));+ auto matmul = std::make_shared<ov::op::internal::FullyConnected>(+ transpose1,+ transpose2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));- model_ref = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ model_ref = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});}}@@ -78,7 +80,10 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest3) {{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 2});auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 2}, {1});- auto matmul = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(3));+ auto matmul = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));model_ref = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});}@@ -96,27 +101,30 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest4) {{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, 2});auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 2}, {1});- auto matmul = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(3));+ auto matmul = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));model_ref = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});}}TEST_F(TransformationTestsF, ConvertMatMulToFCTest5) {- auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{ -1, -1, 2 });- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 3, 2, 2 }, { 1 });+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, 2});+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{3, 2, 2}, {1});auto matmul = std::make_shared<ov::opset1::MatMul>(input1, input2, false, true);- model = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ model = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});manager.register_pass<ConvertMatMulToFC>();}TEST_F(TransformationTestsF, ConvertMatMulToFCTest6) {- auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{ -1, -1, 2 });- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 3, 1, 2 }, { 1 });+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, 2});+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{3, 1, 2}, {1});auto matmul = std::make_shared<ov::opset1::MatMul>(input1, input2, false, true);- model = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ model = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});manager.register_pass<ConvertMatMulToFC>();}@@ -132,7 +140,10 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest7) {{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 2});auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{3, 2}, {1});- auto fc = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(2));+ auto fc = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));model_ref = std::make_shared<ov::Model>(ov::NodeVector{fc}, ov::ParameterVector{input1});}@@ -151,11 +162,14 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest8) {auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, 2});auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{3, 2}, {1});- auto fc = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(2));+ auto fc = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));auto a_shape = std::make_shared<ov::opset3::ShapeOf>(input1);auto I = ov::op::util::node_to_get_shape_value_of_indices_from_shape_node(a_shape, {0, 1});- auto O = ov::opset1::Constant::create(ov::element::i64, { 1 }, { 3 });+ auto O = ov::opset1::Constant::create(ov::element::i64, {1}, {3});auto output_shape = std::make_shared<ov::opset1::Concat>(ov::OutputVector{I, O}, 0);model_ref = std::make_shared<ov::Model>(ov::NodeVector{fc}, ov::ParameterVector{input1});@@ -174,7 +188,10 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest9) {{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 2});auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 2}, {1});- auto matmul = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(3));+ auto matmul = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));model_ref = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});}@@ -182,10 +199,10 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest9) {TEST_F(TransformationTestsF, ConvertMatMulToFCTest10) {auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape::dynamic());- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 2, 2 }, { 1 });+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 2}, {1});auto matmul = std::make_shared<ov::opset1::MatMul>(input1, input2, false, true);- model = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ model = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});manager.register_pass<ConvertMatMulToFC>();}@@ -218,8 +235,11 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest13) {}{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, 1});- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{80, 1}, {1});- auto matmul = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(3));+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 80, 1}, {1});+ auto matmul = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));model_ref = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});}@@ -242,8 +262,13 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest14) {}{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::u8, ov::PartialShape{-1, -1, 1});- auto input2 = ov::opset1::Constant::create(ov::element::i8, ov::Shape{80, 1}, {1});- auto matmul = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(3), ov::element::f32);+ auto input2 = ov::opset1::Constant::create(ov::element::i8, ov::Shape{1, 80, 1}, {1});++ auto matmul = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}),+ ov::element::f32);model_ref = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});}@@ -252,7 +277,7 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest14) {TEST_F(TransformationTestsF, ConvertMatMulToFCTest_4d_1) {{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{2, 3, 4, 5});- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 6, 5 }, { 1 });+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{6, 5}, {1});auto matmul = std::make_shared<ov::opset1::MatMul>(input1, input2, false, true);model = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});@@ -260,8 +285,13 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest_4d_1) {}{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{2, 3, 4, 5});- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 6, 5 }, { 1 });- auto fc = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(4), ov::element::f32);+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{6, 5}, {1});++ auto fc = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}),+ ov::element::f32);model_ref = std::make_shared<ov::Model>(ov::NodeVector{fc}, ov::ParameterVector{input1});}@@ -278,8 +308,11 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest_4d_2) {}{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, 1, 5});- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{10, 5}, {1});- auto fc = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(4));+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 10, 5}, {1});+ auto fc = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));model_ref = std::make_shared<ov::Model>(ov::NodeVector{fc}, ov::ParameterVector{input1});}@@ -288,7 +321,7 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest_4d_2) {TEST_F(TransformationTestsF, ConvertMatMulToFCTest_4d_3) {{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{2, 4});- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1, 5, 4}, { 1 });+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1, 5, 4}, {1});auto matmul = std::make_shared<ov::opset1::MatMul>(input1, input2, false, true);model = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});@@ -296,8 +329,12 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest_4d_3) {}{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{2, 4});- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{5, 4}, { 1 });- auto fc = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(4), ov::element::f32);+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1, 5, 4}, {1});+ auto fc = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}),+ ov::element::f32);model_ref = std::make_shared<ov::Model>(ov::NodeVector{fc}, ov::ParameterVector{input1});}@@ -306,7 +343,7 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest_4d_3) {TEST_F(TransformationTestsF, ConvertMatMulToFCTest_4d_4) {{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 4});- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1, 5, 4}, { 1 });+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1, 5, 4}, {1});auto matmul = std::make_shared<ov::opset1::MatMul>(input1, input2, false, true);model = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});@@ -314,8 +351,12 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest_4d_4) {}{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 4});- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{5, 4}, { 1 });- auto fc = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(4), ov::element::f32);+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1, 5, 4}, {1});+ auto fc = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}),+ ov::element::f32);model_ref = std::make_shared<ov::Model>(ov::NodeVector{fc}, ov::ParameterVector{input1});}@@ -324,7 +365,7 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest_4d_4) {TEST_F(TransformationTestsF, ConvertMatMulToFCTest_4d_5) {{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{2, 3, 2, 4});- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1, 5, 4}, { 1 });+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1, 5, 4}, {1});auto matmul = std::make_shared<ov::opset1::MatMul>(input1, input2, false, true);model = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});@@ -332,8 +373,12 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest_4d_5) {}{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{2, 3, 2, 4});- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{5, 4}, { 1 });- auto fc = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(4), ov::element::f32);+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1, 5, 4}, {1});+ auto fc = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}),+ ov::element::f32);model_ref = std::make_shared<ov::Model>(ov::NodeVector{fc}, ov::ParameterVector{input1});}@@ -350,97 +395,112 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest_second_input_rank_adj_1) {}{auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{5, 2, 3});- auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 3}, {1});- auto matmul = std::make_shared<FullyConnectedNode>(input1, input2, ov::Rank(2));+ auto input2 = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 2, 3}, {1});+ auto matmul = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ input2,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));model_ref = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});}}TEST_F(TransformationTestsF, ConvertMatMulToFCTest_second_input_rank_adj_2) {{- auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 2, 3 });- auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 2, 3 }, { 1 });+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{2, 3});+ auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 3}, {1});auto matmul = std::make_shared<ov::opset1::MatMul>(input1, weights, false, true);- model = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ model = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});manager.register_pass<ConvertMatMulToFC>();}{- auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 2, 3 });- auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 2, 3 }, { 1 });- auto matmul = std::make_shared<FullyConnectedNode>(input1, weights, ov::Rank(2));+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{2, 3});+ auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2, 3}, {1});+ auto matmul = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ weights,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));- model_ref = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ model_ref = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});}}TEST_F(TransformationTestsF, ConvertMatMulToFCTest_second_input_rank_adj_3) {{- auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 5, 2, 3 });- auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 1, 2, 3 }, { 1 });+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{5, 2, 3});+ auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 2, 3}, {1});auto matmul = std::make_shared<ov::opset1::MatMul>(input1, weights, false, true);- model = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ model = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});manager.register_pass<ConvertMatMulToFC>();}{- auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 5, 2, 3 });+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{5, 2, 3});- auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 2, 3 }, { 1 });- auto matmul = std::make_shared<FullyConnectedNode>(input1, weights, ov::Rank(3));- model_ref = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ auto weights = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 2, 3}, {1});+ auto matmul = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ weights,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));+ model_ref = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});}}TEST_F(TransformationTestsF, ConvertMatMulToFCTest_decompress_convert_0) {{- auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 3, 2, 2 });- auto input2 = ov::opset1::Constant::create(ov::element::f16, ov::Shape{ 1, 2, 2 }, { 1 });+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 2});+ auto input2 = ov::opset1::Constant::create(ov::element::f16, ov::Shape{1, 2, 2}, {1});auto convert = std::make_shared<ov::opset1::Convert>(input2, ov::element::f32);ov::mark_as_decompression(convert);auto matmul = std::make_shared<ov::opset1::MatMul>(input1, convert, false, false);- model = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ model = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});manager.register_pass<ConvertMatMulToFC>();}{- auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 3, 2, 2 });+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 2});- auto input2 = ov::opset1::Constant::create(ov::element::f16, ov::Shape{ 2, 2 }, { 1 });- auto transpose_constant = ov::opset1::Constant::create(ov::element::i32, ov::Shape{ 2 }, { 1, 0 });+ auto input2 = ov::opset1::Constant::create(ov::element::f16, ov::Shape{1, 2, 2}, {1});+ auto transpose_constant = ov::opset1::Constant::create(ov::element::i32, ov::Shape{3}, {0, 2, 1});auto transpose = std::make_shared<ov::opset1::Transpose>(input2, transpose_constant);auto convert = std::make_shared<ov::opset1::Convert>(transpose, ov::element::f32);- auto matmul = std::make_shared<FullyConnectedNode>(input1, convert, ov::Rank(3));+ auto matmul = std::make_shared<ov::op::internal::FullyConnected>(+ input1,+ convert,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));- model_ref = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ model_ref = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});}}TEST_F(TransformationTestsF, ConvertMatMulToFCTest_decompress_convert_1) {{- auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 3, 2, 2 });- auto input2 = ov::opset1::Constant::create(ov::element::f16, ov::Shape{ 1, 2, 2 }, { 1 });+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 2});+ auto input2 = ov::opset1::Constant::create(ov::element::f16, ov::Shape{1, 2, 2}, {1});auto convert = std::make_shared<ov::opset1::Convert>(input2, ov::element::f32);ov::mark_as_decompression(convert);auto matmul = std::make_shared<ov::opset1::MatMul>(input1, convert, true, false);- model = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ model = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});manager.register_pass<ConvertMatMulToFC>();}{- auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 3, 2, 2 });- auto transpose_constant1 = ov::opset1::Constant::create(ov::element::i32, ov::Shape{ 3 }, { 0, 2, 1 });+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 2});+ auto transpose_constant1 = ov::opset1::Constant::create(ov::element::i32, ov::Shape{3}, {0, 2, 1});auto transpose1 = std::make_shared<ov::opset1::Transpose>(input1, transpose_constant1);- auto input2 = ov::opset1::Constant::create(ov::element::f16, ov::Shape{ 2, 2 }, { 1 });- auto transpose_constant2 = ov::opset1::Constant::create(ov::element::i32, ov::Shape{ 2 }, { 1, 0 });+ auto input2 = ov::opset1::Constant::create(ov::element::f16, ov::Shape{1, 2, 2}, {1});+ auto transpose_constant2 = ov::opset1::Constant::create(ov::element::i32, ov::Shape{3}, {0, 2, 1});auto transpose2 = std::make_shared<ov::opset1::Transpose>(input2, transpose_constant2);auto convert = std::make_shared<ov::opset1::Convert>(transpose2, ov::element::f32);- auto matmul = std::make_shared<FullyConnectedNode>(transpose1, convert, ov::Rank(3));+ auto matmul = std::make_shared<ov::op::internal::FullyConnected>(+ transpose1,+ convert,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));- model_ref = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ input1 });+ model_ref = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{input1});}}@@ -467,12 +527,13 @@ TEST_F(TransformationTestsF, ConvertMatMulToFCTest_compressed_u8_weights) {auto mul_const = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1, 2}, {1});auto mul = std::make_shared<ov::opset1::Multiply>(sub, mul_const);- auto reshape_const = ov::opset1::Constant::create(ov::element::i32, {2}, {2, -1});- auto reshape = std::make_shared<ov::opset1::Reshape>(mul, reshape_const, false);- auto transpose_const = ov::opset1::Constant::create(ov::element::i32, {2}, {1, 0});- auto transpose = std::make_shared<ov::opset1::Transpose>(reshape, transpose_const);- auto matmul = std::make_shared<FullyConnectedNode>(data, transpose, ov::Rank(3));+ auto transpose_const = ov::opset1::Constant::create(ov::element::i32, {3}, {0, 2, 1});+ auto transpose = std::make_shared<ov::opset1::Transpose>(mul, transpose_const);+ auto matmul = std::make_shared<ov::op::internal::FullyConnected>(+ data,+ transpose,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));- model_ref = std::make_shared<ov::Model>(ov::NodeVector{ matmul }, ov::ParameterVector{ data });+ model_ref = std::make_shared<ov::Model>(ov::NodeVector{matmul}, ov::ParameterVector{data});}}diff --git a/src/plugins/intel_cpu/tests/unit/transformations/move_fc_reshape_to_weights.cpp b/src/plugins/intel_cpu/tests/unit/transformations/move_fc_reshape_to_weights.cppindex 68241c9169b..b3d733aecba 100644--- a/src/plugins/intel_cpu/tests/unit/transformations/move_fc_reshape_to_weights.cpp+++ b/src/plugins/intel_cpu/tests/unit/transformations/move_fc_reshape_to_weights.cpp@@ -11,7 +11,7 @@#include <openvino/core/model.hpp>#include <openvino/opsets/opset1.hpp>-#include <transformations/cpu_opset/common/op/fully_connected.hpp>+#include "ov_ops/fully_connected.hpp"#include <transformations/init_node_info.hpp>#include <transformations/utils/utils.hpp>@@ -115,7 +115,12 @@ public:auto transpose_const = ov::opset1::Constant::create(ov::element::i32, {2}, {1, 0});weights_path = std::make_shared<ov::opset1::Transpose>(weights_path, transpose_const);}- auto fully_connected = std::make_shared<FullyConnectedNode>(data, weights_path, ov::Rank(3));++ auto fully_connected = std::make_shared<ov::op::internal::FullyConnected>(+ data,+ weights_path,+ std::make_shared<ov::op::v0::Constant>(ov::element::undefined, ov::Shape{0}));+return std::make_shared<ov::Model>(ov::NodeVector{fully_connected}, ov::ParameterVector{data});}diff --git a/src/plugins/intel_cpu/tests/unit/transformations/split_fc_test.cpp b/src/plugins/intel_cpu/tests/unit/transformations/split_fc_test.cppdeleted file mode 100644index 4c955ec5286..00000000000--- a/src/plugins/intel_cpu/tests/unit/transformations/split_fc_test.cpp+++ /dev/null@@ -1,280 +0,0 @@-// Copyright (C) 2018-2024 Intel Corporation-// SPDX-License-Identifier: Apache-2.0-//--#include <gtest/gtest.h>--#include <string>-#include <memory>--#include <openvino/core/model.hpp>-#include <openvino/opsets/opset1.hpp>-#include <transformations/cpu_opset/common/op/fully_connected.hpp>-#include <transformations/cpu_opset/common/pass/split_fc.hpp>-#include <transformations/init_node_info.hpp>-#include <transformations/utils/utils.hpp>-#include "openvino/core/visibility.hpp"-#include <openvino/pass/manager.hpp>-#include <ov_ops/type_relaxed.hpp>--#include "common_test_utils/ov_test_utils.hpp"-#include "transformations/rt_info/decompression.hpp"--using namespace testing;-using namespace ov::intel_cpu;--#if defined (OPENVINO_ARCH_ARM) && defined(__linux__)-// Ticket: 153166-TEST_F(TransformationTestsF, DISABLED_SplitFCTest) {-#else-TEST_F(TransformationTestsF, SplitFCTest) {-#endif- disable_rt_info_check();- {- auto src = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 3, 4096, 1 });- auto transpose_constant_src = ov::opset1::Constant::create(ov::element::i32, ov::Shape{ 3 }, { 0, 2, 1 });- auto transpose_src = std::make_shared<ov::opset1::Transpose>(src, transpose_constant_src);-- auto wgt = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 2048, 4096 }, { 12.34 });-- auto fc = std::make_shared<FullyConnectedNode>(transpose_src, wgt, ov::Rank(3));- model = std::make_shared<ov::Model>(ov::NodeVector{fc}, ov::ParameterVector{src});- manager.register_pass<SplitFC>(1);- }- {- auto src = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 3, 4096, 1 });- auto transpose_constant_src = ov::opset1::Constant::create(ov::element::i32, ov::Shape{ 3 }, { 0, 2, 1 });- auto transpose_src = std::make_shared<ov::opset1::Transpose>(src, transpose_constant_src);-- auto wgt = ov::opset1::Constant::create(ov::element::f32, ov::Shape{ 2048, 4096 }, { 12.34 });-- auto split_dim_node = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, 0);- auto split_length = ov::opset1::Constant::create<int32_t>(ov::element::i32, ov::Shape{2}, {1024, 1024});- auto split_wgts = std::make_shared<ov::opset1::VariadicSplit>(wgt, split_dim_node, split_length);-- auto fc0 = std::make_shared<FullyConnectedNode>(transpose_src, split_wgts->output(0), ov::Rank(3));- auto fc1 = std::make_shared<FullyConnectedNode>(transpose_src, split_wgts->output(1), ov::Rank(3));-- ov::NodeVector concat_args({fc0, fc1});- constexpr size_t concat_dim = -1;- auto concat = std::make_shared<ov::opset1::Concat>(concat_args, concat_dim);- model_ref = std::make_shared<ov::Model>(ov::NodeVector{concat}, ov::ParameterVector{src});- }-}--#if defined (OPENVINO_ARCH_ARM) && defined(__linux__)-// Ticket: 153166-TEST_F(TransformationTestsF, DISABLED_SplitFCTest_int8_weight) {-#else-TEST_F(TransformationTestsF, SplitFCTest_int8_weight) {-#endif- disable_rt_info_check();- {- auto src = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 4096, 1});- auto transpose_constant_src = ov::opset1::Constant::create(ov::element::i32, ov::Shape{3}, {0, 2, 1});- auto transpose_src = std::make_shared<ov::opset1::Transpose>(src, transpose_constant_src);-- auto wgt = ov::opset1::Constant::create(ov::element::u8, ov::Shape{2048, 4096}, {123});- auto cvt_wgt = std::make_shared<ov::opset1::Convert>(wgt, ov::element::f32);-- auto zp = ov::opset1::Constant::create(ov::element::u8, ov::Shape{2048, 1}, {1});- auto cvt_zp = std::make_shared<ov::opset1::Convert>(zp, ov::element::f32);-- auto sub = std::make_shared<ov::opset1::Subtract>(cvt_wgt, cvt_zp);-- auto mul_const = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2048, 1}, {0.2});- auto mul = std::make_shared<ov::opset1::Multiply>(sub, mul_const);-- auto fc = std::make_shared<FullyConnectedNode>(transpose_src, mul, ov::Rank(3));- model = std::make_shared<ov::Model>(ov::NodeVector{fc}, ov::ParameterVector{src});- manager.register_pass<SplitFC>(1);- }- {- auto src = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 3, 4096, 1 });- auto transpose_constant_src = ov::opset1::Constant::create(ov::element::i32, ov::Shape{ 3 }, { 0, 2, 1 });- auto transpose_src = std::make_shared<ov::opset1::Transpose>(src, transpose_constant_src);-- auto wgt = ov::opset1::Constant::create(ov::element::u8, ov::Shape{ 2048, 4096 }, { 123 });- auto cvt_wgt = std::make_shared<ov::opset1::Convert>(wgt, ov::element::f32);-- auto split_dim_node = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, 0);- auto split_length = ov::opset1::Constant::create<int32_t>(ov::element::i32, ov::Shape{2}, {1024, 1024});-- auto split_wgts = std::make_shared<ov::opset1::VariadicSplit>(wgt, split_dim_node, split_length);- auto cvt_wgt0 = std::make_shared<ov::opset1::Convert>(split_wgts->output(0), ov::element::f32);- auto cvt_wgt1 = std::make_shared<ov::opset1::Convert>(split_wgts->output(1), ov::element::f32);-- auto zp = ov::opset1::Constant::create(ov::element::u8, ov::Shape{2048, 1}, {1});- auto split_zp = std::make_shared<ov::opset1::VariadicSplit>(zp, split_dim_node, split_length);-- auto cvt_zp0 = std::make_shared<ov::opset1::Convert>(split_zp->output(0), ov::element::f32);- auto cvt_zp1 = std::make_shared<ov::opset1::Convert>(split_zp->output(1), ov::element::f32);-- auto sub0 = std::make_shared<ov::opset1::Subtract>(cvt_wgt0, cvt_zp0);- auto sub1 = std::make_shared<ov::opset1::Subtract>(cvt_wgt1, cvt_zp1);-- auto mul_const = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2048, 1}, {0.2});- auto split_mul_const = std::make_shared<ov::opset1::VariadicSplit>(mul_const, split_dim_node, split_length);-- auto mul0 = std::make_shared<ov::opset1::Multiply>(sub0, split_mul_const->output(0));- auto mul1 = std::make_shared<ov::opset1::Multiply>(sub1, split_mul_const->output(1));-- auto fc0 = std::make_shared<FullyConnectedNode>(transpose_src, mul0, ov::Rank(3));- auto fc1 = std::make_shared<FullyConnectedNode>(transpose_src, mul1, ov::Rank(3));-- ov::NodeVector concat_args({fc0, fc1});- constexpr size_t concat_dim = -1;- auto concat = std::make_shared<ov::opset1::Concat>(concat_args, concat_dim);- model_ref = std::make_shared<ov::Model>(ov::NodeVector{concat}, ov::ParameterVector{src});- }-}--#if defined (OPENVINO_ARCH_ARM) && defined(__linux__)-// Ticket: 153166-TEST_F(TransformationTestsF, DISABLED_SplitFCTest_int4_weight) {-#else-TEST_F(TransformationTestsF, SplitFCTest_int4_weight) {-#endif- disable_rt_info_check();- {- auto src = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 4096, 1});- auto transpose_constant_src = ov::opset1::Constant::create(ov::element::i32, ov::Shape{3}, {0, 2, 1});- auto transpose_src = std::make_shared<ov::opset1::Transpose>(src, transpose_constant_src);-- auto wgt = ov::opset1::Constant::create(ov::element::u4, ov::Shape{2048, 4096}, {12});- auto cvt_wgt = std::make_shared<ov::opset1::Convert>(wgt, ov::element::f32);-- auto zp = ov::opset1::Constant::create(ov::element::u4, ov::Shape{2048, 1}, {1});- auto cvt_zp = std::make_shared<ov::opset1::Convert>(zp, ov::element::f32);-- auto sub = std::make_shared<ov::opset1::Subtract>(cvt_wgt, cvt_zp);-- auto mul_const = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2048, 1}, {0.2});- auto mul = std::make_shared<ov::opset1::Multiply>(sub, mul_const);-- auto fc = std::make_shared<FullyConnectedNode>(transpose_src, mul, ov::Rank(3));- model = std::make_shared<ov::Model>(ov::NodeVector{fc}, ov::ParameterVector{src});- manager.register_pass<SplitFC>(1);- }- {- auto src = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 4096, 1});- auto transpose_constant_src = ov::opset1::Constant::create(ov::element::i32, ov::Shape{3}, {0, 2, 1});- auto transpose_src = std::make_shared<ov::opset1::Transpose>(src, transpose_constant_src);-- auto wgt = ov::opset1::Constant::create(ov::element::u4, ov::Shape{2048, 4096}, {12});- auto cvt_wgt_i8 = std::make_shared<ov::opset1::Convert>(wgt, ov::element::i8);-- auto split_dim_node = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, 0);- auto split_length = ov::opset1::Constant::create<int32_t>(ov::element::i32, ov::Shape{2}, {1024, 1024});-- auto split_wgts = std::make_shared<ov::opset1::VariadicSplit>(cvt_wgt_i8, split_dim_node, split_length);- auto cvt_wgt0_u4 = std::make_shared<ov::opset1::Convert>(split_wgts->output(0), ov::element::u4);- auto cvt_wgt1_u4 = std::make_shared<ov::opset1::Convert>(split_wgts->output(1), ov::element::u4);- auto cvt_wgt0_f32 = std::make_shared<ov::opset1::Convert>(cvt_wgt0_u4, ov::element::f32);- auto cvt_wgt1_f32 = std::make_shared<ov::opset1::Convert>(cvt_wgt1_u4, ov::element::f32);-- auto zp = ov::opset1::Constant::create(ov::element::u4, ov::Shape{2048, 1}, {1});- auto cvt_zp_i8 = std::make_shared<ov::opset1::Convert>(zp, ov::element::i8);- auto split_zp = std::make_shared<ov::opset1::VariadicSplit>(cvt_zp_i8, split_dim_node, split_length);-- auto cvt_zp0_u4 = std::make_shared<ov::opset1::Convert>(split_zp->output(0), ov::element::u4);- auto cvt_zp1_u4 = std::make_shared<ov::opset1::Convert>(split_zp->output(1), ov::element::u4);- auto cvt_zp0_f32 = std::make_shared<ov::opset1::Convert>(cvt_zp0_u4, ov::element::f32);- auto cvt_zp1_f32 = std::make_shared<ov::opset1::Convert>(cvt_zp1_u4, ov::element::f32);-- auto sub0 = std::make_shared<ov::opset1::Subtract>(cvt_wgt0_f32, cvt_zp0_f32);- auto sub1 = std::make_shared<ov::opset1::Subtract>(cvt_wgt1_f32, cvt_zp1_f32);-- auto mul_const = ov::opset1::Constant::create(ov::element::f32, ov::Shape{2048, 1}, {0.2});- auto split_mul_const = std::make_shared<ov::opset1::VariadicSplit>(mul_const, split_dim_node, split_length);-- auto mul0 = std::make_shared<ov::opset1::Multiply>(sub0, split_mul_const->output(0));- auto mul1 = std::make_shared<ov::opset1::Multiply>(sub1, split_mul_const->output(1));-- auto fc0 = std::make_shared<FullyConnectedNode>(transpose_src, mul0, ov::Rank(3));- auto fc1 = std::make_shared<FullyConnectedNode>(transpose_src, mul1, ov::Rank(3));-- ov::NodeVector concat_args({fc0, fc1});- constexpr size_t concat_dim = -1;- auto concat = std::make_shared<ov::opset1::Concat>(concat_args, concat_dim);- model_ref = std::make_shared<ov::Model>(ov::NodeVector{concat}, ov::ParameterVector{src});- }-}--#if (defined OPENVINO_ARCH_ARM && defined(__linux__))-// Ticket: 153166-TEST_F(TransformationTestsF, DISABLED_SplitFCTest_int4_weight_reshape) {-#else-TEST_F(TransformationTestsF, SplitFCTest_int4_weight_reshape) {-#endif- disable_rt_info_check();- {- auto src = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 3, 2048, 1 });- auto transpose_constant_src = ov::opset1::Constant::create(ov::element::i32, ov::Shape{ 3 }, { 0, 2, 1 });- auto transpose_src = std::make_shared<ov::opset1::Transpose>(src, transpose_constant_src);-- auto wgt = ov::opset1::Constant::create(ov::element::u4, ov::Shape{ 4096, 2, 1024}, { 12 });- auto cvt_wgt = std::make_shared<ov::opset1::Convert>(wgt, ov::element::f32);-- auto zp = ov::opset1::Constant::create(ov::element::u4, ov::Shape{1}, { 1 });- auto cvt_zp = std::make_shared<ov::opset1::Convert>(zp, ov::element::f32);-- auto sub = std::make_shared<ov::opset1::Subtract>(cvt_wgt, cvt_zp);-- auto mul_const = ov::opset1::Constant::create(ov::element::f32, ov::Shape{4096, 2, 1}, {0.2});- auto mul = std::make_shared<ov::opset1::Multiply>(sub, mul_const);-- auto res_const = ov::opset1::Constant::create(ov::element::i32, ov::Shape{2}, {4096, 2048});- auto reshape = std::make_shared<ov::opset1::Reshape>(mul, res_const, false);-- auto fc = std::make_shared<FullyConnectedNode>(transpose_src, reshape, ov::Rank(3));- model = std::make_shared<ov::Model>(ov::NodeVector{fc}, ov::ParameterVector{src});- manager.register_pass<SplitFC>(1);- }- {- auto src = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{ 3, 2048, 1 });- auto transpose_constant_src = ov::opset1::Constant::create(ov::element::i32, ov::Shape{ 3 }, { 0, 2, 1 });- auto transpose_src = std::make_shared<ov::opset1::Transpose>(src, transpose_constant_src);-- auto wgt = ov::opset1::Constant::create(ov::element::u4, ov::Shape{ 4096, 2, 1024 }, { 12 });- auto cvt_wgt_i8 = std::make_shared<ov::opset1::Convert>(wgt, ov::element::i8);-- auto split_dim_node = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, 0);- auto split_length = ov::opset1::Constant::create<int32_t>(ov::element::i32, ov::Shape{2}, {2048, 2048});-- auto split_wgts = std::make_shared<ov::opset1::VariadicSplit>(cvt_wgt_i8, split_dim_node, split_length);- auto cvt_wgt0_u4 = std::make_shared<ov::opset1::Convert>(split_wgts->output(0), ov::element::u4);- auto cvt_wgt1_u4 = std::make_shared<ov::opset1::Convert>(split_wgts->output(1), ov::element::u4);- auto cvt_wgt0_f32 = std::make_shared<ov::opset1::Convert>(cvt_wgt0_u4, ov::element::f32);- auto cvt_wgt1_f32 = std::make_shared<ov::opset1::Convert>(cvt_wgt1_u4, ov::element::f32);-- auto zp = ov::opset1::Constant::create(ov::element::u4, ov::Shape{1}, { 1 });- auto zp0 = std::make_shared<ov::opset1::Constant>(zp->get_element_type(), zp->get_shape(), zp->get_data_ptr());- auto zp1 = std::make_shared<ov::opset1::Constant>(zp->get_element_type(), zp->get_shape(), zp->get_data_ptr());-- auto cvt_zp0 = std::make_shared<ov::opset1::Convert>(zp0, ov::element::f32);- auto cvt_zp1 = std::make_shared<ov::opset1::Convert>(zp1, ov::element::f32);-- auto sub0 = std::make_shared<ov::opset1::Subtract>(cvt_wgt0_f32, cvt_zp0);- auto sub1 = std::make_shared<ov::opset1::Subtract>(cvt_wgt1_f32, cvt_zp1);-- auto mul_const = ov::opset1::Constant::create(ov::element::f32, ov::Shape{4096, 2, 1}, {0.2});- auto split_mul_const = std::make_shared<ov::opset1::VariadicSplit>(mul_const, split_dim_node, split_length);-- auto mul0 = std::make_shared<ov::opset1::Multiply>(sub0, split_mul_const->output(0));- auto mul1 = std::make_shared<ov::opset1::Multiply>(sub1, split_mul_const->output(1));-- std::vector<int32_t> reshape_pattern_vec = {2048, 2048};- auto reshape_pattern = std::make_shared<ov::opset1::Constant>(ov::element::i32, ov::Shape{2}, reshape_pattern_vec);- auto reshape0 = std::make_shared<ov::opset1::Reshape>(mul0, reshape_pattern, false);- auto reshape1 = std::make_shared<ov::opset1::Reshape>(mul1, reshape_pattern, false);-- auto fc0 = std::make_shared<FullyConnectedNode>(transpose_src, reshape0, ov::Rank(3));- auto fc1 = std::make_shared<FullyConnectedNode>(transpose_src, reshape1, ov::Rank(3));-- ov::NodeVector concat_args({fc0, fc1});- constexpr size_t concat_dim = -1;- auto concat = std::make_shared<ov::opset1::Concat>(concat_args, concat_dim);- model_ref = std::make_shared<ov::Model>(ov::NodeVector{concat}, ov::ParameterVector{src});- }-}diff --git a/src/tests/test_utils/common_test_utils/src/ov_test_utils.cpp b/src/tests/test_utils/common_test_utils/src/ov_test_utils.cppindex 8ca920d4210..d781d92b570 100644--- a/src/tests/test_utils/common_test_utils/src/ov_test_utils.cpp+++ b/src/tests/test_utils/common_test_utils/src/ov_test_utils.cpp@@ -88,6 +88,7 @@ void TransformationTestsF::TearDown() {ASSERT_TRUE(res.valid) << res.message;comparator.disable(FunctionsComparator::CmpValues::ACCURACY);}+auto res = comparator.compare(model, model_ref);ASSERT_TRUE(res.valid) << res.message;}