Skip to content

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

[GPU][Tests] Refactor matmul_weights_decompression.cpp test (#36641)

Tomasz Krupa0516fe1cd4c3
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 3d51f606e83..9b987d5626c 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
@@ -5,20 +5,21 @@
#include <optional>
#include "common_test_utils/ov_tensor_utils.hpp"
-#include "intel_gpu/runtime/utils.hpp"
-#include "shared_test_classes/base/ov_subgraph.hpp"
-#include "transformations/rt_info/decompression.hpp"
+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"
#include "intel_gpu/runtime/internal_properties.hpp"
-
-#include "openvino/op/parameter.hpp"
+#include "intel_gpu/runtime/utils.hpp"
#include "openvino/op/constant.hpp"
-#include "openvino/op/result.hpp"
+#include "openvino/op/convert.hpp"
#include "openvino/op/matmul.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/parameter.hpp"
#include "openvino/op/reshape.hpp"
-#include "openvino/op/convert.hpp"
+#include "openvino/op/result.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/op/transpose.hpp"
-#include "openvino/op/multiply.hpp"
+#include "shared_test_classes/base/ov_subgraph.hpp"
+#include "transformations/rt_info/decompression.hpp"
+#include "transformations/utils/utils.hpp"
namespace {
using ov::test::InputShape;
@@ -55,18 +56,17 @@ struct ShapeParams {
int weights_group_size;
};
-using MatmulWeightsDecompressionParams = std::tuple<ShapeParams, // input shapes
- ov::element::Type, // weights type
- ov::element::Type, // activations type
- ov::element::Type, // scale type
- bool, // transpose on weights
- bool, // decompression subtract
- 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
+using MatmulWeightsDecompressionParams = std::tuple<ShapeParams, // input shapes
+ ov::element::Type, // weights type
+ ov::element::Type, // activations type
+ ov::element::Type, // scale type
+ bool, // transpose on weights
+ ov::test::utils::DecompressionType, // decompression subtract type
+ bool, // reshape on decompression constants
+ bool, // extra multiply
+ bool, // parameter weights
+ uint64_t, // dynamic_quantization_group_size
+ float // abs_threshold_f16
>;
class MatmulWeightsDecompression : public testing::WithParamInterface<MatmulWeightsDecompressionParams>,
@@ -81,7 +81,6 @@ public:
decompression_sub,
reshape_on_decompression,
extra_multiply,
- per_tensor_zp,
param_weights,
dyn_quan_group_size,
abs_threshold_f16] = obj.param;
@@ -101,7 +100,6 @@ public:
result << "decompression_subtract=" << decompression_sub << "_";
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 << "_";
@@ -135,170 +133,42 @@ protected:
const ov::element::Type weights_precision,
const ov::element::Type scale_precision,
const bool transpose_weights,
- const bool add_subtract,
+ const ov::test::utils::DecompressionType decompression_subtract_type,
const bool reshape_on_decompression,
const bool extra_multiply,
- 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(params,
- weights_shape,
- group_size,
- data_precision,
- weights_precision,
- scale_precision,
- transpose_weights,
- add_subtract,
- reshape_on_decompression,
- extra_multiply,
- per_tensor_zp,
- param_weight);
-
+ const auto decompression_multiply_type = ov::test::utils::DecompressionType::full;
+ const std::optional<bool> insert_transpose_node = std::nullopt;
+ const int seed = 1;
+ const auto weights_subgraph = ov::test::utils::initMatMulDecompressionSubgraph(weights_shape,
+ group_size,
+ data_precision,
+ weights_precision,
+ data_precision,
+ scale_precision,
+ transpose_weights,
+ decompression_multiply_type,
+ decompression_subtract_type,
+ reshape_on_decompression,
+ insert_transpose_node,
+ seed,
+ extra_multiply,
+ param_weight);
+
+ std::unordered_set<ov::Node*> visited_nodes;
+ auto add_params = [&params](ov::Node* node) {
+ if (auto param = std::dynamic_pointer_cast<ov::op::v0::Parameter>(node->shared_from_this())) {
+ params.push_back(param);
+ }
+ };
+ ov::op::util::visit_path(weights_subgraph.get(), visited_nodes, add_params, [](ov::Node*) {
+ return false;
+ });
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");
}
- virtual ov::Shape get_weight_zero_point_shape(const ov::Shape& scaleshift_const_shape,
- bool per_tensor_zp) const {
- return per_tensor_zp ? ov::Shape{1} : scaleshift_const_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,
- const ov::element::Type scale_precision,
- const bool transpose_weights,
- const bool add_subtract,
- const bool reshape_on_decompression_constant,
- const bool extra_multiply,
- const bool per_tensor_zp,
- const bool param_weight) {
- auto transpose_if_necessary = [&](const ov::Shape& shape) {
- auto result_shape = shape;
- if (transpose_weights)
- std::swap(*result_shape.rbegin(), *(result_shape.rbegin() + 1));
- return result_shape;
- };
-
- const bool group_decompression = group_size != -1;
- // Weights has shape [I, O], where
- // I - input channels
- // O - output channels
- // In case of group decompression, input channels dimension is split into 2: I -> [N, G], where
- // N - number of groups
- // G - group size
- auto transformed_weights_shape = transpose_if_necessary(weights_shape);
- auto weights_rank = weights_shape.size();
- if (group_decompression) {
- OPENVINO_ASSERT(weights_shape[weights_rank - 2] % group_size == 0,
- "Weights output channels count (",
- weights_shape[weights_rank - 2],
- ") must be divisible by decompression group size (",
- group_size,
- ").");
- auto in_channel_idx = transpose_weights ? transformed_weights_shape.size() - 1 : transformed_weights_shape.size() - 2;
- 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);
- }
- 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);
-
- std::shared_ptr<ov::Node> mul_parent = weights_convert;
- auto output_channels = *weights_shape.rbegin();
-
- // Decompression constants shape:
- // Ordinary decompression: [O, 1]
- // Group decompression: [O, N, 1]
- ov::Shape scaleshift_target_shape{output_channels};
- scaleshift_target_shape.insert(scaleshift_target_shape.begin(), group_decompression ? weights_shape[weights_rank - 2] / group_size : 1);
- if (weights_shape.size() == 3 && std::count_if(weights_shape.begin(), weights_shape.end(), [](size_t dim) { return dim != 1; }) == 3)
- scaleshift_target_shape.insert(scaleshift_target_shape.begin(), weights_shape[0]);
- scaleshift_target_shape = transpose_if_necessary(scaleshift_target_shape);
- if (group_decompression) {
- auto in_channel_idx = transpose_weights ? scaleshift_target_shape.size() - 1 : scaleshift_target_shape.size() - 2;
- scaleshift_target_shape.insert(scaleshift_target_shape.begin() + in_channel_idx + 1, 1);
- }
-
- auto scaleshift_const_shape = scaleshift_target_shape;
- if (reshape_on_decompression_constant)
- scaleshift_const_shape.erase(std::remove(scaleshift_const_shape.begin(), scaleshift_const_shape.end(), 1), scaleshift_const_shape.end());
- if (add_subtract) {
- auto shift_tensor_shape = get_weight_zero_point_shape(scaleshift_const_shape, per_tensor_zp);
- auto shift_tensor = ov::test::utils::create_and_fill_tensor(weights_precision, shift_tensor_shape);
- if (per_tensor_zp && weights_precision.bitwidth() == 4) {
- static_cast<uint8_t*>(shift_tensor.data())[0] = 0x88;
- }
- auto shift_const = std::make_shared<ov::op::v0::Constant>(shift_tensor);
- std::shared_ptr<ov::Node> shift_convert = std::make_shared<ov::op::v0::Convert>(shift_const, data_precision);
- if (reshape_on_decompression_constant && !per_tensor_zp) {
- auto shift_reshape_const = ov::op::v0::Constant::create(ov::element::i32, {scaleshift_target_shape.size()}, scaleshift_target_shape);
- auto shift_reshape = std::make_shared<ov::op::v1::Reshape>(shift_convert, shift_reshape_const, false);
- shift_convert = shift_reshape;
- }
- mul_parent = std::make_shared<ov::op::v1::Subtract>(weights_convert, shift_convert);
- }
-
- ov::test::utils::InputGenerateData in_data;
- in_data.start_from = -0.5;
- in_data.range = 1;
- in_data.resolution = 30000;
- auto scale_tensor = ov::test::utils::create_and_fill_tensor(scale_precision, scaleshift_const_shape, in_data);
- for (size_t i = 0; i < scale_tensor.get_size(); i++) {
- if (scale_precision == ov::element::f16)
- scale_tensor.data<ov::float16>()[i] /= ov::float16(16.f);
- else if (scale_precision == ov::element::f32)
- scale_tensor.data<float>()[i] /= 16.f;
- else if (scale_precision == ov::element::f8e8m0)
- scale_tensor.data<ov::float8_e8m0>()[i] /= ov::float8_e8m0(16.f);
- }
-
- std::shared_ptr<ov::Node> scale_const = std::make_shared<ov::op::v0::Constant>(scale_tensor);
- if (scale_precision != data_precision) {
- auto scale_convert = std::make_shared<ov::op::v0::Convert>(scale_const, data_precision);
- scale_const = scale_convert;
- }
-
- if (reshape_on_decompression_constant) {
- auto scale_reshape_const = ov::op::v0::Constant::create(ov::element::i32, {scaleshift_target_shape.size()}, scaleshift_target_shape);
- auto scale_reshape = std::make_shared<ov::op::v1::Reshape>(scale_const, scale_reshape_const, false);
- scale_const = scale_reshape;
- }
- std::shared_ptr<ov::Node> last_node = std::make_shared<ov::op::v1::Multiply>(mul_parent, scale_const);
-
- if (group_decompression) {
- auto weight_hidden_idx = weights_shape.size() - 2;
- auto reshape_target_shape = transpose_weights ? std::vector<int>{-1, static_cast<int>(weights_shape[weight_hidden_idx])}
- : std::vector<int>{static_cast<int>(weights_shape[weight_hidden_idx]), -1};
- for (size_t i = 0; i < weight_hidden_idx; ++i) {
- reshape_target_shape.insert(reshape_target_shape.begin() + i, weights_shape[i]);
- }
- auto target_shape_node = ov::op::v0::Constant::create(ov::element::i32, {reshape_target_shape.size()}, reshape_target_shape);
- last_node = std::make_shared<ov::op::v1::Reshape>(last_node, target_shape_node, false);
- }
- if (transpose_weights) {
- const size_t rank = last_node->get_output_partial_shape(0).size();
- std::vector<int> order(rank);
- std::iota(order.begin(), order.end(), 0);
- std::swap(*order.rbegin(), *(order.rbegin() + 1));
- auto transpose_constant = ov::op::v0::Constant::create(ov::element::i32, {rank}, order);
- last_node = std::make_shared<ov::op::v1::Transpose>(last_node, transpose_constant);
- } else if (extra_multiply) {
- last_node = std::make_shared<ov::op::v1::Multiply>(last_node, scale_const);
- }
- return last_node;
- }
-
void SetUp() override {
targetDevice = ov::test::utils::DEVICE_GPU;
@@ -310,7 +180,6 @@ protected:
decompression_sub,
reshape_on_decompression,
extra_multiply,
- per_tensor_zp,
param_weights,
dyn_quan_group_size,
abs_threshold_f16] = GetParam();
@@ -330,7 +199,6 @@ protected:
decompression_sub,
reshape_on_decompression,
extra_multiply,
- per_tensor_zp,
param_weights);
if (activations_precision == ov::element::f16) {
@@ -378,7 +246,6 @@ TEST_P(MatmulWeightsDecompression, Inference) {
decompression_sub,
reshape_on_decompression,
extra_multiply,
- per_tensor_zp,
param_weights,
dyn_quan_group_size,
abs_threshold_f16] = GetParam();
@@ -391,36 +258,6 @@ TEST_P(MatmulWeightsDecompression, Inference) {
check_results();
}
-class MatmulWeightsDecompressionScalarWeightZp : public MatmulWeightsDecompression {
-protected:
- ov::Shape get_weight_zero_point_shape(const ov::Shape& scaleshift_const_shape,
- bool per_tensor_zp) const override {
- return per_tensor_zp ? ov::Shape{} : scaleshift_const_shape;
- }
-};
-
-TEST_P(MatmulWeightsDecompressionScalarWeightZp, Inference) {
- const auto& [shape_params,
- weights_precision,
- activations_precision,
- scale_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();
-}
-
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};
@@ -449,9 +286,8 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_basic,
::testing::ValuesIn(activations_precisions),
::testing::Values(ov::element::dynamic),
::testing::ValuesIn(transpose_weights),
+ ::testing::Values(ov::test::utils::DecompressionType::full),
::testing::Values(true),
- ::testing::Values(true),
- ::testing::Values(false),
::testing::Values(false),
::testing::ValuesIn(param_weights),
::testing::Values(0),
@@ -465,10 +301,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_extra_multiply,
::testing::ValuesIn(activations_precisions),
::testing::Values(ov::element::dynamic),
::testing::Values(false),
- ::testing::Values(false),
+ ::testing::Values(ov::test::utils::DecompressionType::empty),
::testing::Values(false),
::testing::Values(true),
- ::testing::Values(false),
::testing::ValuesIn(param_weights),
::testing::Values(0),
::testing::Values(1.0f)),
@@ -481,10 +316,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_extra_multiply_non_trivia
::testing::ValuesIn(activations_precisions),
::testing::Values(ov::element::dynamic),
::testing::Values(false),
- ::testing::Values(false),
+ ::testing::Values(ov::test::utils::DecompressionType::empty),
::testing::Values(false),
::testing::Values(true),
- ::testing::Values(false),
::testing::ValuesIn(param_weights),
::testing::Values(0),
::testing::Values(1.0f)),
@@ -503,9 +337,14 @@ const std::vector<ShapeParams> input_shapes_corner_cases_big = {
{{{-1, 4096}, {{1, 4096}}}, {4096, 4096}, 128},
};
-const std::vector<bool> add_decompression_sub = {true, false};
+const std::vector<ov::test::utils::DecompressionType> decompression_sub = {ov::test::utils::DecompressionType::full,
+ ov::test::utils::DecompressionType::scalar,
+ ov::test::utils::DecompressionType::empty};
+const std::vector<ov::test::utils::DecompressionType> decompression_sub_no_full = {ov::test::utils::DecompressionType::scalar,
+ ov::test::utils::DecompressionType::empty};
+const std::vector<ov::test::utils::DecompressionType> decompression_sub_no_scalar = {ov::test::utils::DecompressionType::full,
+ ov::test::utils::DecompressionType::empty};
const std::vector<bool> reshape_on_decompression = {true, false};
-const std::vector<bool> per_tensor_zp = {true, false};
INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_corner_cases_basic,
MatmulWeightsDecompression,
@@ -514,10 +353,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_corner_cases_basic,
::testing::ValuesIn(activations_precisions),
::testing::Values(ov::element::dynamic),
::testing::ValuesIn(transpose_weights),
- ::testing::ValuesIn(add_decompression_sub),
+ ::testing::ValuesIn(decompression_sub),
::testing::ValuesIn(reshape_on_decompression),
::testing::Values(false),
- ::testing::ValuesIn(per_tensor_zp),
::testing::ValuesIn(param_weights),
::testing::Values(0),
::testing::Values(1.0f)),
@@ -530,10 +368,9 @@ INSTANTIATE_TEST_SUITE_P(MatMulCompressedWeights_corner_cases_big,
::testing::ValuesIn(activations_precisions),
::testing::Values(ov::element::dynamic),
::testing::ValuesIn(transpose_weights),
- ::testing::ValuesIn(add_decompression_sub),
+ ::testing::ValuesIn(decompression_sub),
::testing::ValuesIn(reshape_on_decompression),
::testing::Values(false),
- ::testing::ValuesIn(per_tensor_zp),
::testing::ValuesIn(param_weights),
::testing::Values(0),
::testing::Values(1.0f)),
@@ -552,10 +389,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_dyn_quan,
::testing::Values(ov::element::f16),
::testing::Values(ov::element::f16),
::testing::Values(false),
- ::testing::ValuesIn(add_decompression_sub),
+ ::testing::ValuesIn(decompression_sub_no_full),
::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
@@ -569,10 +405,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_dyn_quan_precomputed_redu
::testing::Values(ov::element::f16),
::testing::Values(ov::element::f16),
::testing::Values(false),
- ::testing::ValuesIn(add_decompression_sub),
+ ::testing::ValuesIn(decompression_sub_no_scalar),
::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
@@ -587,10 +422,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_dyn_quan_unaligned, /
::testing::Values(ov::element::f16),
::testing::Values(ov::element::f16),
::testing::Values(false),
- ::testing::Values(false),
+ ::testing::Values(ov::test::utils::DecompressionType::empty),
::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
@@ -604,10 +438,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_dyn_quan_no_slm,
::testing::Values(ov::element::f16),
::testing::Values(ov::element::f16),
::testing::Values(false),
- ::testing::ValuesIn(add_decompression_sub),
+ ::testing::ValuesIn(decompression_sub_no_full),
::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
@@ -621,11 +454,10 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_3D_weight,
::testing::Values(ov::element::f16),
::testing::Values(ov::element::f16),
::testing::Values(false),
+ ::testing::Values(ov::test::utils::DecompressionType::empty),
::testing::Values(false),
::testing::Values(false),
::testing::Values(false),
- ::testing::Values(true),
- ::testing::Values(false),
::testing::Values(0),
::testing::Values(2.0f)),
MatmulWeightsDecompression::get_test_case_name);
@@ -638,8 +470,7 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(ov::element::f16),
::testing::Values(ov::element::f8e8m0),
::testing::Values(true),
- ::testing::Values(false),
- ::testing::Values(false),
+ ::testing::Values(ov::test::utils::DecompressionType::empty),
::testing::Values(false),
::testing::Values(false),
::testing::Values(false),
@@ -655,27 +486,25 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(ov::element::f16),
::testing::Values(ov::element::f16),
::testing::Values(true),
+ ::testing::Values(ov::test::utils::DecompressionType::empty),
::testing::Values(false),
::testing::Values(false),
- ::testing::Values(true),
- ::testing::Values(false),
::testing::Values(false),
::testing::ValuesIn(std::vector<uint64_t>{32, 128, std::numeric_limits<uint64_t>::max()}),
::testing::Values(1.0f)),
MatmulWeightsDecompression::get_test_case_name);
INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_dyn_quan_scalar_wzp,
- MatmulWeightsDecompressionScalarWeightZp,
+ MatmulWeightsDecompression,
::testing::Combine(::testing::Values(ShapeParams{{{-1, -1, 1024}, {{1024, 1, 1024}}},
{1024, 1024}, 128}),
::testing::Values(ov::element::u4),
::testing::Values(ov::element::f16),
::testing::Values(ov::element::f16),
::testing::Values(false),
- ::testing::Values(true),
- ::testing::Values(true),
+ ::testing::Values(ov::test::utils::DecompressionType::scalar),
+ ::testing::Values(false),
::testing::Values(false),
- ::testing::Values(true),
::testing::Values(false),
::testing::Values(128),
::testing::Values(2.0f)),
@@ -689,11 +518,10 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_dyn_quan_precomputed_redu
::testing::Values(ov::element::f16),
::testing::Values(ov::element::f16),
::testing::Values(false),
- ::testing::ValuesIn(add_decompression_sub),
+ ::testing::ValuesIn(decompression_sub_no_scalar),
::testing::Values(true),
::testing::Values(false),
::testing::Values(false),
- ::testing::Values(false),
::testing::Values(128),
::testing::Values(2.0f)),
MatmulWeightsDecompression::get_test_case_name);
@@ -706,11 +534,10 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_input_4d,
::testing::Values(ov::element::f16),
::testing::Values(ov::element::f16),
::testing::Values(false),
+ ::testing::Values(ov::test::utils::DecompressionType::empty),
::testing::Values(false),
::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/tests/test_utils/common_test_utils/include/common_test_utils/subgraph_builders/weights_decompression_builders.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/subgraph_builders/weights_decompression_builders.hpp
index 223a9797141..2db137f2e2f 100644
--- a/src/tests/test_utils/common_test_utils/include/common_test_utils/subgraph_builders/weights_decompression_builders.hpp
+++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/subgraph_builders/weights_decompression_builders.hpp
@@ -36,7 +36,9 @@ std::shared_ptr<ov::Node> initMatMulDecompressionSubgraph(
const DecompressionType decompression_subtract_type,
const bool reshape_on_decompression_constant,
const std::optional<bool>& insert_transpose_node = std::nullopt,
- const size_t seed = 1);
+ const size_t seed = 1,
+ const bool extra_multiply = false,
+ const bool param_weights = false);
// Real-quantize a random fp32 tensor. Source range [-0.1, 0.1) matches LLM FFN weights;
// wider ranges sink deep-chain outputs into bf16/f16 noise.
diff --git a/src/tests/test_utils/common_test_utils/src/subgraph_builders/weights_decompression_builders.cpp b/src/tests/test_utils/common_test_utils/src/subgraph_builders/weights_decompression_builders.cpp
index f4a0d762b8a..25d581239a5 100644
--- a/src/tests/test_utils/common_test_utils/src/subgraph_builders/weights_decompression_builders.cpp
+++ b/src/tests/test_utils/common_test_utils/src/subgraph_builders/weights_decompression_builders.cpp
@@ -11,6 +11,7 @@
#include "openvino/core/type/element_iterator.hpp"
#include "openvino/op/convert.hpp"
#include "openvino/op/multiply.hpp"
+#include "openvino/op/parameter.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/op/transpose.hpp"
@@ -49,7 +50,9 @@ std::shared_ptr<ov::Node> initMatMulDecompressionSubgraph(const ov::Shape& weigh
const DecompressionType decompression_subtract_type,
const bool reshape_on_decompression_constant,
const std::optional<bool>& insert_transpose_node,
- const size_t seed) {
+ const size_t seed,
+ const bool extra_multiply,
+ const bool param_weights) {
auto transpose_if_necessary = [&](const ov::Shape& shape) {
auto result_shape = shape;
if (transpose_weights)
@@ -81,11 +84,17 @@ std::shared_ptr<ov::Node> initMatMulDecompressionSubgraph(const ov::Shape& weigh
auto up_to = weights_precision == ov::element::u2 ? 3 : weights_precision == ov::element::i4 ? 7 : 15;
auto start_from = weights_precision == ov::element::u2 ? 0 : 1;
- auto weights_tensor =
- ov::test::utils::create_and_fill_tensor(weights_precision,
- transformed_weights_shape,
- ov::test::utils::InputGenerateData(start_from, up_to, 1, seed));
- auto weights = std::make_shared<ov::op::v0::Constant>(weights_tensor);
+
+ std::shared_ptr<ov::Node> weights = nullptr;
+ if (param_weights) {
+ weights = std::make_shared<ov::op::v0::Parameter>(weights_precision, transformed_weights_shape);
+ } else {
+ auto weights_tensor =
+ ov::test::utils::create_and_fill_tensor(weights_precision,
+ transformed_weights_shape,
+ ov::test::utils::InputGenerateData(start_from, up_to, 1, seed));
+ weights = std::make_shared<ov::op::v0::Constant>(weights_tensor);
+ }
auto weights_convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);
@@ -135,6 +144,7 @@ std::shared_ptr<ov::Node> initMatMulDecompressionSubgraph(const ov::Shape& weigh
mul_parent = std::make_shared<ov::opset10::Subtract>(weights_convert, shift_convert);
}
+ std::shared_ptr<ov::Node> scale_const = nullptr;
std::shared_ptr<ov::Node> last_node = mul_parent;
const auto& scale_prc = scale_precision == ov::element::dynamic ? decompression_precision : scale_precision;
if (decompression_multiply_type != DecompressionType::empty) {
@@ -142,7 +152,7 @@ std::shared_ptr<ov::Node> initMatMulDecompressionSubgraph(const ov::Shape& weigh
decompression_multiply_type == DecompressionType::full ? scaleshift_const_shape : ov::Shape({});
auto scale_const_tensor =
ov::test::utils::create_and_fill_tensor_real_distribution(scale_prc, multiply_shape, 0.001f, 0.01f, seed);
- std::shared_ptr<ov::Node> scale_const = std::make_shared<ov::op::v0::Constant>(scale_const_tensor);
+ scale_const = std::make_shared<ov::op::v0::Constant>(scale_const_tensor);
if (scale_prc != decompression_precision) {
const auto scale_convert = std::make_shared<ov::op::v0::Convert>(scale_const, decompression_precision);
@@ -176,6 +186,11 @@ std::shared_ptr<ov::Node> initMatMulDecompressionSubgraph(const ov::Shape& weigh
ov::mark_as_decompression(last_node);
}
const bool insert_transpose = insert_transpose_node.value_or(transpose_weights);
+ if (extra_multiply) {
+ OPENVINO_ASSERT(decompression_multiply_type != DecompressionType::empty,
+ "Extra multiply is only supported when decompression_multiply_type is not empty.");
+ OPENVINO_ASSERT(!insert_transpose, "Extra multiply is not supported when insert_transpose is true.");
+ }
if (insert_transpose) {
const size_t rank = last_node->get_output_partial_shape(0).size();
std::vector<int> order(rank);
@@ -183,6 +198,8 @@ std::shared_ptr<ov::Node> initMatMulDecompressionSubgraph(const ov::Shape& weigh
std::swap(*order.rbegin(), *(order.rbegin() + 1));
auto transpose_constant = ov::opset10::Constant::create(ov::element::i32, {rank}, order);
last_node = std::make_shared<ov::opset10::Transpose>(last_node, transpose_constant);
+ } else if (extra_multiply) {
+ last_node = std::make_shared<ov::op::v1::Multiply>(last_node, scale_const);
}
return last_node;
}