OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[TRANSFORMATIONS] Fix NCHW/NHWC layout mismatch in ConvertWeightCompressedConv1x1ToMatmul (#37181)
Vladislav Golubev93e433ec2702
diff --git a/src/common/transformations/src/transformations/op_conversions/convert_weight_compressed_conv1x1_to_matmul.cpp b/src/common/transformations/src/transformations/op_conversions/convert_weight_compressed_conv1x1_to_matmul.cppindex d3bf679dd40..bcde1252d38 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_weight_compressed_conv1x1_to_matmul.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_weight_compressed_conv1x1_to_matmul.cpp@@ -65,7 +65,8 @@ ov::pass::ConvertWeightCompressedConv1x1ToMatmul::ConvertWeightCompressedConv1x1auto weight_reshape_m =ov::pass::pattern::wrap_type<ov::op::v1::Reshape>({weight_mult_m, ov::pass::pattern::any_input()});auto weight_input_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{weight_mult_m, weight_reshape_m});- auto conv1x1_m = ov::pass::pattern::wrap_type<ov::op::v1::Convolution>({a_m, weight_input_m});+ auto conv1x1_m =+ ov::pass::pattern::wrap_type<ov::op::v1::Convolution>({a_m, weight_input_m}, ov::pass::pattern::rank_equals(4));ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -340,9 +341,27 @@ ov::pass::ConvertWeightCompressedConv1x1ToMatmul::ConvertWeightCompressedConv1x1ov::copy_runtime_info(m.get_matched_nodes(), final_out);ov::replace_node(consumer_transpose, final_out);} else if (consumer_reshape) {- // Reshape consumer found - clone reshape with matmul output+ // final_out is NHWC (channel last), but Reshape does not reorder elements, so+ // consumer_reshape (built for the Convolution's NCHW output) needs NCHW input too.+ const auto& conv_out_pshape = conv1x1->get_output_partial_shape(0);+ std::shared_ptr<Node> reshape_input = final_out;+ // Skip the NCHW-restoring Transpose only when the spatial size H*W is statically 1: then+ // the NHWC [N, 1, 1, Cout] and NCHW [N, Cout, 1, 1] layouts have identical element order.+ // Otherwise (H*W > 1) final_out is NHWC [N, H, W, Cout] (the+ // MatMul preserves the activation's spatial dims), so a single Transpose [0, 3, 1, 2]+ // restores the NCHW order the matched Reshape was built for.+ const auto spatial_size = conv_out_pshape[2] * conv_out_pshape[3];+ if (!(spatial_size.is_static() && spatial_size.get_length() == 1)) {+ auto nhwc_to_nchw_order = std::make_shared<ov::op::v0::Constant>(ov::element::i32,+ ov::Shape{4},+ std::vector<int64_t>{0, 3, 1, 2});+ auto final_out_nchw = std::make_shared<ov::op::v1::Transpose>(final_out, nhwc_to_nchw_order);+ ov::copy_runtime_info(conv1x1, final_out_nchw);+ reshape_input = final_out_nchw;+ }+auto reshape_order = consumer_reshape->get_input_node_shared_ptr(1);- auto reshape_final = consumer_reshape->clone_with_new_inputs({final_out, reshape_order});+ auto reshape_final = consumer_reshape->clone_with_new_inputs({reshape_input, reshape_order});reshape_final->set_friendly_name(consumer_reshape->get_friendly_name());ov::copy_runtime_info(m.get_matched_nodes(), reshape_final);ov::replace_node(consumer_reshape, reshape_final);diff --git a/src/common/transformations/tests/op_conversions/convert_weight_compressed_conv1x1_to_matmul_test.cpp b/src/common/transformations/tests/op_conversions/convert_weight_compressed_conv1x1_to_matmul_test.cppindex 94b9b8ab158..773d8adacbe 100644--- a/src/common/transformations/tests/op_conversions/convert_weight_compressed_conv1x1_to_matmul_test.cpp+++ b/src/common/transformations/tests/op_conversions/convert_weight_compressed_conv1x1_to_matmul_test.cpp@@ -208,6 +208,10 @@ std::shared_ptr<ov::Model> gen_model_ref(const Conv1x1ToMatmulTestParams& p) {std::shared_ptr<ov::Node> out_node = current_node;if (p.activation_op_type == "Reshape" || p.activation_op_type == "None_Reshape") {+ // Here H = W = 1, so the NHWC MatMul output [N, 1, 1, Cout] and the NCHW order the matched+ // Reshape was built for [N, Cout, 1, 1] have identical element order. The transformation+ // therefore feeds the MatMul output directly into the matched Reshape without inserting any+ // NCHW-restoring Reshape/Transpose (those are only needed when H*W > 1).auto reshape_const = ov::opset1::Constant::create(ov::element::i32, ov::Shape{4}, {(int)input_batch, 1, 1, 15});out_node = std::make_shared<ov::opset1::Reshape>(out_node, reshape_const, false);}@@ -328,4 +332,131 @@ TEST_F(ConvertWeightCompressedConv1x1ToMatmulTest_Blocked, conv3x3) {};model = CreateConv3x3();}++// Regression test for the NCHW/NHWC layout mismatch when the Convolution output is consumed by a+// Reshape and the spatial size H*W > 1 (see PR #37133). This mirrors the self-attention projections+// of the machine-translation Transformer model that regressed: a weight-compressed 1x1 Convolution+// producing NCHW [1, Cout, 1, W] (W > 1) feeding a Reshape to [Cout, W].+//+// MatMul(transpose_b=true) produces channel-last output [N, H, W, Cout], while the Convolution it+// replaces produces channel-second NCHW [N, Cout, H, W]. Reshape never reorders elements, so the+// matched Reshape (built for the Convolution's NCHW output) must receive NCHW data.+class ConvertWeightCompressedConv1x1ToMatmulTest_ReshapeConsumerSpatial : public TransformationTestsF {+public:+ ConvertWeightCompressedConv1x1ToMatmulTest_ReshapeConsumerSpatial() {+ manager.register_pass<ov::pass::ConvertWeightCompressedConv1x1ToMatmul>();+ }+};++TEST_F(ConvertWeightCompressedConv1x1ToMatmulTest_ReshapeConsumerSpatial, conv1x1_reshape_consumer_spatial_gt_1) {+ const int Cin = 10;+ const int Cout = 15;+ const int W = 5; // spatial size > 1 - exposes the NHWC/NCHW mismatch++ {+ // input [1, 1, W, Cin] -> Transpose[0,3,1,2] -> conv input [1, Cin, 1, W]+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{1, 1, W, Cin});+ auto in_transpose_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{4}, {0, 3, 1, 2});+ auto act_node = std::make_shared<ov::op::v1::Transpose>(input, in_transpose_const);++ auto weights = ov::op::v0::Constant::create(ov::element::i4, ov::Shape{Cout, Cin, 1, 1}, {1});+ auto weights_convert = std::make_shared<ov::op::v0::Convert>(weights, ov::element::f16);+ auto scale = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{Cout, 1, 1, 1}, {1});+ auto mul = std::make_shared<ov::op::v1::Multiply>(weights_convert, scale);++ auto conv = std::make_shared<ov::op::v1::Convolution>(act_node,+ mul,+ ov::Strides{1, 1},+ ov::CoordinateDiff{0, 0},+ ov::CoordinateDiff{0, 0},+ ov::Strides{1, 1},+ ov::op::PadType::EXPLICIT);+ // conv output NCHW [1, Cout, 1, W] -> Reshape to [Cout, W]+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {Cout, W});+ auto reshape = std::make_shared<ov::op::v1::Reshape>(conv, reshape_const, false);++ model = std::make_shared<ov::Model>(ov::OutputVector{reshape}, ov::ParameterVector{input});+ }++ {+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{1, 1, W, Cin});++ // weights squeezed to 2D [Cout, Cin]+ auto weights = ov::op::v0::Constant::create(ov::element::i4, ov::Shape{Cout, Cin}, {1});+ auto weights_convert = std::make_shared<ov::op::v0::Convert>(weights, ov::element::f16);+ auto scale = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{Cout, 1}, {1});+ auto mul = std::make_shared<ov::op::v1::Multiply>(weights_convert, scale);++ // activation is used directly (input transpose is absorbed); MatMul(transpose_b=true)+ auto matmul = std::make_shared<ov::op::v0::MatMul>(input, mul, false, true); // -> [1, 1, W, Cout] NHWC++ // MatMul output is already NHWC [N, H, W, Cout], so a single Transpose [0, 3, 1, 2] restores NCHW+ auto nhwc_to_nchw_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{4}, {0, 3, 1, 2});+ auto nchw = std::make_shared<ov::op::v1::Transpose>(matmul, nhwc_to_nchw_const); // -> [1, Cout, 1, W]++ // matched Reshape to [Cout, W]+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {Cout, W});+ auto reshape = std::make_shared<ov::op::v1::Reshape>(nchw, reshape_const, false);++ model_ref = std::make_shared<ov::Model>(ov::OutputVector{reshape}, ov::ParameterVector{input});+ }+}++// Companion to conv1x1_reshape_consumer_spatial_gt_1 for the spatial size H*W == 1 case, which+// mirrors the gpt_oss Transformer self-attention projections: a weight-compressed 1x1 Convolution+// producing NCHW [1, Cout, 1, 1] whose output is consumed by a Reshape.+//+// When H*W == 1 the channel-last MatMul output [N, 1, 1, Cout] and the NCHW order the matched+// Reshape was built for [N, Cout, 1, 1] have identical element order, so no NCHW-restoring+// Reshape/Transpose is needed - the MatMul output must feed the matched Reshape directly. This+// guards against inserting the redundant no-op Reshape/Transpose pair (which is only required when+// H*W > 1, see conv1x1_reshape_consumer_spatial_gt_1).+TEST_F(ConvertWeightCompressedConv1x1ToMatmulTest_ReshapeConsumerSpatial, conv1x1_reshape_consumer_spatial_eq_1) {+ const int Cin = 10;+ const int Cout = 15;++ {+ // input [1, 1, 1, Cin] -> Transpose[0,3,1,2] -> conv input [1, Cin, 1, 1]+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{1, 1, 1, Cin});+ auto in_transpose_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{4}, {0, 3, 1, 2});+ auto act_node = std::make_shared<ov::op::v1::Transpose>(input, in_transpose_const);++ auto weights = ov::op::v0::Constant::create(ov::element::i4, ov::Shape{Cout, Cin, 1, 1}, {1});+ auto weights_convert = std::make_shared<ov::op::v0::Convert>(weights, ov::element::f16);+ auto scale = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{Cout, 1, 1, 1}, {1});+ auto mul = std::make_shared<ov::op::v1::Multiply>(weights_convert, scale);++ auto conv = std::make_shared<ov::op::v1::Convolution>(act_node,+ mul,+ ov::Strides{1, 1},+ ov::CoordinateDiff{0, 0},+ ov::CoordinateDiff{0, 0},+ ov::Strides{1, 1},+ ov::op::PadType::EXPLICIT);+ // conv output NCHW [1, Cout, 1, 1] -> Reshape to [1, Cout]+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, Cout});+ auto reshape = std::make_shared<ov::op::v1::Reshape>(conv, reshape_const, false);++ model = std::make_shared<ov::Model>(ov::OutputVector{reshape}, ov::ParameterVector{input});+ }++ {+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{1, 1, 1, Cin});++ // weights squeezed to 2D [Cout, Cin]+ auto weights = ov::op::v0::Constant::create(ov::element::i4, ov::Shape{Cout, Cin}, {1});+ auto weights_convert = std::make_shared<ov::op::v0::Convert>(weights, ov::element::f16);+ auto scale = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{Cout, 1}, {1});+ auto mul = std::make_shared<ov::op::v1::Multiply>(weights_convert, scale);++ // activation is used directly (input transpose is absorbed); MatMul(transpose_b=true)+ auto matmul = std::make_shared<ov::op::v0::MatMul>(input, mul, false, true); // -> [1, 1, 1, Cout] NHWC++ // H*W == 1: the MatMul output feeds the matched Reshape directly, no Reshape/Transpose pair.+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, Cout});+ auto reshape = std::make_shared<ov::op::v1::Reshape>(matmul, reshape_const, false);++ model_ref = std::make_shared<ov::Model>(ov::OutputVector{reshape}, ov::ParameterVector{input});+ }+}} // namespace ov::testdiff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/conv1x1_weight_compressed_to_matmul.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/conv1x1_weight_compressed_to_matmul.cppnew file mode 100644index 00000000000..b7177069241--- /dev/null+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/conv1x1_weight_compressed_to_matmul.cpp@@ -0,0 +1,62 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "common_test_utils/test_constants.hpp"+#include "subgraph_tests/conv1x1_weight_compressed_to_matmul.hpp"++namespace {+using ov::test::Conv1x1ExpectedOpCounts;+using ov::test::Conv1x1WeightCompressedShapeParams;+using ov::test::Conv1x1WeightCompressedToMatmulTest;+using ov::test::InputShape;++const std::vector<ov::element::Type> weights_precisions = {ov::element::i4, ov::element::i8};++const Conv1x1ExpectedOpCounts op_counts_1x1{{"Convolution", 0}, {"FullyConnected", 1}, {"Transpose", 0}, {"Reshape", 1}};++const InputShape transpose_in_1x1{{-1, 1, 1, 128}, {{1, 1, 1, 128}, {3, 1, 1, 128}}};+// input Transpose, H*W == 1: the output decoration does not change the (fully eliminated) layout ops.+INSTANTIATE_TEST_SUITE_P(+ smoke_Conv1x1WeightCompressedToMatmul_TransposeInput,+ Conv1x1WeightCompressedToMatmulTest,+ ::testing::Combine(::testing::Values(Conv1x1WeightCompressedShapeParams{transpose_in_1x1, 128}),+ ::testing::Values("Transpose"),+ ::testing::Values("Transpose", "Reshape"),+ ::testing::Values(ov::element::f32),+ ::testing::ValuesIn(weights_precisions),+ ::testing::Values(op_counts_1x1),+ ::testing::Values(ov::test::utils::DEVICE_CPU)),+ Conv1x1WeightCompressedToMatmulTest::getTestCaseName);++const InputShape reshape_in_1x1{{-1, 128}, {{1, 128}, {3, 128}}};++INSTANTIATE_TEST_SUITE_P(+ smoke_Conv1x1WeightCompressedToMatmul_ReshapeInput,+ Conv1x1WeightCompressedToMatmulTest,+ ::testing::Combine(::testing::Values(Conv1x1WeightCompressedShapeParams{reshape_in_1x1, 128}),+ ::testing::Values("Reshape"),+ ::testing::Values("Reshape"),+ ::testing::Values(ov::element::f32),+ ::testing::ValuesIn(weights_precisions),+ ::testing::Values(op_counts_1x1),+ ::testing::Values(ov::test::utils::DEVICE_CPU)),+ Conv1x1WeightCompressedToMatmulTest::getTestCaseName);++// H*W > 1: a 1x1 Convolution producing [N, 128, 1, 55] consumed by a Reshape. Transpose after MatMul is needed+const InputShape transpose_in_1x55{{-1, 1, 55, 128}, {{1, 1, 55, 128}, {3, 1, 55, 128}}};+const Conv1x1ExpectedOpCounts op_counts_1xW{{"Convolution", 0}, {"FullyConnected", 1}, {"Transpose", 1}, {"Reshape", 1}};++INSTANTIATE_TEST_SUITE_P(+ smoke_Conv1x1WeightCompressedToMatmul_SpatialGt1,+ Conv1x1WeightCompressedToMatmulTest,+ ::testing::Combine(::testing::Values(Conv1x1WeightCompressedShapeParams{transpose_in_1x55, 128}),+ ::testing::Values("Transpose"),+ ::testing::Values("Reshape"),+ ::testing::Values(ov::element::f32),+ ::testing::ValuesIn(weights_precisions),+ ::testing::Values(op_counts_1xW),+ ::testing::Values(ov::test::utils::DEVICE_CPU)),+ Conv1x1WeightCompressedToMatmulTest::getTestCaseName);++} // namespacediff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/conv1x1_weight_compressed_to_matmul.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/conv1x1_weight_compressed_to_matmul.cppnew file mode 100644index 00000000000..8db44c4e286--- /dev/null+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/conv1x1_weight_compressed_to_matmul.cpp@@ -0,0 +1,62 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "common_test_utils/test_constants.hpp"+#include "subgraph_tests/conv1x1_weight_compressed_to_matmul.hpp"++namespace {+using ov::test::Conv1x1ExpectedOpCounts;+using ov::test::Conv1x1WeightCompressedShapeParams;+using ov::test::Conv1x1WeightCompressedToMatmulTest;+using ov::test::InputShape;++const std::vector<ov::element::Type> weights_precisions = {ov::element::i4, ov::element::i8};++const Conv1x1ExpectedOpCounts op_counts_1x1{{"Convolution", 0}, {"FullyConnected", 1}, {"Transpose", 0}, {"Reshape", 1}};++const InputShape transpose_in_1x1{{-1, 1, 1, 128}, {{1, 1, 1, 128}, {3, 1, 1, 128}}};+// input Transpose, H*W == 1: the output decoration does not change the (fully eliminated) layout ops.+INSTANTIATE_TEST_SUITE_P(+ smoke_Conv1x1WeightCompressedToMatmul_TransposeInput,+ Conv1x1WeightCompressedToMatmulTest,+ ::testing::Combine(::testing::Values(Conv1x1WeightCompressedShapeParams{transpose_in_1x1, 128}),+ ::testing::Values("Transpose"),+ ::testing::Values("Transpose", "Reshape"),+ ::testing::Values(ov::element::f32),+ ::testing::ValuesIn(weights_precisions),+ ::testing::Values(op_counts_1x1),+ ::testing::Values(ov::test::utils::DEVICE_GPU)),+ Conv1x1WeightCompressedToMatmulTest::getTestCaseName);++const InputShape reshape_in_1x1{{-1, 128}, {{1, 128}, {3, 128}}};++INSTANTIATE_TEST_SUITE_P(+ smoke_Conv1x1WeightCompressedToMatmul_ReshapeInput,+ Conv1x1WeightCompressedToMatmulTest,+ ::testing::Combine(::testing::Values(Conv1x1WeightCompressedShapeParams{reshape_in_1x1, 128}),+ ::testing::Values("Reshape"),+ ::testing::Values("Reshape"),+ ::testing::Values(ov::element::f32),+ ::testing::ValuesIn(weights_precisions),+ ::testing::Values(op_counts_1x1),+ ::testing::Values(ov::test::utils::DEVICE_GPU)),+ Conv1x1WeightCompressedToMatmulTest::getTestCaseName);++// H*W > 1: a 1x1 Convolution producing [N, 128, 1, 55] consumed by a Reshape. Transpose after MatMul is needed (Permute type is used in GPU)+const InputShape transpose_in_1x55{{-1, 1, 55, 128}, {{1, 1, 55, 128}, {3, 1, 55, 128}}};+const Conv1x1ExpectedOpCounts op_counts_1xW{{"Convolution", 0}, {"FullyConnected", 1}, {"Permute", 1}, {"Reshape", 1}};++INSTANTIATE_TEST_SUITE_P(+ smoke_Conv1x1WeightCompressedToMatmul_SpatialGt1,+ Conv1x1WeightCompressedToMatmulTest,+ ::testing::Combine(::testing::Values(Conv1x1WeightCompressedShapeParams{transpose_in_1x55, 128}),+ ::testing::Values("Transpose"),+ ::testing::Values("Reshape"),+ ::testing::Values(ov::element::f32),+ ::testing::ValuesIn(weights_precisions),+ ::testing::Values(op_counts_1xW),+ ::testing::Values(ov::test::utils::DEVICE_GPU)),+ Conv1x1WeightCompressedToMatmulTest::getTestCaseName);++} // namespacediff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/conv1x1_weight_compressed_to_matmul.hpp b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/conv1x1_weight_compressed_to_matmul.hppnew file mode 100644index 00000000000..255ab9d5c1c--- /dev/null+++ b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/conv1x1_weight_compressed_to_matmul.hpp@@ -0,0 +1,54 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <map>+#include <string>+#include <tuple>++#include "openvino/core/type/element_type.hpp"+#include "shared_test_classes/base/ov_subgraph.hpp"++namespace ov {+namespace test {++// Activation Parameter shape (dynamic + static test shapes) plus the Convolution output channels Cout.+// The input channels and spatial size are derived from data_shape and the input decoration.+struct Conv1x1WeightCompressedShapeParams {+ InputShape data_shape;+ size_t channels_out;+};++// Expected runtime op-type counts (ov::exec_model_info::LAYER_TYPE) after compilation; only the listed+// types are asserted. Runtime op names are plugin specific, so the map is supplied per instantiation.+using Conv1x1ExpectedOpCounts = std::map<std::string, size_t>;++// A decoration is one of "None", "Transpose", "Reshape" ("Reshape" on the input side requires H*W == 1).+using Conv1x1WeightCompressedToMatmulParams = std::tuple<+ Conv1x1WeightCompressedShapeParams, // geometry+ std::string, // input decoration+ std::string, // output decoration+ ov::element::Type, // activation precision+ ov::element::Type, // compressed weights precision+ Conv1x1ExpectedOpCounts, // expected runtime op-type counts+ std::string // target device+>;++class Conv1x1WeightCompressedToMatmulTest+ : public testing::WithParamInterface<Conv1x1WeightCompressedToMatmulParams>,+ virtual public ov::test::SubgraphBaseTest {+public:+ static std::string getTestCaseName(const testing::TestParamInfo<Conv1x1WeightCompressedToMatmulParams>& obj);++protected:+ void SetUp() override;+ void validate() override;++private:+ Conv1x1ExpectedOpCounts expected_op_counts_;+};++} // namespace test+} // namespace ovdiff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/conv1x1_weight_compressed_to_matmul.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/conv1x1_weight_compressed_to_matmul.hppnew file mode 100644index 00000000000..7efc072276c--- /dev/null+++ b/src/tests/functional/plugin/shared/include/subgraph_tests/conv1x1_weight_compressed_to_matmul.hpp@@ -0,0 +1,17 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "shared_test_classes/subgraph/conv1x1_weight_compressed_to_matmul.hpp"++namespace ov {+namespace test {++TEST_P(Conv1x1WeightCompressedToMatmulTest, Inference) {+ run();+}++} // namespace test+} // namespace ovdiff --git a/src/tests/functional/plugin/shared/src/subgraph/conv1x1_weight_compressed_to_matmul.cpp b/src/tests/functional/plugin/shared/src/subgraph/conv1x1_weight_compressed_to_matmul.cppnew file mode 100644index 00000000000..bc643663c68--- /dev/null+++ b/src/tests/functional/plugin/shared/src/subgraph/conv1x1_weight_compressed_to_matmul.cpp@@ -0,0 +1,122 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "shared_test_classes/subgraph/conv1x1_weight_compressed_to_matmul.hpp"++#include <sstream>++#include "common_test_utils/ov_tensor_utils.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/convolution.hpp"+#include "openvino/op/multiply.hpp"+#include "openvino/op/parameter.hpp"+#include "openvino/op/reshape.hpp"+#include "openvino/op/result.hpp"+#include "openvino/op/transpose.hpp"+#include "openvino/runtime/properties.hpp"++namespace ov {+namespace test {++namespace {+const std::string DECOR_NONE = "None";+const std::string DECOR_TRANSPOSE = "Transpose";+const std::string DECOR_RESHAPE = "Reshape";++void validate_decoration(const std::string& decoration) {+ OPENVINO_ASSERT(decoration == DECOR_NONE || decoration == DECOR_TRANSPOSE || decoration == DECOR_RESHAPE,+ "Unsupported conv1x1 decoration: ",+ decoration);+}+} // namespace++std::string Conv1x1WeightCompressedToMatmulTest::getTestCaseName(+ const testing::TestParamInfo<Conv1x1WeightCompressedToMatmulParams>& obj) {+ const auto& [shape_params, in_decoration, out_decoration, act_prec, weights_prec, expected_op_counts, device] =+ obj.param;++ std::ostringstream result;+ result << "IS=" << shape_params.data_shape << "_";+ result << "Cout=" << shape_params.channels_out << "_";+ result << "in=" << in_decoration << "_out=" << out_decoration << "_";+ result << "actPrec=" << act_prec << "_wPrec=" << weights_prec << "_device=" << device;+ return result.str();+}++void Conv1x1WeightCompressedToMatmulTest::SetUp() {+ const auto& [shape_params, in_decoration, out_decoration, act_prec, weights_prec, expected_op_counts, device] =+ GetParam();+ targetDevice = device;+ expected_op_counts_ = expected_op_counts;+ abs_threshold = 0.05f;+ rel_threshold = 0.01f;+ validate_decoration(in_decoration);+ validate_decoration(out_decoration);++ init_input_shapes({shape_params.data_shape});+ const auto& param_pshape = inputDynamicShapes[0];++ // Cin is the Convolution input channel: last dim for the Transpose input layout, dim 1 otherwise.+ const auto Cin = (in_decoration == DECOR_TRANSPOSE ? param_pshape[param_pshape.size() - 1] : param_pshape[1]).get_length();+ OPENVINO_ASSERT(in_decoration != DECOR_RESHAPE || param_pshape.size() == 2,+ "Reshape input decoration expects a 2D [N, Cin] activation");++ auto param = std::make_shared<ov::op::v0::Parameter>(act_prec, param_pshape);++ std::shared_ptr<ov::Node> conv_input = param;+ if (in_decoration == DECOR_TRANSPOSE) {+ auto order = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{4}, {0, 3, 1, 2});+ conv_input = std::make_shared<ov::op::v1::Transpose>(param, order);+ } else if (in_decoration == DECOR_RESHAPE) {+ auto pattern = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{4}, {0, static_cast<int>(Cin), 1, 1});+ conv_input = std::make_shared<ov::op::v1::Reshape>(param, pattern, true);+ }++ const int seed = 1;+ const int up_to = weights_prec == ov::element::u2 ? 3 : (weights_prec == ov::element::i4 ? 7 : 15);+ const int start_from = weights_prec == ov::element::u2 ? 0 : 1;+ auto weights_tensor = ov::test::utils::create_and_fill_tensor(+ weights_prec,+ ov::Shape{shape_params.channels_out, static_cast<size_t>(Cin), 1, 1},+ ov::test::utils::InputGenerateData(start_from, up_to, 1, seed));+ auto weights = std::make_shared<ov::op::v0::Constant>(weights_tensor);+ auto weights_convert = std::make_shared<ov::op::v0::Convert>(weights, act_prec);+ auto scale_tensor = ov::test::utils::create_and_fill_tensor_real_distribution(+ act_prec, ov::Shape{shape_params.channels_out, 1, 1, 1}, 0.001f, 0.01f, seed);+ auto scale = std::make_shared<ov::op::v0::Constant>(scale_tensor);+ auto weights_dequant = std::make_shared<ov::op::v1::Multiply>(weights_convert, scale);++ auto conv = std::make_shared<ov::op::v1::Convolution>(conv_input,+ weights_dequant,+ ov::Strides{1, 1},+ ov::CoordinateDiff{0, 0},+ ov::CoordinateDiff{0, 0},+ ov::Strides{1, 1},+ ov::op::PadType::EXPLICIT);++ std::shared_ptr<ov::Node> out_node = conv;+ if (out_decoration == DECOR_TRANSPOSE) {+ auto order = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{4}, {0, 2, 3, 1});+ out_node = std::make_shared<ov::op::v1::Transpose>(conv, order);+ } else if (out_decoration == DECOR_RESHAPE) {+ auto pattern = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {0, -1});+ out_node = std::make_shared<ov::op::v1::Reshape>(conv, pattern, true);+ }++ auto result = std::make_shared<ov::op::v0::Result>(out_node);+ function = std::make_shared<ov::Model>(ov::ResultVector{result},+ ov::ParameterVector{param},+ "Conv1x1WeightCompressedToMatmul");+}++void Conv1x1WeightCompressedToMatmulTest::validate() {+ SubgraphBaseTest::validate();+ for (const auto& [layer_type, expected_count] : expected_op_counts_) {+ CheckNumberOfNodesWithType(compiledModel, layer_type, expected_count);+ }+}++} // namespace test+} // namespace ov