Skip to content

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

[GPU] Introduce ConvertWeightCompressedConv1x1ToMatmul pass (#32224)

Mikhail Dvoretckii662d21e5dc66
diff --git a/src/common/transformations/include/transformations/utils/utils.hpp b/src/common/transformations/include/transformations/utils/utils.hpp
index 83589cbb157..946741e66cd 100644
--- a/src/common/transformations/include/transformations/utils/utils.hpp
+++ b/src/common/transformations/include/transformations/utils/utils.hpp
@@ -17,6 +17,7 @@
#include "openvino/core/rt_info.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convert.hpp"
+#include "openvino/op/random_uniform.hpp"
#include "openvino/pass/graph_rewrite.hpp"
#include "openvino/pass/pattern/op/op.hpp"
#include "openvino/util/pp.hpp"
@@ -287,7 +288,43 @@ TRANSFORMATIONS_API bool can_eliminate_eltwise_node(const std::shared_ptr<Node>&
TRANSFORMATIONS_API bool is_constant_and_all_values_equal_int(const Output<Node>& output, const int64_t& v);
-TRANSFORMATIONS_API bool is_on_constant_path(const ov::Output<ov::Node>& output);
+template <typename... AllowedTypes>
+bool is_on_path(const ov::Output<ov::Node>& output) {
+ auto status = true;
+
+ auto root_node = output.get_node();
+ if (!root_node || root_node->get_output_size() == 0) {
+ return false;
+ }
+ std::deque<ov::Node*> nodes_to_calculate = {root_node};
+
+ std::unordered_set<ov::Node*> visited;
+ while (status && !nodes_to_calculate.empty()) {
+ auto current_node = nodes_to_calculate.front();
+ nodes_to_calculate.pop_front();
+ if (visited.count(current_node)) {
+ continue;
+ }
+ visited.insert(current_node);
+ // RandomUniform output changes during runtime, so we should not consider it as a constant
+ if (current_node->get_type_info() == ov::op::v8::RandomUniform::get_type_info_static()) {
+ return false;
+ }
+
+ if (current_node->get_input_size() == 0 && !(ov::is_type_any_of<AllowedTypes...>(current_node))) {
+ status = false;
+ } else {
+ // not a leaf - continue to search
+ for (const auto& input_value : current_node->input_values()) {
+ const auto& input_node = input_value.get_node();
+ if (!visited.count(input_node)) {
+ nodes_to_calculate.push_front(input_node);
+ }
+ }
+ }
+ }
+ return status;
+}
TRANSFORMATIONS_API bool process_subgraph(ov::pass::ModelPass& model_pass, const std::shared_ptr<Node>& node);
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.cpp
index 4a1b3ea78fc..6b0ceec6c71 100644
--- 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.cpp
@@ -45,7 +45,7 @@ ov::pass::ConvertFCToFCQuantizedLegacy::ConvertFCToFCQuantizedLegacy() {
const auto& multiply_output_shape = multiply.get_partial_shape();
if (*fc_output_shape.rbegin() != *multiply_output_shape.rbegin() ||
- !ov::op::util::is_on_constant_path(weights)) {
+ !ov::op::util::is_on_path<ov::op::v0::Constant>(weights)) {
return false;
}
diff --git a/src/common/transformations/src/transformations/op_conversions/convert_sequences_to_tensor_iterator.cpp b/src/common/transformations/src/transformations/op_conversions/convert_sequences_to_tensor_iterator.cpp
index 29f9ef9ab0a..4f872a3b7e2 100644
--- a/src/common/transformations/src/transformations/op_conversions/convert_sequences_to_tensor_iterator.cpp
+++ b/src/common/transformations/src/transformations/op_conversions/convert_sequences_to_tensor_iterator.cpp
@@ -128,17 +128,17 @@ bool convert_sequence_to_ti(const std::shared_ptr<ov::Node>& sequence,
const auto squeezed_x = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(X_body_param, axis_1);
const auto squeezed_w = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(W, axis_0);
std::shared_ptr<ov::op::v0::Parameter> W_body_param;
- if (!ov::op::util::is_on_constant_path(squeezed_w))
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(squeezed_w))
W_body_param = std::make_shared<ov::op::v0::Parameter>(squeezed_w->get_element_type(),
squeezed_w->get_output_partial_shape(0));
const auto squeezed_r = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(R, axis_0);
std::shared_ptr<ov::op::v0::Parameter> R_body_param;
- if (!ov::op::util::is_on_constant_path(squeezed_r))
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(squeezed_r))
R_body_param = std::make_shared<ov::op::v0::Parameter>(squeezed_r->get_element_type(),
squeezed_r->get_output_partial_shape(0));
const auto squeezed_b = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(B, axis_0);
std::shared_ptr<ov::op::v0::Parameter> B_body_param;
- if (!ov::op::util::is_on_constant_path(squeezed_b))
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(squeezed_b))
B_body_param = std::make_shared<ov::op::v0::Parameter>(squeezed_b->get_element_type(),
squeezed_b->get_output_partial_shape(0));
diff --git a/src/common/transformations/src/transformations/utils/utils.cpp b/src/common/transformations/src/transformations/utils/utils.cpp
index 253d63144d2..95ad0daebdb 100644
--- a/src/common/transformations/src/transformations/utils/utils.cpp
+++ b/src/common/transformations/src/transformations/utils/utils.cpp
@@ -22,7 +22,6 @@
#include "openvino/op/multiply.hpp"
#include "openvino/op/paged_attention.hpp"
#include "openvino/op/parameter.hpp"
-#include "openvino/op/random_uniform.hpp"
#include "openvino/op/read_value.hpp"
#include "openvino/op/relu.hpp"
#include "openvino/op/reshape.hpp"
@@ -499,43 +498,6 @@ bool is_constant_and_all_values_equal_int(const Output<Node>& output, const int6
return false;
}
-bool is_on_constant_path(const ov::Output<ov::Node>& output) {
- auto status = true;
-
- auto root_node = output.get_node();
- if (!root_node || root_node->get_output_size() == 0) {
- return false;
- }
- std::deque<ov::Node*> nodes_to_calculate = {root_node};
-
- std::unordered_set<ov::Node*> visited;
- while (status && !nodes_to_calculate.empty()) {
- auto current_node = nodes_to_calculate.front();
- nodes_to_calculate.pop_front();
- if (visited.count(current_node)) {
- continue;
- }
- visited.insert(current_node);
- // RandomUniform output changes during runtime, so we should not consider it as a constant
- if (current_node->get_type_info() == ov::op::v8::RandomUniform::get_type_info_static()) {
- return false;
- }
-
- if (current_node->get_input_size() == 0 && !ov::is_type<ov::op::v0::Constant>(current_node)) {
- status = false;
- } else {
- // not a leaf - continue to search
- for (const auto& input_value : current_node->input_values()) {
- const auto& input_node = input_value.get_node();
- if (!visited.count(input_node)) {
- nodes_to_calculate.push_front(input_node);
- }
- }
- }
- }
- return status;
-}
-
bool process_subgraph(ov::pass::ModelPass& model_pass, const std::shared_ptr<Node>& node) {
bool changed = false;
diff --git a/src/core/tests/pattern.cpp b/src/core/tests/pattern.cpp
index fb4d031b720..c8817e122ac 100644
--- a/src/core/tests/pattern.cpp
+++ b/src/core/tests/pattern.cpp
@@ -469,7 +469,7 @@ TEST(pattern, optional_match_node_with_single_input) {
TestMatcher matcher;
// is_on_const_path
auto param_predicate = [](const Output<Node>& output) {
- return !ov::op::util::is_on_constant_path(output);
+ return !ov::op::util::is_on_path<ov::op::v0::Constant>(output);
};
auto pattern_in_0 = ov::pass::pattern::any_input();
diff --git a/src/inference/src/dev/performance_heuristics.cpp b/src/inference/src/dev/performance_heuristics.cpp
index c49f1a5fdac..1af4e4e8130 100644
--- a/src/inference/src/dev/performance_heuristics.cpp
+++ b/src/inference/src/dev/performance_heuristics.cpp
@@ -62,7 +62,7 @@ MemBandwidthPressure mem_bandwidth_pressure_tolerance(const std::shared_ptr<ov::
output.get_partial_shape().is_static()) {
const auto& shapeInput0 = input0.get_shape();
const auto& shapeInput1 = input1.get_shape();
- const auto non_const = !ov::op::util::is_on_constant_path(node->input_value(1));
+ const auto non_const = !ov::op::util::is_on_path<ov::op::v0::Constant>(node->input_value(1));
const auto& shapeOutput = output.get_shape();
const auto dataSizeInput0 =
std::accumulate(shapeInput0.begin(), shapeInput0.end(), size_t(1), std::multiplies<size_t>());
diff --git a/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp b/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp
index 479378a1c5b..77c1ea42730 100644
--- a/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp
+++ b/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp
@@ -40,6 +40,7 @@
#include "openvino/core/node.hpp"
#include "openvino/core/type.hpp"
#include "openvino/core/type/element_type.hpp"
+#include "openvino/op/constant.hpp"
#include "openvino/runtime/threading/cpu_message.hpp"
#include "ov_ops/fully_connected.hpp"
#include "ov_ops/fully_connected_compressed.hpp"
@@ -111,15 +112,15 @@ bool FullyConnected::isSupportedOperation(const std::shared_ptr<const ov::Node>&
}
if (ov::is_type<const ov::op::internal::FullyConnected>(op)) {
- if (!ov::op::util::is_on_constant_path(op->input_value(BIAS))) {
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(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))) {
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(WEIGHT_SCALES)) ||
+ !ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(WEIGHT_ZERO_POINTS))) {
errorMessage =
"Only Constant operation on 'weight scales', and 'weight zero points' inputs is supported";
return false;
diff --git a/src/plugins/intel_cpu/src/nodes/gathermatmul.cpp b/src/plugins/intel_cpu/src/nodes/gathermatmul.cpp
index 4a43bfc27bd..101b7e8d3d9 100644
--- a/src/plugins/intel_cpu/src/nodes/gathermatmul.cpp
+++ b/src/plugins/intel_cpu/src/nodes/gathermatmul.cpp
@@ -41,6 +41,7 @@
#include "openvino/core/parallel.hpp"
#include "openvino/core/type.hpp"
#include "openvino/core/type/element_type.hpp"
+#include "openvino/op/constant.hpp"
#include "shape_inference/custom/gathermatmul.hpp"
#include "transformations/cpu_opset/common/op/batch_gather_matmul.hpp"
#include "transformations/cpu_opset/common/op/batch_gather_matmul_compressed.hpp"
@@ -253,7 +254,7 @@ bool GatherMatmul::isSupportedOperation(const std::shared_ptr<const ov::Node>& o
}
// Check that weights input (port 1) is constant
- if (!ov::op::util::is_on_constant_path(op->input_value(WEIGHTS))) {
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(WEIGHTS))) {
errorMessage = "Only constant weights are supported for GatherMatmul operation";
return false;
}
@@ -261,14 +262,14 @@ bool GatherMatmul::isSupportedOperation(const std::shared_ptr<const ov::Node>& o
// For compressed variant, check that scales and zero points are constant
if (isBatchGatherMatmulCompressed) {
if (op->get_input_size() > WEIGHT_SCALES) {
- if (!ov::op::util::is_on_constant_path(op->input_value(WEIGHT_SCALES))) {
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(WEIGHT_SCALES))) {
errorMessage = "Only constant weight scales are supported for GatherMatmul operation";
return false;
}
}
if (op->get_input_size() > WEIGHT_ZERO_POINTS) {
- if (!ov::op::util::is_on_constant_path(op->input_value(WEIGHT_ZERO_POINTS))) {
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(WEIGHT_ZERO_POINTS))) {
errorMessage = "Only constant weight zero points are supported for GatherMatmul operation";
return false;
}
@@ -280,7 +281,7 @@ bool GatherMatmul::isSupportedOperation(const std::shared_ptr<const ov::Node>& o
const auto& biasInput = op->input_value(BIAS);
// Skip validation if bias is dynamic (empty constant)
if (biasInput.get_element_type() != ov::element::dynamic) {
- if (!ov::op::util::is_on_constant_path(biasInput)) {
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(biasInput)) {
errorMessage = "Only constant bias is supported for GatherMatmul operation";
return false;
}
diff --git a/src/plugins/intel_cpu/src/nodes/rnn.cpp b/src/plugins/intel_cpu/src/nodes/rnn.cpp
index 410c98b5499..4621738f329 100644
--- a/src/plugins/intel_cpu/src/nodes/rnn.cpp
+++ b/src/plugins/intel_cpu/src/nodes/rnn.cpp
@@ -43,6 +43,7 @@
#include "openvino/core/type.hpp"
#include "openvino/core/type/element_type.hpp"
#include "openvino/core/type/element_type_traits.hpp"
+#include "openvino/op/constant.hpp"
#include "openvino/op/gru_cell.hpp"
#include "openvino/op/gru_sequence.hpp"
#include "openvino/op/lstm_cell.hpp"
@@ -274,9 +275,9 @@ bool RNN::isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::s
ov::op::v0::RNNCell::get_type_info_static(),
ov::op::v3::GRUCell::get_type_info_static())) {
// Plug-in does not support dynamism on weights.
- if (!ov::op::util::is_on_constant_path(op->input_value(2)) ||
- !ov::op::util::is_on_constant_path(op->input_value(3)) ||
- (op->get_input_size() > 4 && !ov::op::util::is_on_constant_path(op->input_value(4)))) {
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(2)) ||
+ !ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(3)) ||
+ (op->get_input_size() > 4 && !ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(4)))) {
errorMessage = "Node expects constants as W, R, B inputs.";
return false;
}
@@ -286,9 +287,9 @@ bool RNN::isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::s
ov::op::v5::GRUSequence::get_type_info_static(),
ov::op::v5::RNNSequence::get_type_info_static())) {
// Plug-in does not support dynamism on weights.
- if (!ov::op::util::is_on_constant_path(op->input_value(3)) ||
- !ov::op::util::is_on_constant_path(op->input_value(4)) ||
- (op->get_input_size() > 5 && !ov::op::util::is_on_constant_path(op->input_value(5)))) {
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(3)) ||
+ !ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(4)) ||
+ (op->get_input_size() > 5 && !ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(5)))) {
errorMessage = "Node expects constants as W, R, B inputs.";
return false;
}
@@ -302,9 +303,9 @@ bool RNN::isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::s
return false;
}
// Plug-in does not support dynamism on weights.
- if (!ov::op::util::is_on_constant_path(op->input_value(4)) ||
- !ov::op::util::is_on_constant_path(op->input_value(5)) ||
- !ov::op::util::is_on_constant_path(op->input_value(6))) {
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(4)) ||
+ !ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(5)) ||
+ !ov::op::util::is_on_path<ov::op::v0::Constant>(op->input_value(6))) {
errorMessage = "Node expects static shaped W, R, B inputs.";
return false;
}
diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/batch_gather_matmul.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/batch_gather_matmul.cpp
index 237cbf3d2f9..200e292824c 100644
--- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/batch_gather_matmul.cpp
+++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/batch_gather_matmul.cpp
@@ -54,7 +54,9 @@ void BatchGatherMatmul::validate_and_infer_types() {
", expected at least 4.");
// Check input B is on constant path
- NODE_VALIDATION_CHECK(this, ov::op::util::is_on_constant_path(input_value(1)), "Input B must be on constant path.");
+ NODE_VALIDATION_CHECK(this,
+ ov::op::util::is_on_path<ov::op::v0::Constant>(input_value(1)),
+ "Input B must be on constant path.");
const auto& a_shape = get_input_partial_shape(0);
const auto& b_shape = get_input_partial_shape(1);
diff --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.cpp
index 0ad15dcce13..a3d52173746 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
@@ -48,7 +48,7 @@ ov::intel_cpu::ConvertMatMulToFC::ConvertMatMulToFC() {
MATCHER_SCOPE(ConvertMatMulToFC);
auto activations_m = ov::pass::pattern::any_input(ov::pass::pattern::has_static_rank());
auto weights_path = [](const ov::Output<ov::Node>& output) {
- return ov::op::util::is_on_constant_path(output);
+ return ov::op::util::is_on_path<ov::op::v0::Constant>(output);
};
auto weights_m = ov::pass::pattern::any_input(weights_path);
auto matmul_m = ov::pass::pattern::wrap_type<ov::op::v0::MatMul>({activations_m, weights_m},
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/snippets_mark_skipped.cpp b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/snippets_mark_skipped.cpp
index fba1d3ec6c0..85b1678f3f0 100644
--- a/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/snippets_mark_skipped.cpp
+++ b/src/plugins/intel_cpu/src/transformations/snippets/aarch64/pass/snippets_mark_skipped.cpp
@@ -97,7 +97,7 @@ bool isFullyConnected(const std::shared_ptr<const ov::Node>& node) {
const auto rank_w = out_weights.get_partial_shape().rank();
return out_weights.get_partial_shape().is_static() && rank_a.is_static() && rank_w.is_static() &&
rank_a.get_length() != 1 && rank_w.get_length() != 1 && rank_w.get_length() <= 3 &&
- ov::op::util::is_on_constant_path(out_weights);
+ ov::op::util::is_on_path<ov::op::v0::Constant>(out_weights);
}
bool SupportsFusingWithConvolution_Simple(const std::shared_ptr<const Node>& node) {
@@ -171,7 +171,8 @@ bool isSuitableChildForFusingBias(const std::shared_ptr<const Node>& node, int f
}
const auto bias_port = 1 - in.get_index();
const auto bias_out = node->input_value(bias_port);
- if ((bias_out.get_target_inputs().size() > 1) || !ov::op::util::is_on_constant_path(bias_out)) {
+ if ((bias_out.get_target_inputs().size() > 1) ||
+ !ov::op::util::is_on_path<ov::op::v0::Constant>(bias_out)) {
break;
}
const auto& bias_pshape = bias_out.get_partial_shape();
@@ -255,7 +256,7 @@ auto is_skipped_op(const std::shared_ptr<ov::Node>& op) -> bool {
bool isSuitableMatMulWithConstantPath(const std::shared_ptr<Node>& node) {
return ov::is_type<ov::op::v0::MatMul>(node) &&
!ov::is_type<ov::op::v0::Constant>(node->get_input_node_shared_ptr(1)) &&
- ov::op::util::is_on_constant_path(node->input_value(1));
+ ov::op::util::is_on_path<ov::op::v0::Constant>(node->input_value(1));
}
} // namespace
diff --git a/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/snippets_mark_skipped.cpp b/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/snippets_mark_skipped.cpp
index 604fcdfb4fe..fd1206a8f01 100644
--- a/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/snippets_mark_skipped.cpp
+++ b/src/plugins/intel_cpu/src/transformations/snippets/x64/pass/snippets_mark_skipped.cpp
@@ -116,7 +116,7 @@ bool isFullyConnected(const std::shared_ptr<const ov::Node>& node) {
const auto rank_w = out_weights.get_partial_shape().rank();
return out_weights.get_partial_shape().is_static() && rank_a.is_static() && rank_w.is_static() &&
rank_a.get_length() != 1 && rank_w.get_length() != 1 && rank_a.get_length() <= 3 &&
- rank_w.get_length() <= 3 && ov::op::util::is_on_constant_path(out_weights);
+ rank_w.get_length() <= 3 && ov::op::util::is_on_path<ov::op::v0::Constant>(out_weights);
}
bool SupportsFusingWithConvolution_SumActivation(const std::shared_ptr<const Node>& node) {
// todo: Do all PReLUs are fused? Not sure about round and softRelu
@@ -344,7 +344,8 @@ bool isSuitableChildForFusingMatMul(const std::shared_ptr<const Node>& node,
}
const auto bias_port = 1 - in.get_index();
const auto bias_out = node->input_value(bias_port);
- if ((bias_out.get_target_inputs().size() > 1) || !ov::op::util::is_on_constant_path(bias_out)) {
+ if ((bias_out.get_target_inputs().size() > 1) ||
+ !ov::op::util::is_on_path<ov::op::v0::Constant>(bias_out)) {
break;
}
const auto& bias_pshape = bias_out.get_partial_shape();
@@ -415,14 +416,14 @@ bool isSuitableChildForFusingMatMul(const std::shared_ptr<const Node>& node,
size_t num_non_const_inputs = 0;
size_t num_mm_inputs = 0;
for (const auto& parent_out : node->input_values()) {
- // To avoid endless check `is_on_constant_path` for MatMul branch
+ // To avoid endless check `is_on_path<ov::op::v0::Constant>` for MatMul branch
if (any_of(GetNodeFusingType(parent_out.get_node_shared_ptr()),
NodeFusingType::FusedWithMatMul,
NodeFusingType::FusedWithMatMulI8,
NodeFusingType::FusedWithFC,
NodeFusingType::FusedWithFCI8)) {
num_mm_inputs++;
- } else if (!ov::op::util::is_on_constant_path(parent_out)) {
+ } else if (!ov::op::util::is_on_path<ov::op::v0::Constant>(parent_out)) {
num_non_const_inputs++;
}
}
@@ -505,7 +506,7 @@ bool isSuitableGatherChild(const std::shared_ptr<const Node>& node) {
bool isSuitableMatMulWithConstantPath(const std::shared_ptr<Node>& node) {
return ov::is_type<ov::op::v0::MatMul>(node) &&
!ov::is_type<ov::op::v0::Constant>(node->get_input_node_shared_ptr(1)) &&
- ov::op::util::is_on_constant_path(node->input_value(1));
+ ov::op::util::is_on_path<ov::op::v0::Constant>(node->input_value(1));
}
// Continue fusing chain of the passed type if the node has one child
// Otherwise mark node as FusedTerminator (Fused, but fusing chain is interrupted)
diff --git a/src/plugins/intel_cpu/src/transformations/utils.cpp b/src/plugins/intel_cpu/src/transformations/utils.cpp
index 60d3a8b684c..c3eaf749e98 100644
--- a/src/plugins/intel_cpu/src/transformations/utils.cpp
+++ b/src/plugins/intel_cpu/src/transformations/utils.cpp
@@ -10,6 +10,7 @@
#include "openvino/core/model.hpp"
#include "openvino/core/node.hpp"
#include "openvino/core/type.hpp"
+#include "openvino/op/constant.hpp"
#include "openvino/op/matmul.hpp"
#include "openvino/op/multiply.hpp"
#include "ov_ops/fully_connected.hpp"
@@ -38,7 +39,7 @@ bool has_matmul_with_compressed_weights(const std::shared_ptr<const ov::Model>&
}
auto weights = op->input_value(1);
- if (!ov::op::util::is_on_constant_path(weights)) {
+ if (!ov::op::util::is_on_path<ov::op::v0::Constant>(weights)) {
continue;
}
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp b/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp
index 05660f291c7..e58cbe725cb 100644
--- a/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp
+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp
@@ -67,8 +67,9 @@ struct FullyConnectedImplementationManager : public ImplementationManager {
if (fc_prim->decompression_zero_point.is_valid()) {
auto decompression_zp_idx = fc_prim->bias.is_valid() ? 4 : 3;
auto decompression_zp_dt = fc_node.get_input_layout(decompression_zp_idx).data_type;
- if ((wei_dt != ov::element::Type_t::u4 && wei_dt != ov::element::Type_t::u8) ||
- (decompression_zp_dt != ov::element::Type_t::u8 && decompression_zp_dt != ov::element::Type_t::i8)) {
+ if ((wei_dt != ov::element::Type_t::i4 && wei_dt != ov::element::Type_t::u4 && wei_dt != ov::element::Type_t::u8) ||
+ (decompression_zp_dt != ov::element::Type_t::i4 && decompression_zp_dt != ov::element::Type_t::u8 &&
+ decompression_zp_dt != ov::element::Type_t::i8)) {
LOG_AND_RETURN_FALSE(node);
}
}
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/convert_matmul_to_fc.cpp b/src/plugins/intel_gpu/src/plugin/transformations/convert_matmul_to_fc.cpp
index eaaa1ee4f5c..6ccfb87d91c 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations/convert_matmul_to_fc.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations/convert_matmul_to_fc.cpp
@@ -28,7 +28,7 @@ ConvertMatMulToFullyConnected::ConvertMatMulToFullyConnected(bool supports_immad
};
auto weights_path = [&static_rank_gt_1](const ov::Output<ov::Node>& output) {
const auto& pshape = output.get_partial_shape();
- return ov::op::util::is_on_constant_path(output) &&
+ return ov::op::util::is_on_path<ov::op::v0::Constant>(output) &&
static_rank_gt_1(output) &&
pshape.is_static();
};
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/convert_weight_compressed_conv1x1_to_matmul.cpp b/src/plugins/intel_gpu/src/plugin/transformations/convert_weight_compressed_conv1x1_to_matmul.cpp
new file mode 100644
index 00000000000..99630f6730a
--- /dev/null
+++ b/src/plugins/intel_gpu/src/plugin/transformations/convert_weight_compressed_conv1x1_to_matmul.cpp
@@ -0,0 +1,239 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "convert_weight_compressed_conv1x1_to_matmul.hpp"
+
+#include <iostream>
+#include <ostream>
+#include <vector>
+
+#include "graph/include/gemm_inst.h"
+#include "intel_gpu/runtime/utils.hpp"
+#include "openvino/core/graph_util.hpp"
+#include "openvino/core/node_vector.hpp"
+#include "openvino/core/partial_shape.hpp"
+#include "openvino/core/rt_info.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "openvino/op/add.hpp"
+#include "openvino/op/convolution.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/convert.hpp"
+#include "openvino/op/matmul.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/any.hpp"
+#include "openvino/pass/pattern/op/label.hpp"
+#include "openvino/pass/pattern/op/or.hpp"
+#include "openvino/pass/pattern/op/pattern.hpp"
+#include "openvino/pass/pattern/op/wrap_type.hpp"
+#include "transformations/utils/utils.hpp"
+
+using namespace ov::pass::pattern;
+using ov::pass::pattern::op::Or;
+
+namespace ov::intel_gpu {
+
+ConvertWeightCompressedConv1x1ToMatmul::ConvertWeightCompressedConv1x1ToMatmul(bool supports_immad) {
+ add_matcher<ConvertWeightCompressedConv1x1ToMatmulMatcher>(supports_immad);
+}
+
+ConvertWeightCompressedConv1x1ToMatmulMatcher::ConvertWeightCompressedConv1x1ToMatmulMatcher(bool supports_immad) {
+ auto filter1x1_path = [](const ov::Output<ov::Node>& output) {
+ const auto& pshape = output.get_partial_shape();
+ return ov::op::util::is_on_path<ov::op::v0::Constant, ov::op::v0::Parameter>(output) && pshape.is_static() && pshape[-1] == 1 && pshape[-2] == 1;
+ };
+
+ auto bias_path = [](const ov::Output<ov::Node>& output) {
+ const auto& pshape = output.get_partial_shape();
+ return ov::op::util::is_on_path<ov::op::v0::Constant>(output) && pshape.is_static() && pshape[0] == 1 && pshape[2] == 1 && pshape[3] == 1;
+ };
+
+ auto first_input_m = ov::pass::pattern::any_input();
+ auto a_order_m = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();
+ auto transpose_activations_m = ov::pass::pattern::wrap_type<ov::op::v1::Transpose>({first_input_m, a_order_m});
+ auto reshape_activations_m = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>({first_input_m, a_order_m});
+ auto a_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{transpose_activations_m, reshape_activations_m});
+
+ auto weights_const_m = wrap_type<ov::op::v0::Constant>(rank_equals(4) && has_static_rank() && filter1x1_path);
+ auto weights_param_m = wrap_type<ov::op::v0::Parameter>(rank_equals(4) && has_static_rank() && filter1x1_path);
+ auto weights_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{weights_const_m, weights_param_m});
+ auto weight_convert_m = ov::pass::pattern::wrap_type<ov::op::v0::Convert>({weights_m});
+ auto weights_scales_m = ov::pass::pattern::any_input();
+ auto weights_zp_m = ov::pass::pattern::any_input();
+ auto weights_zp_convert_m = ov::pass::pattern::wrap_type<ov::op::v0::Convert>({weights_zp_m});
+ auto weight_subtract_m = ov::pass::pattern::wrap_type<ov::op::v1::Subtract>({weight_convert_m, weights_zp_convert_m});
+ // Make zp subtraction optional to account for symmetrical quantization cases
+ auto weight_dequantized_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{weight_convert_m, weight_subtract_m});
+ auto weight_mult_m = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({weight_dequantized_m, weights_scales_m});
+ auto conv1x1_m = ov::pass::pattern::wrap_type<ov::op::v1::Convolution>({a_m, weight_mult_m});
+
+ // Optional bias
+ auto bias_const_m = wrap_type<ov::op::v0::Constant>(rank_equals(4) && has_static_rank() && bias_path);
+ auto bias_m = ov::pass::pattern::wrap_type<ov::op::v1::Add>({conv1x1_m, bias_const_m});
+ auto bias_out_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{conv1x1_m, bias_m});
+
+ auto convert_m = ov::pass::pattern::wrap_type<ov::op::v0::Convert>({bias_out_m});
+ auto conv_out_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{bias_out_m, convert_m});
+
+ auto c_order_m = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();
+ auto transpose_output_m = ov::pass::pattern::wrap_type<ov::op::v1::Transpose>({conv_out_m, c_order_m});
+ auto reshape_output_m = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>({conv_out_m, c_order_m});
+ auto output_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{transpose_output_m, reshape_output_m});
+
+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {
+ const auto& pattern_map = m.get_pattern_value_map();
+
+ auto conv1x1 = ov::as_type_ptr<ov::op::v1::Convolution>(pattern_map.at(conv1x1_m).get_node_shared_ptr());
+ auto weight_convert = ov::as_type_ptr<ov::op::v0::Convert>(pattern_map.at(weight_convert_m).get_node_shared_ptr());
+ auto weight_sub = (pattern_map.count(weight_subtract_m) > 0) ? pattern_map.at(weight_subtract_m).get_node_shared_ptr() : nullptr;
+ auto weight_mult = ov::as_type_ptr<ov::op::v1::Multiply>(pattern_map.at(weight_mult_m).get_node_shared_ptr());
+ auto bias_out = (pattern_map.count(bias_m) > 0) ? pattern_map.at(bias_m).get_node_shared_ptr() : nullptr;
+ auto bias_const = (pattern_map.count(bias_const_m) > 0) ? pattern_map.at(bias_const_m).get_node_shared_ptr() : nullptr;
+ auto convert_out = (pattern_map.count(convert_m) > 0) ? pattern_map.at(convert_m).get_node_shared_ptr() : nullptr;
+ auto out_order = (pattern_map.count(c_order_m) > 0) ? pattern_map.at(c_order_m).get_node_shared_ptr() : nullptr;
+ auto reshape_out = (pattern_map.count(reshape_output_m) > 0) ? pattern_map.at(reshape_output_m).get_node_shared_ptr() : nullptr;
+ if (!conv1x1 || transformation_callback(conv1x1)) {
+ return false;
+ }
+
+ auto weight = pattern_map.at(weights_m).get_node_shared_ptr();
+ auto scale = pattern_map.at(weights_scales_m).get_node_shared_ptr();
+ auto zp = (pattern_map.count(weights_zp_m) > 0) ? pattern_map.at(weights_zp_m).get_node_shared_ptr() : nullptr;
+ auto activation = pattern_map.at(first_input_m).get_node_shared_ptr();
+
+ auto reshape_const_to_2d = [](std::shared_ptr<ov::Node> node) {
+ auto constant = ov::as_type_ptr<ov::op::v0::Constant>(node);
+ OPENVINO_ASSERT(constant != nullptr);
+ ov::Shape current_shape = constant->get_shape();
+ if (current_shape.size() == 2)
+ return constant;
+
+ if (current_shape.size() <= 1) {
+ auto new_shape = ov::Shape{(current_shape.size() == 1) ? current_shape[0] : 1, 1};
+
+ auto new_constant = std::make_shared<ov::op::v0::Constant>(*constant, new_shape);
+
+ ov::copy_weightless_cache_attr(constant, new_constant);
+ return new_constant;
+ } else {
+ OPENVINO_ASSERT(current_shape.size() == 4);
+ OPENVINO_ASSERT(current_shape[2] == 1 && current_shape[3] == 1);
+
+ auto new_shape = ov::Shape{current_shape[0], current_shape[1]};
+
+ auto new_constant = std::make_shared<ov::op::v0::Constant>(*constant, new_shape);
+
+ ov::copy_weightless_cache_attr(constant, new_constant);
+ return new_constant;
+ }
+ };
+
+ // add reshape after weight
+ std::shared_ptr<ov::op::v0::Convert> weight_squeezed_convert;
+ if (ov::as_type_ptr<ov::op::v0::Constant>(weight)) {
+ auto Reshape_weight = reshape_const_to_2d(weight);
+ MatcherPass::register_new_node(Reshape_weight);
+ Reshape_weight->set_friendly_name(weight->get_friendly_name() + "_Reshape_weight");
+ weight_squeezed_convert = ov::as_type_ptr<ov::op::v0::Convert>(weight_convert->clone_with_new_inputs({Reshape_weight}));
+ ov::copy_runtime_info(weight_convert, weight_squeezed_convert);
+ } else {
+ auto param = ov::as_type_ptr<ov::op::v0::Parameter>(weight);
+ OPENVINO_ASSERT(param != nullptr);
+ std::vector<int> values_reshape_b;
+ auto shape_b = param->get_output_partial_shape(0);
+ for (size_t i = 0; i < shape_b.size(); i++)
+ if (shape_b.to_shape()[i] != 1) {
+ values_reshape_b.push_back(shape_b.to_shape()[i]);
+ }
+
+ auto reshape_weight_const = ov::op::v0::Constant::create(element::i32, Shape{2}, values_reshape_b);
+ auto Reshape_weight = std::make_shared<ov::op::v1::Reshape>(param, reshape_weight_const, false);
+ MatcherPass::register_new_node(Reshape_weight);
+ Reshape_weight->set_friendly_name(param->get_friendly_name() + "_Reshape_weight");
+ weight_squeezed_convert = ov::as_type_ptr<ov::op::v0::Convert>(weight_convert->clone_with_new_inputs({Reshape_weight}));
+ ov::copy_runtime_info(weight_convert, weight_squeezed_convert);
+ }
+ ov::disable_constant_folding(weight_squeezed_convert);
+
+ // add reshape after scales
+ auto Reshape_scale = reshape_const_to_2d(scale);
+ MatcherPass::register_new_node(Reshape_scale);
+ Reshape_scale->set_friendly_name(scale->get_friendly_name() + "_Reshape_scale");
+ ov::copy_runtime_info(scale, Reshape_scale);
+
+ auto scaled_weight = weight_mult->clone_with_new_inputs({weight_squeezed_convert, Reshape_scale});
+ if (zp) {
+ // add reshape after zero points
+ auto Reshape_zp = reshape_const_to_2d(zp);
+ MatcherPass::register_new_node(Reshape_zp);
+ Reshape_zp->set_friendly_name(zp->get_friendly_name() + "_Reshape_zp");
+ auto weights_zp_convert = ov::as_type_ptr<ov::op::v0::Convert>(pattern_map.at(weights_zp_convert_m).get_node_shared_ptr());
+ auto zp_squeezed_convert = weights_zp_convert->clone_with_new_inputs({Reshape_zp});
+ ov::copy_runtime_info(weights_zp_convert, zp_squeezed_convert);
+ ov::disable_constant_folding(zp_squeezed_convert);
+ auto zero_adjusted_weight = weight_sub->clone_with_new_inputs({weight_squeezed_convert, zp_squeezed_convert});
+ ov::copy_runtime_info(weight_sub, zero_adjusted_weight);
+ scaled_weight = weight_mult->clone_with_new_inputs({zero_adjusted_weight, Reshape_scale});
+ }
+ ov::copy_runtime_info(weight_mult, scaled_weight);
+ ov::disable_constant_folding(scaled_weight);
+
+ auto matmul = std::make_shared<ov::op::v0::MatMul>(activation, scaled_weight, false, true);
+ std::shared_ptr<Node> matmul_out;
+ if (bias_out) {
+ auto bias = ov::as_type_ptr<ov::op::v0::Constant>(bias_const);
+ OPENVINO_ASSERT(bias != nullptr);
+
+ ov::Shape bias_shape = bias->get_shape();
+ OPENVINO_ASSERT(bias_shape.size() == 4);
+
+ auto new_bias_shape = ov::Shape{bias_shape[0], bias_shape[2], bias_shape[3], bias_shape[1]};
+
+ auto Reshape_bias = std::make_shared<ov::op::v0::Constant>(*bias, new_bias_shape);
+
+ ov::copy_weightless_cache_attr(bias, Reshape_bias);
+ MatcherPass::register_new_node(Reshape_bias);
+ Reshape_bias->set_friendly_name(bias->get_friendly_name() + "_Reshape_bias");
+
+ matmul_out = bias_out->clone_with_new_inputs({matmul, Reshape_bias});
+ } else {
+ matmul_out = matmul;
+ }
+
+ if (reshape_out) {
+ if (convert_out) {
+ auto convert_final = convert_out->clone_with_new_inputs({matmul_out});
+ auto reshape_final = reshape_out->clone_with_new_inputs({convert_final, out_order});
+ reshape_final->set_friendly_name(m.get_match_root()->get_friendly_name());
+ ov::copy_runtime_info(m.get_matched_nodes(), reshape_final);
+ ov::replace_node(m.get_match_root(), reshape_final);
+ } else {
+ auto reshape_final = reshape_out->clone_with_new_inputs({matmul_out, out_order});
+ reshape_final->set_friendly_name(m.get_match_root()->get_friendly_name());
+ ov::copy_runtime_info(m.get_matched_nodes(), reshape_final);
+ ov::replace_node(m.get_match_root(), reshape_final);
+ }
+ } else {
+ if (convert_out) {
+ auto convert_final = convert_out->clone_with_new_inputs({matmul_out});
+ convert_final->set_friendly_name(m.get_match_root()->get_friendly_name());
+ ov::copy_runtime_info(m.get_matched_nodes(), convert_final);
+ ov::replace_node(m.get_match_root(), convert_final);
+ } else {
+ matmul_out->set_friendly_name(m.get_match_root()->get_friendly_name());
+ ov::copy_runtime_info(m.get_matched_nodes(), matmul_out);
+ ov::replace_node(m.get_match_root(), matmul_out);
+ }
+ }
+
+ return true;
+ };
+
+ auto m = std::make_shared<ov::pass::pattern::Matcher>(output_m, "ConvertWeightCompressedConv1x1ToMatmulMatcher");
+ this->register_matcher(m, callback);
+}
+
+} // namespace ov::intel_gpu
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/convert_weight_compressed_conv1x1_to_matmul.hpp b/src/plugins/intel_gpu/src/plugin/transformations/convert_weight_compressed_conv1x1_to_matmul.hpp
new file mode 100644
index 00000000000..f7d8a2d75c8
--- /dev/null
+++ b/src/plugins/intel_gpu/src/plugin/transformations/convert_weight_compressed_conv1x1_to_matmul.hpp
@@ -0,0 +1,23 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "openvino/pass/graph_rewrite.hpp"
+
+namespace ov::intel_gpu {
+
+class ConvertWeightCompressedConv1x1ToMatmul : public ov::pass::GraphRewrite {
+public:
+ OPENVINO_GRAPH_REWRITE_RTTI("ConvertWeightCompressedConv1x1ToMatmul");
+ ConvertWeightCompressedConv1x1ToMatmul(bool supports_immad = false);
+};
+
+class ConvertWeightCompressedConv1x1ToMatmulMatcher : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("ConvertWeightCompressedConv1x1ToMatmulMatcher");
+ ConvertWeightCompressedConv1x1ToMatmulMatcher(bool supports_immad);
+};
+
+} // namespace ov::intel_gpu
diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
index 797d35cbd91..7f2327f611f 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
@@ -77,6 +77,7 @@
#include "plugin/transformations/convert_matmul_to_fc.hpp"
#include "plugin/transformations/convert_moe_to_compressed.hpp"
#include "plugin/transformations/convert_stridedslices_to_variadicsplit.hpp"
+#include "plugin/transformations/convert_weight_compressed_conv1x1_to_matmul.hpp"
#include "plugin/transformations/decompose_reduce_scalar_output.hpp"
#include "plugin/transformations/dynamic_quantize_fully_connected.hpp"
#include "plugin/transformations/fc_convert_fusion.hpp"
@@ -1312,6 +1313,7 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
ov::pass::Manager manager("GPU:PostLPT");
manager.set_per_pass_validation(false);
+ manager.register_pass<ov::intel_gpu::ConvertWeightCompressedConv1x1ToMatmul>();
manager.register_pass<ov::intel_gpu::ClampFP16Output>();
manager.register_pass<ov::intel_gpu::ConvertMatMulToFullyConnected>(device_info.supports_immad);
manager.register_pass<ov::intel_gpu::MoveFCReshapeToWeights>();
diff --git a/src/plugins/intel_gpu/tests/unit/transformations/convert_weight_compressed_conv1x1_to_matmul_test.cpp b/src/plugins/intel_gpu/tests/unit/transformations/convert_weight_compressed_conv1x1_to_matmul_test.cpp
new file mode 100644
index 00000000000..aedfea3e12b
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/unit/transformations/convert_weight_compressed_conv1x1_to_matmul_test.cpp
@@ -0,0 +1,104 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <gtest/gtest.h>
+
+#include <intel_gpu/op/placeholder.hpp>
+#include <memory>
+#include <openvino/core/model.hpp>
+#include <openvino/pass/manager.hpp>
+#include <ov_ops/type_relaxed.hpp>
+#include <plugin/transformations/convert_weight_compressed_conv1x1_to_matmul.hpp>
+#include <string>
+#include <transformations/init_node_info.hpp>
+#include <transformations/utils/utils.hpp>
+
+#include "common_test_utils/ov_test_utils.hpp"
+#include "openvino/op/concat.hpp"
+#include "openvino/op/convolution.hpp"
+#include "openvino/op/matmul.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/shape_of.hpp"
+#include "openvino/op/subtract.hpp"
+#include "openvino/op/transpose.hpp"
+#include "openvino/opsets/opset1_decl.hpp"
+#include "openvino/opsets/opset3_decl.hpp"
+#include "openvino/opsets/opset7_decl.hpp"
+#include "transformations/rt_info/decompression.hpp"
+
+using namespace testing;
+using namespace ov::intel_gpu;
+
+TEST_F(TransformationTestsF, ConvertWeightCompressedConv1x1ToMatmulTest1) {
+ ov::Strides strides{1, 1};
+ ov::Strides dilations{1, 1};
+ ov::CoordinateDiff pads_begin{0, 0};
+ ov::CoordinateDiff pads_end{0, 0};
+ {
+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::Shape{1, 1, 2, 10});
+ auto transpose_constant1 = ov::opset1::Constant::create(ov::element::i32, ov::Shape{4}, {0, 3, 1, 2});
+ auto transpose_constant2 = ov::opset1::Constant::create(ov::element::i32, ov::Shape{4}, {0, 2, 3, 1});
+ auto input2 = ov::opset1::Constant::create(ov::element::i4, ov::Shape{15, 10, 1, 1}, {1});
+ auto input2_convert = std::make_shared<ov::op::v0::Convert>(input2, ov::element::f16);
+ auto input2_scale = ov::opset1::Constant::create(ov::element::f16, ov::Shape{15, 10, 1, 1}, {1});
+ auto mul = std::make_shared<ov::opset1::Multiply>(input2_convert, input2_scale);
+ auto transpose1 = std::make_shared<ov::opset1::Transpose>(input1, transpose_constant1);
+ auto conv1x1 = std::make_shared<ov::opset1::Convolution>(transpose1, mul, strides, pads_begin, pads_end, dilations, ov::op::PadType::EXPLICIT);
+ auto transpose2 = std::make_shared<ov::opset1::Transpose>(conv1x1, transpose_constant2);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{transpose2}, ov::ParameterVector{input1});
+ manager.register_pass<ConvertWeightCompressedConv1x1ToMatmul>();
+ }
+ {
+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::Shape{1, 1, 2, 10});
+ auto input2 = ov::opset1::Constant::create(ov::element::i4, ov::Shape{15, 10}, {1});
+ auto input2_convert = std::make_shared<ov::op::v0::Convert>(input2, ov::element::f16);
+ auto input2_scale = ov::opset1::Constant::create(ov::element::f16, ov::Shape{15, 10}, {1});
+ auto mul = std::make_shared<ov::opset1::Multiply>(input2_convert, input2_scale);
+ auto matmul = std::make_shared<ov::op::v0::MatMul>(input1, mul, false, true);
+
+ model_ref = std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{input1});
+ }
+}
+
+// Checked blocked cases
+TEST(TransformationTests, ConvertWeightCompressedConv1x1ToMatmulExceptionTest_conv3x3) {
+ auto CreateConv = [&]() {
+ ov::Strides strides{1, 1};
+ ov::Strides dilations{1, 1};
+ ov::CoordinateDiff pads_begin{1, 1};
+ ov::CoordinateDiff pads_end{1, 1};
+ auto input1 = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::Shape{1, 1, 2, 1});
+ auto transpose_constant1 = ov::opset1::Constant::create(ov::element::i32, ov::Shape{4}, {0, 3, 1, 2});
+ auto transpose_constant2 = ov::opset1::Constant::create(ov::element::i32, ov::Shape{4}, {0, 2, 3, 1});
+ auto input2 = ov::opset1::Constant::create(ov::element::i4, ov::Shape{1, 1, 3, 3}, {1});
+ auto input2_convert = std::make_shared<ov::op::v0::Convert>(input2, ov::element::f16);
+ auto input2_scale = ov::opset1::Constant::create(ov::element::f16, ov::Shape{1, 1, 3, 3}, {1});
+ auto mul = std::make_shared<ov::opset1::Multiply>(input2_convert, input2_scale);
+ auto transpose1 = std::make_shared<ov::opset1::Transpose>(input1, transpose_constant1);
+ auto conv3x3 = std::make_shared<ov::opset1::Convolution>(transpose1, mul, strides, pads_begin, pads_end, dilations, ov::op::PadType::EXPLICIT);
+ auto transpose2 = std::make_shared<ov::opset1::Transpose>(conv3x3, transpose_constant2);
+
+ auto model = std::make_shared<ov::Model>(ov::OutputVector{transpose2}, ov::ParameterVector{input1});
+ return model;
+ };
+
+ ov::pass::Manager manager;
+ manager.set_per_pass_validation(false);
+ manager.register_pass<ov::intel_gpu::ConvertWeightCompressedConv1x1ToMatmul>();
+
+ auto func = CreateConv();
+
+ manager.run_passes(func);
+
+ bool success = false;
+ for (auto& ops : func->get_ops()) {
+ std::string type_name(ops->get_type_name());
+ if (type_name.find("MatMul") != std::string::npos) {
+ success = true;
+ break;
+ }
+ }
+ ASSERT_TRUE(success == false);
+}