Skip to content

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

[GPU] Recognize parameters as valid inputs for compressed weights - duplicate PR (#34767)

Bartlomiej Filipek42ac0416bdeb
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/compressed_weights_pattern.hpp b/src/plugins/intel_gpu/src/plugin/transformations/compressed_weights_pattern.hpp
index dac8f239fb9..0a1c1200ea8 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations/compressed_weights_pattern.hpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations/compressed_weights_pattern.hpp
@@ -1,3 +1,7 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
#pragma once
using namespace ov::pass::pattern;
@@ -14,18 +18,25 @@ using namespace ov::pass::pattern;
((in_ps.size() == 3 && out_ps.size() == 2) || (in_ps.size() == 4 && out_ps.size() == 3));\
};\
\
- auto compressed_weights_m = wrap_type<ov::op::v0::Constant>(compressed_constant);\
+ auto weights_const_m = wrap_type<ov::op::v0::Constant>(compressed_constant);\
+ auto weights_param_m = wrap_type<ov::op::v0::Parameter>(compressed_constant);\
+ auto weights_initial_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{weights_const_m, weights_param_m});\
+ auto weights_reshape_m = wrap_type<ov::op::v1::Reshape>({weights_initial_m, any_input()});\
+ auto compressed_weights_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{weights_const_m, weights_param_m, weights_reshape_m});\
auto convert_m = wrap_type<ov::op::v0::Convert>({compressed_weights_m});\
+ auto weights_param_convert_m = wrap_type<ov::op::v0::Convert>({weights_param_m});\
+ auto weights_convert_reshape_m = wrap_type<ov::op::v1::Reshape>({weights_param_convert_m, any_input()});\
+ auto decompressed_weights_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{convert_m, weights_convert_reshape_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 sub_with_convert_m = wrap_type<ov::op::v1::Subtract>({decompressed_weights_m, sub_convert_const_m});\
+ auto sub_no_convert_m = wrap_type<ov::op::v1::Subtract>({decompressed_weights_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_with_sub_m = wrap_type<ov::op::v1::Multiply>({subtract_m, mul_const_m});\
- auto mul_no_sub_m = wrap_type<ov::op::v1::Multiply>({convert_m, mul_const_m});\
+ auto mul_no_sub_m = wrap_type<ov::op::v1::Multiply>({decompressed_weights_m, mul_const_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>();\
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/convert_fc_to_compressed.cpp b/src/plugins/intel_gpu/src/plugin/transformations/convert_fc_to_compressed.cpp
index 244e28b9176..e9d4ca1aeb2 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations/convert_fc_to_compressed.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations/convert_fc_to_compressed.cpp
@@ -40,9 +40,8 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon
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(compressed_weights_m));
+ OPENVINO_ASSERT(pattern_map.count(decompressed_weights_m));
OPENVINO_ASSERT(pattern_map.count(bias_m));
- OPENVINO_ASSERT(pattern_map.count(convert_m));
auto fc = ov::as_type_ptr<op::FullyConnected>(pattern_map.at(fully_connected_m).get_node_shared_ptr());
if (!fc || transformation_callback(fc)) {
return false;
@@ -55,8 +54,9 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon
bool is_weight_3d = (std::count_if(weight_shape.begin(), weight_shape.end(), [](size_t d) { return d > 1; }) == 3);
bool grouped = scale_shape.size() == weight_shape.size() + 1;
- auto weight_ptr = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(compressed_weights_m).get_node_shared_ptr());
bool weight_u8 = false;
+ std::shared_ptr<ov::Node> weight_ptr =
+ pattern_map.count(weights_const_m) ? pattern_map.at(weights_const_m).get_node_shared_ptr() : pattern_map.at(weights_param_m).get_node_shared_ptr();
if (weight_ptr->get_element_type() == ov::element::u8 || weight_ptr->get_element_type() == ov::element::i8)
weight_u8 = true;
@@ -112,12 +112,36 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon
optional_zero_point = convert_const_to_u8(reshape_const(pattern_map.at(sub_const_m).get_node_shared_ptr()));
}
- std::shared_ptr<ov::Node> fc_input_b = reshape_const(pattern_map.at(compressed_weights_m).get_node_shared_ptr());
+ std::shared_ptr<ov::Node> fc_input_b =
+ pattern_map.count(weights_const_m) ? reshape_const(pattern_map.at(weights_const_m).get_node_shared_ptr())
+ : (pattern_map.count(weights_reshape_m) ? pattern_map.at(weights_reshape_m).get_node_shared_ptr()
+ : pattern_map.at(weights_param_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 (fc_input_b->get_output_partial_shape(0).size() != fc_input_scale->get_shape().size()) {
+ OPENVINO_ASSERT(!pattern_map.count(weights_const_m));
+ ov::Shape weight_shape_final(fc_input_scale->get_shape().size(), 1);
+ for (size_t i = weight_shape.size() - 1, idx = fc_input_scale->get_shape().size() - 1; ; --i) {
+ if (weight_shape[i] > 1) {
+ weight_shape_final[idx--] = weight_shape[i];
+ }
+ if (i == 0) {
+ break;
+ }
+ }
+ if (has_transpose) {
+ std::swap(weight_shape_final[0], weight_shape_final[1]);
+ }
+ std::shared_ptr<ov::Node> weight_shape_const =
+ std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{weight_shape_final.size()}, weight_shape_final);
+ fc_input_b = std::make_shared<ov::op::v1::Reshape>(fc_input_b, weight_shape_const, false);
+ result_nodes.push_back(weight_shape_const);
+ result_nodes.push_back(fc_input_b);
+ }
+
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();
@@ -128,16 +152,16 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon
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 });
+ fc_input_b = transpose->clone_with_new_inputs({fc_input_b->output(0), transpose_const});
result_nodes.push_back(fc_input_b);
if (ov::shape_size(scale->output(0).get_shape()) > 1) {
- fc_input_scale = transpose->clone_with_new_inputs({ scale->output(0), transpose_const });
+ fc_input_scale = transpose->clone_with_new_inputs({scale->output(0), transpose_const});
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 });
+ fc_input_zp = transpose->clone_with_new_inputs({optional_zero_point->output(0), transpose_const});
result_nodes.push_back(fc_input_zp);
}
}
@@ -149,18 +173,10 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon
std::shared_ptr<ov::Node> new_fc = nullptr;
if (with_zero_point) {
- new_fc = std::make_shared<op::FullyConnectedCompressed>(fc_input_a,
- fc_input_b,
- fc_input_bias,
- fc_input_scale,
- fc_input_zp,
- fc->get_output_type());
+ new_fc =
+ std::make_shared<op::FullyConnectedCompressed>(fc_input_a, fc_input_b, fc_input_bias, fc_input_scale, fc_input_zp, fc->get_output_type());
} else {
- new_fc = std::make_shared<op::FullyConnectedCompressed>(fc_input_a,
- fc_input_b,
- fc_input_bias,
- fc_input_scale,
- fc->get_output_type());
+ new_fc = std::make_shared<op::FullyConnectedCompressed>(fc_input_a, fc_input_b, fc_input_bias, fc_input_scale, fc->get_output_type());
}
result_nodes.push_back(new_fc);
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 46268af2a49..bad64ce1489 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_path<ov::op::v0::Constant>(output) &&
+ return ov::op::util::is_on_path<ov::op::v0::Constant, ov::op::v0::Parameter>(output) &&
static_rank_gt_1(output) &&
pshape.is_static();
};
diff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/matmul_weights_decompression.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/matmul_weights_decompression.cpp
index 3fb57dd70a5..948fb8a5595 100644
--- a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/matmul_weights_decompression.cpp
+++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/matmul_weights_decompression.cpp
@@ -59,6 +59,7 @@ using MatmulWeightsDecompressionParams = std::tuple<ShapeParams, //
bool, // reshape on decompression constants
bool, // extra multiply
bool, // per-tensor zero-point
+ bool, // parameter weights
uint64_t, // dynamic_quantization_group_size
float // abs_threshold_f16
>;
@@ -75,6 +76,7 @@ public:
reshape_on_decompression,
extra_multiply,
per_tensor_zp,
+ param_weights,
dyn_quan_group_size,
abs_threshold_f16] = obj.param;
@@ -93,11 +95,31 @@ public:
result << "reshape_on_decompression=" << reshape_on_decompression << "_";
result << "extra_multiply=" << extra_multiply << "_";
result << "per_tensor_zp=" << per_tensor_zp << "_";
+ result << "param_weights=" << param_weights << "_";
result << "dyn_quan_group_size=" << dyn_quan_group_size;
return result.str();
}
+ void configure_model() override {
+ ov::preprocess::PrePostProcessor p(function);
+ {
+ if (inType != ov::element::Type_t::dynamic) {
+ p.input(0).tensor().set_element_type(inType);
+ }
+ }
+
+ {
+ auto results = function->get_results();
+ for (size_t i = 0; i < results.size(); i++) {
+ if (outType != ov::element::Type_t::dynamic) {
+ p.output(i).tensor().set_element_type(outType);
+ }
+ }
+ }
+ function = p.build();
+ }
+
protected:
std::shared_ptr<ov::Model> init_subgraph(const ov::PartialShape& data_shape,
const ov::Shape& weights_shape,
@@ -108,9 +130,11 @@ protected:
const bool add_subtract,
const bool reshape_on_decompression,
const bool extra_multiply,
- const bool per_tensor_zp) {
+ const bool per_tensor_zp,
+ const bool param_weight) {
ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(data_precision, data_shape)};
- const auto weights_subgraph = init_compressed_weights_subgraph(weights_shape,
+ const auto weights_subgraph = init_compressed_weights_subgraph(params,
+ weights_shape,
group_size,
data_precision,
weights_precision,
@@ -118,7 +142,8 @@ protected:
add_subtract,
reshape_on_decompression,
extra_multiply,
- per_tensor_zp);
+ per_tensor_zp,
+ param_weight);
auto mat_mul = std::make_shared<ov::op::v0::MatMul>(params[0], weights_subgraph);
return std::make_shared<ov::Model>(ov::OutputVector{mat_mul}, params, "MatmulWeightsDecompression");
@@ -130,7 +155,8 @@ protected:
}
- std::shared_ptr<ov::Node> init_compressed_weights_subgraph(const ov::Shape& weights_shape,
+ std::shared_ptr<ov::Node> init_compressed_weights_subgraph(ov::ParameterVector& params,
+ const ov::Shape& weights_shape,
const int group_size,
const ov::element::Type data_precision,
const ov::element::Type weights_precision,
@@ -138,7 +164,8 @@ protected:
const bool add_subtract,
const bool reshape_on_decompression_constant,
const bool extra_multiply,
- const bool per_tensor_zp) {
+ const bool per_tensor_zp,
+ const bool param_weight) {
auto transpose_if_necessary = [&](const ov::Shape& shape) {
auto result_shape = shape;
if (transpose_weights)
@@ -166,8 +193,14 @@ protected:
transformed_weights_shape[in_channel_idx] = weights_shape[weights_rank - 2] / group_size;
transformed_weights_shape.insert(transformed_weights_shape.begin() + in_channel_idx + 1, group_size);
}
- auto weights_tensor = ov::test::utils::create_and_fill_tensor(weights_precision, transformed_weights_shape);
- auto weights = std::make_shared<ov::op::v0::Constant>(weights_tensor);
+ std::shared_ptr<ov::Node> weights;
+ if (param_weight) {
+ weights = std::make_shared<ov::op::v0::Parameter>(weights_precision, transformed_weights_shape);
+ params.push_back(ov::as_type_ptr<ov::op::v0::Parameter>(weights));
+ } else {
+ auto weights_tensor = ov::test::utils::create_and_fill_tensor(weights_precision, transformed_weights_shape);
+ weights = std::make_shared<ov::op::v0::Constant>(weights_tensor);
+ }
weights->set_friendly_name("Compressed_weights");
auto weights_convert = std::make_shared<ov::op::v0::Convert>(weights, data_precision);
@@ -259,6 +292,7 @@ protected:
reshape_on_decompression,
extra_multiply,
per_tensor_zp,
+ param_weights,
dyn_quan_group_size,
abs_threshold_f16] = GetParam();
@@ -275,7 +309,8 @@ protected:
decompression_sub,
reshape_on_decompression,
extra_multiply,
- per_tensor_zp);
+ per_tensor_zp,
+ param_weights);
if (activations_precision == ov::element::f16) {
@@ -296,7 +331,9 @@ protected:
in_data.start_from = -1;
in_data.range = 3;
in_data.resolution = 10000;
- ov::Tensor tensor = ov::test::utils::create_and_fill_tensor(model_input.get_element_type(), target_input_static_shapes[i], in_data);
+ ov::Tensor tensor = ov::test::utils::create_and_fill_tensor(model_input.get_element_type(),
+ model_input.get_partial_shape().is_static() ? model_input.get_shape() : target_input_static_shapes[i],
+ in_data);
inputs.insert({model_input.get_node_shared_ptr(), tensor});
}
}
@@ -313,6 +350,21 @@ protected:
};
TEST_P(MatmulWeightsDecompression, Inference) {
+ const auto& [shape_params,
+ weights_precision,
+ activations_precision,
+ transpose_weights,
+ decompression_sub,
+ reshape_on_decompression,
+ extra_multiply,
+ per_tensor_zp,
+ param_weights,
+ dyn_quan_group_size,
+ abs_threshold_f16] = GetParam();
+ // Skip tests for 4-bit parameter weights because 4-bit transpose is not supported
+ if (param_weights && weights_precision != ov::element::u8) {
+ GTEST_SKIP();
+ }
SKIP_IF_CURRENT_TEST_IS_DISABLED(); // This is necessary because of check_results
run();
check_results();
@@ -327,6 +379,21 @@ protected:
};
TEST_P(MatmulWeightsDecompressionScalarWeightZp, Inference) {
+ const auto& [shape_params,
+ weights_precision,
+ activations_precision,
+ transpose_weights,
+ decompression_sub,
+ reshape_on_decompression,
+ extra_multiply,
+ per_tensor_zp,
+ param_weights,
+ dyn_quan_group_size,
+ abs_threshold_f16] = GetParam();
+ // Skip tests for 4-bit parameter weights because 4-bit transpose is not supported
+ if (param_weights && weights_precision != ov::element::u8) {
+ GTEST_SKIP();
+ }
SKIP_IF_CURRENT_TEST_IS_DISABLED();
run();
check_results();
@@ -335,6 +402,7 @@ TEST_P(MatmulWeightsDecompressionScalarWeightZp, Inference) {
const std::vector<ov::element::Type> activations_precisions = {ov::element::f32, ov::element::f16};
const std::vector<ov::element::Type> weights_precisions = {ov::element::u8, ov::element::u4, ov::element::i4};
const std::vector<bool> transpose_weights = {true, false};
+const std::vector<bool> param_weights = {true, false};
const std::vector<ShapeParams> input_shapes_basic = {
{{{-1, -1, -1}, {{1, 4, 16}, {10, 16, 16}}}, {16, 32}},
{{{}, {{1, 4, 16}}}, {16, 32}, 2ul},
@@ -353,6 +421,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_basic,
::testing::Values(true),
::testing::Values(false),
::testing::Values(false),
+ ::testing::ValuesIn(param_weights),
::testing::Values(0),
::testing::Values(1.0f)),
MatmulWeightsDecompression::get_test_case_name);
@@ -367,6 +436,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_extra_multiply,
::testing::Values(false),
::testing::Values(true),
::testing::Values(false),
+ ::testing::ValuesIn(param_weights),
::testing::Values(0),
::testing::Values(1.0f)),
MatmulWeightsDecompression::get_test_case_name);
@@ -398,6 +468,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_corner_cases_basic,
::testing::ValuesIn(reshape_on_decompression),
::testing::Values(false),
::testing::ValuesIn(per_tensor_zp),
+ ::testing::ValuesIn(param_weights),
::testing::Values(0),
::testing::Values(1.0f)),
MatmulWeightsDecompression::get_test_case_name);
@@ -412,6 +483,7 @@ INSTANTIATE_TEST_SUITE_P(MatMulCompressedWeights_corner_cases_big,
::testing::ValuesIn(reshape_on_decompression),
::testing::Values(false),
::testing::ValuesIn(per_tensor_zp),
+ ::testing::ValuesIn(param_weights),
::testing::Values(0),
::testing::Values(1.0f)),
MatmulWeightsDecompression::get_test_case_name);
@@ -432,6 +504,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_dyn_quan,
::testing::Values(true),
::testing::Values(false),
::testing::Values(true), // per_tensor_zp
+ ::testing::Values(false),
::testing::ValuesIn(group_size),
::testing::Values(2.0f)), // Note: this is because of potential cldnn accuracy issue
MatmulWeightsDecompression::get_test_case_name);
@@ -447,6 +520,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_dyn_quan_precomputed_redu
::testing::Values(true),
::testing::Values(false),
::testing::Values(false), // per_tensor_zp
+ ::testing::Values(false),
::testing::Values(128),
::testing::Values(2.0f)), // Note: this is because of potential cldnn accuracy issue
MatmulWeightsDecompression::get_test_case_name);
@@ -463,6 +537,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_dyn_quan_unaligned, /
::testing::Values(true),
::testing::Values(false),
::testing::Values(true), // per_tensor_zp
+ ::testing::Values(false),
::testing::Values(std::numeric_limits<int64_t>::max()),
::testing::Values(2.0f)), // Note: this is because of potential cldnn accuracy issue
MatmulWeightsDecompression::get_test_case_name);
@@ -478,6 +553,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_dyn_quan_no_slm,
::testing::Values(true),
::testing::Values(false),
::testing::Values(true), // per_tensor_zp
+ ::testing::Values(false),
::testing::ValuesIn(group_size),
::testing::Values(2.0f)), // Note: this is because of potential cldnn accuracy issue
MatmulWeightsDecompression::get_test_case_name);
@@ -493,6 +569,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_3D_weight,
::testing::Values(false),
::testing::Values(false),
::testing::Values(true),
+ ::testing::Values(false),
::testing::Values(0),
::testing::Values(2.0f)),
MatmulWeightsDecompression::get_test_case_name);
@@ -508,6 +585,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_dyn_quan_scalar_wzp,
::testing::Values(true),
::testing::Values(false),
::testing::Values(true),
+ ::testing::Values(false),
::testing::Values(128),
::testing::Values(2.0f)),
MatmulWeightsDecompression::get_test_case_name);
@@ -523,6 +601,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_dyn_quan_precomputed_redu
::testing::Values(true),
::testing::Values(false),
::testing::Values(false),
+ ::testing::Values(false),
::testing::Values(128),
::testing::Values(2.0f)),
MatmulWeightsDecompression::get_test_case_name);
@@ -538,6 +617,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_input_4d,
::testing::Values(false),
::testing::Values(false),
::testing::Values(true),
+ ::testing::Values(false),
::testing::Values(0),
::testing::Values(1.0f)),
MatmulWeightsDecompression::get_test_case_name);
diff --git a/src/plugins/intel_gpu/tests/unit/transformations/convert_fc_to_compressed_test.cpp b/src/plugins/intel_gpu/tests/unit/transformations/convert_fc_to_compressed_test.cpp
index 8bcb6114ffa..cab74b5e51e 100644
--- a/src/plugins/intel_gpu/tests/unit/transformations/convert_fc_to_compressed_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/transformations/convert_fc_to_compressed_test.cpp
@@ -492,6 +492,147 @@ TEST_F(TransformationTestsF, ConvertFCToCompressed11) {
}
}
+TEST_F(TransformationTestsF, ConvertFCToCompressed12) {
+ {
+ auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights_param = std::make_shared<ov::op::v0::Parameter>(ov::element::u4, ov::Shape{32, 16});
+ auto convert = std::make_shared<ov::op::v0::Convert>(weights_param, ov::element::f16);
+ auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{32, 1}, {1});
+ auto scale = std::make_shared<ov::op::v1::Multiply>(convert, scale_const);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+
+ auto fc = std::make_shared<ov::intel_gpu::op::FullyConnected>(input1, scale, no_bias);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{fc}, ov::ParameterVector{input1, weights_param});
+ manager.register_pass<ConvertFullyConnectedToFullyConnectedCompressed>();
+ }
+ {
+ auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights_param = std::make_shared<ov::op::v0::Parameter>(ov::element::u4, ov::Shape{32, 16});
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{32, 1}, {1});
+
+ auto fc_compressed = std::make_shared<ov::intel_gpu::op::FullyConnectedCompressed>(input1, weights_param, no_bias, scale_const);
+
+ model_ref = std::make_shared<ov::Model>(ov::OutputVector{fc_compressed}, ov::ParameterVector{input1, weights_param});
+ }
+}
+
+TEST_F(TransformationTestsF, ConvertFCToCompressed13) {
+ {
+ auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights_param = std::make_shared<ov::op::v0::Parameter>(ov::element::u4, ov::Shape{4, 4, 32});
+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {16, 32});
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(weights_param, reshape_const, false);
+ auto convert = std::make_shared<ov::op::v0::Convert>(reshape, ov::element::f16);
+ auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 32}, {1});
+ auto scale = std::make_shared<ov::op::v1::Multiply>(convert, scale_const);
+ auto transpose_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});
+ auto transpose = std::make_shared<ov::op::v1::Transpose>(scale, transpose_const);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+
+ auto fc = std::make_shared<ov::intel_gpu::op::FullyConnected>(input1, transpose, no_bias);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{fc}, ov::ParameterVector{input1, weights_param});
+ manager.register_pass<ConvertFullyConnectedToFullyConnectedCompressed>();
+ }
+ {
+ auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights_param = std::make_shared<ov::op::v0::Parameter>(ov::element::u4, ov::Shape{4, 4, 32});
+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {16, 32});
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(weights_param, reshape_const, false);
+ auto transpose_weights_param = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});
+ auto transpose_weights = std::make_shared<ov::op::v1::Transpose>(reshape, transpose_weights_param);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 32}, {1});
+ auto transpose_scale_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});
+ auto transpose_scale = std::make_shared<ov::op::v1::Transpose>(scale_const, transpose_scale_const);
+
+ auto fc_compressed = std::make_shared<ov::intel_gpu::op::FullyConnectedCompressed>(input1, transpose_weights, no_bias, transpose_scale);
+
+ model_ref = std::make_shared<ov::Model>(ov::OutputVector{fc_compressed}, ov::ParameterVector{input1, weights_param});
+ }
+}
+
+TEST_F(TransformationTestsF, ConvertFCToCompressed14) {
+ {
+ auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights_param = std::make_shared<ov::op::v0::Parameter>(ov::element::u4, ov::Shape{4, 4, 32});
+ auto convert = std::make_shared<ov::op::v0::Convert>(weights_param, ov::element::f16);
+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {16, 32});
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(convert, reshape_const, false);
+ auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 32}, {1});
+ auto scale = std::make_shared<ov::op::v1::Multiply>(reshape, scale_const);
+ auto transpose_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});
+ auto transpose = std::make_shared<ov::op::v1::Transpose>(scale, transpose_const);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+
+ auto fc = std::make_shared<ov::intel_gpu::op::FullyConnected>(input1, transpose, no_bias);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{fc}, ov::ParameterVector{input1, weights_param});
+ manager.register_pass<ConvertFullyConnectedToFullyConnectedCompressed>();
+ }
+ {
+ auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights_param = std::make_shared<ov::op::v0::Parameter>(ov::element::u4, ov::Shape{4, 4, 32});
+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {16, 32});
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(weights_param, reshape_const, false);
+ auto transpose_weights_param = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});
+ auto transpose_weights = std::make_shared<ov::op::v1::Transpose>(reshape, transpose_weights_param);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 32}, {1});
+ auto transpose_scale_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});
+ auto transpose_scale = std::make_shared<ov::op::v1::Transpose>(scale_const, transpose_scale_const);
+
+ auto fc_compressed = std::make_shared<ov::intel_gpu::op::FullyConnectedCompressed>(input1, transpose_weights, no_bias, transpose_scale);
+
+ model_ref = std::make_shared<ov::Model>(ov::OutputVector{fc_compressed}, ov::ParameterVector{input1, weights_param});
+ }
+}
+
+TEST_F(TransformationTestsF, ConvertFCToCompressed15) {
+ {
+ auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights_param = std::make_shared<ov::op::v0::Parameter>(ov::element::u4, ov::Shape{4, 4, 32});
+ auto convert = std::make_shared<ov::op::v0::Convert>(weights_param, ov::element::f16);
+ auto zp_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{4, 1, 32}, {1});
+ auto zp_convert = std::make_shared<ov::op::v0::Convert>(zp_const, ov::element::f16);
+ auto sub = std::make_shared<ov::op::v1::Subtract>(convert, zp_convert);
+ auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{4, 1, 32}, {1});
+ auto scale = std::make_shared<ov::op::v1::Multiply>(sub, scale_const);
+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {16, 32});
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(scale, reshape_const, false);
+ auto transpose_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});
+ auto transpose = std::make_shared<ov::op::v1::Transpose>(reshape, transpose_const);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+
+ auto fc = std::make_shared<ov::intel_gpu::op::FullyConnected>(input1, transpose, no_bias);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{fc}, ov::ParameterVector{input1, weights_param});
+ manager.register_pass<ConvertFullyConnectedToFullyConnectedCompressed>();
+ }
+ {
+ auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights_param = std::make_shared<ov::op::v0::Parameter>(ov::element::u4, ov::Shape{4, 4, 32});
+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {16, 32});
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(weights_param, reshape_const, false);
+ auto transpose_weights_param = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});
+ auto transpose_weights = std::make_shared<ov::op::v1::Transpose>(reshape, transpose_weights_param);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{4, 32}, {1});
+ auto transpose_scale_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});
+ auto transpose_scale = std::make_shared<ov::op::v1::Transpose>(scale_const, transpose_scale_const);
+ auto zp_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{4, 32}, {1});
+ auto zp_convert = std::make_shared<ov::op::v0::Convert>(zp_const, ov::element::f16);
+ auto transpose_zp_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});
+ auto transpose_zp = std::make_shared<ov::op::v1::Transpose>(zp_const, transpose_zp_const);
+
+ auto fc_compressed = std::make_shared<ov::intel_gpu::op::FullyConnectedCompressed>(input1, transpose_weights, no_bias, transpose_scale, transpose_zp);
+
+ model_ref = std::make_shared<ov::Model>(ov::OutputVector{fc_compressed}, ov::ParameterVector{input1, weights_param});
+ }
+}
+
} // namespace intel_gpu
} // namespace test
} // namespace ov
diff --git a/src/plugins/intel_gpu/tests/unit/transformations/convert_matmul_to_fc_test.cpp b/src/plugins/intel_gpu/tests/unit/transformations/convert_matmul_to_fc_test.cpp
index 7b176225305..30f71d07ff3 100644
--- a/src/plugins/intel_gpu/tests/unit/transformations/convert_matmul_to_fc_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/transformations/convert_matmul_to_fc_test.cpp
@@ -442,6 +442,38 @@ TEST_F(TransformationTestsF, ConvertMatMulToFullyConnectedTest_compressed_u8_wei
}
}
+TEST_F(TransformationTestsF, ConvertMatMulToFullyConnectedTest_compressed_u8_parameter_weights) {
+ {
+ auto data = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 2});
+ auto weights = std::make_shared<ov::opset1::Parameter>(ov::element::u8, ov::Shape{1, 2, 2});
+ auto convert = std::make_shared<ov::opset1::Convert>(weights, ov::element::f32);
+ auto sub_const = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1, 2}, {1});
+ auto sub = std::make_shared<ov::opset1::Subtract>(convert, sub_const);
+ 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 matmul = std::make_shared<ov::opset1::MatMul>(data, mul);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{data, weights});
+ manager.register_pass<ConvertMatMulToFullyConnected>();
+ }
+ {
+ auto data = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{3, 2, 2});
+ auto weights = std::make_shared<ov::opset1::Parameter>(ov::element::u8, ov::Shape{1, 2, 2});
+ auto convert = std::make_shared<ov::opset1::Convert>(weights, ov::element::f32);
+ auto sub_const = ov::opset1::Constant::create(ov::element::f32, ov::Shape{1, 1, 2}, {1});
+ auto sub = std::make_shared<ov::opset1::Subtract>(convert, sub_const);
+ 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 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 no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto matmul = std::make_shared<op::FullyConnected>(data, transpose, no_bias);
+
+ model_ref = std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{data, weights});
+ }
+}
+
TEST_F(TransformationTestsF, ConvertMatMulToFullyConnectedTest_compressed_u4_weights_3D) {
{
auto data = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::Shape{3, 2, 2});
@@ -594,7 +626,7 @@ TEST(TransformationTests, ConvertMatMulToFullyConnectedExceptionTest_sibling_mat
break;
}
}
- ASSERT_TRUE(success == false);
+ ASSERT_TRUE(success == true);
func = CreateMatMul(false, false, false, true);
manager.run_passes(func);
@@ -606,7 +638,7 @@ TEST(TransformationTests, ConvertMatMulToFullyConnectedExceptionTest_sibling_mat
break;
}
}
- ASSERT_TRUE(success == false);
+ ASSERT_TRUE(success == true);
}
TEST(TransformationTests, ConvertMatMulToFullyConnectedExceptionTest_sibling_matmul_same_input) {