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
[Snippets][CPU] Add transpose MatMul precision coverage (#38862)
Arseniy Obolenskiyf1a4a8a861a0
diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/transpose_matmul.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/transpose_matmul.cppindex 2d23cbd8a64..3955f71a1c0 100644--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/transpose_matmul.cpp+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/transpose_matmul.cpp@@ -176,6 +176,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_FullyConnected, TransposeMatMul,namespace explicit_transpose {static inline std::vector<std::vector<element::Type>> precisions(bool only_fp32 = true) {std::vector<std::vector<element::Type>> prc = precision_f32(2);+#ifndef SNIPPETS_LIBXSMM_TPPif (!only_fp32) {auto quant = quantized_precisions_if_supported();std::copy(quant.begin(), quant.end(), std::back_inserter(prc));@@ -184,6 +185,7 @@ static inline std::vector<std::vector<element::Type>> precisions(bool only_fp32auto halffloat = precision_fp16_if_supported(2);std::copy(halffloat.begin(), halffloat.end(), std::back_inserter(prc));}+#endifreturn prc;}@@ -191,7 +193,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_ExplicitTransposeMatMul, ExplicitTranspo::testing::Combine(::testing::ValuesIn(SNIPPETS_TESTS_STATIC_SHAPES({{1, 2, 69, 43}, {2, 49, 2, 43}})),::testing::Values(1), // Transpose on second input- ::testing::ValuesIn(precisions()),+ ::testing::ValuesIn(precisions(false)),::testing::Values(MatMulType::MatMul),::testing::Values(1), // Subgraph;::testing::Values(1), // Tokenized MatMul+Bias@@ -219,7 +221,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_TransposeMatMulBias, ExplicitTransposeMa::testing::Combine(::testing::ValuesIn(SNIPPETS_TESTS_STATIC_SHAPES({{1, 2, 69, 43}, {2, 49, 2, 43}, {1, 1, 69, 49}})),::testing::Values(1), // Transpose on second input- ::testing::ValuesIn(precisions()),+ ::testing::ValuesIn(precisions(false)),::testing::Values(MatMulType::MatMul),::testing::Values(1), // Subgraph;::testing::Values(1), // Tokenized MatMul+Bias@@ -248,4 +250,4 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_DynTransposeMatMulBias, ExplicitTranspos} // namespace} // namespace snippets} // namespace test-} // namespace ov\ No newline at end of file+} // namespace ovdiff --git a/src/tests/functional/plugin/shared/src/snippets/transpose_matmul.cpp b/src/tests/functional/plugin/shared/src/snippets/transpose_matmul.cppindex 41f1008b4cd..c66f8a32f5c 100644--- a/src/tests/functional/plugin/shared/src/snippets/transpose_matmul.cpp+++ b/src/tests/functional/plugin/shared/src/snippets/transpose_matmul.cpp@@ -71,11 +71,11 @@ std::shared_ptr<MatMulFunctionBase> TransposeMatMulFQ::get_builder(const std::ve}std::shared_ptr<MatMulFunctionBase> ExplicitTransposeMatMul::get_builder(const std::vector<ov::element::Type>& types) {- return std::make_shared<TransposeMatMulFunction>(inputDynamicShapes);+ return std::make_shared<TransposeMatMulFunction>(inputDynamicShapes, types);}std::shared_ptr<MatMulFunctionBase> ExplicitTransposeMatMulBias::get_builder(const std::vector<ov::element::Type>& types) {- return std::make_shared<TransposeMatMulBiasFunction>(inputDynamicShapes);+ return std::make_shared<TransposeMatMulBiasFunction>(inputDynamicShapes, types);}TEST_P(TransposeMatMul, CompareWithRefImpl) {diff --git a/src/tests/ov_helpers/ov_snippets_models/include/subgraph_matmul.hpp b/src/tests/ov_helpers/ov_snippets_models/include/subgraph_matmul.hppindex cb6531f5b0a..ede02b58890 100644--- a/src/tests/ov_helpers/ov_snippets_models/include/subgraph_matmul.hpp+++ b/src/tests/ov_helpers/ov_snippets_models/include/subgraph_matmul.hpp@@ -152,7 +152,9 @@ protected:class TransposeMatMulFunction : public MatMulFunctionBase {public:- explicit TransposeMatMulFunction(const std::vector<PartialShape>& inputShapes) : MatMulFunctionBase(inputShapes, MatMulType::MatMul) {+ explicit TransposeMatMulFunction(const std::vector<PartialShape>& inputShapes,+ const std::vector<ov::element::Type>& precisions)+ : MatMulFunctionBase(inputShapes, MatMulType::MatMul, precisions) {OPENVINO_ASSERT(input_shapes.size() == 2, "Got invalid number of input shapes");}protected:@@ -161,7 +163,9 @@ protected:class TransposeMatMulBiasFunction : public MatMulFunctionBase {public:- explicit TransposeMatMulBiasFunction(const std::vector<PartialShape>& inputShapes) : MatMulFunctionBase(inputShapes, MatMulType::MatMul) {+ explicit TransposeMatMulBiasFunction(const std::vector<PartialShape>& inputShapes,+ const std::vector<ov::element::Type>& precisions)+ : MatMulFunctionBase(inputShapes, MatMulType::MatMul, precisions) {OPENVINO_ASSERT(input_shapes.size() == 3, "Got invalid number of input shapes");}protected:diff --git a/src/tests/ov_helpers/ov_snippets_models/src/subgraph_matmul.cpp b/src/tests/ov_helpers/ov_snippets_models/src/subgraph_matmul.cppindex 942145edb8d..db5181a8b9a 100644--- a/src/tests/ov_helpers/ov_snippets_models/src/subgraph_matmul.cpp+++ b/src/tests/ov_helpers/ov_snippets_models/src/subgraph_matmul.cpp@@ -262,20 +262,39 @@ std::shared_ptr<ov::Model> Transpose0213MatMulFunction::initOriginal() const {}std::shared_ptr<ov::Model> TransposeMatMulFunction::initOriginal() const {- auto data0 = std::make_shared<op::v0::Parameter>(precision, input_shapes[0]);- auto data1 = std::make_shared<op::v0::Parameter>(precision, input_shapes[1]);+ auto data0 = std::make_shared<op::v0::Parameter>(precisions[0], input_shapes[0]);+ auto data1 = std::make_shared<op::v0::Parameter>(precisions[1], input_shapes[1]);auto const_order = std::make_shared<op::v0::Constant>(ov::element::i32, Shape {4}, std::vector<int>{0, 2, 3, 1});auto transpose = std::make_shared<op::v1::Transpose>(data1, const_order);- auto matmul = std::make_shared<op::v0::MatMul>(data0, transpose);+ std::shared_ptr<Node> matmul;+ if (precisions[1] == ov::element::i8) {+ matmul = std::make_shared<op::TypeRelaxed<op::v0::MatMul>>(+ std::vector<element::Type>{ov::element::f32, element::f32},+ std::vector<element::Type>{element::f32},+ ov::op::TemporaryReplaceOutputType(data0, element::f32).get(),+ ov::op::TemporaryReplaceOutputType(transpose, element::f32).get());+ } else {+ matmul = std::make_shared<op::v0::MatMul>(data0, transpose);+ }return std::make_shared<ov::Model>(OutputVector{matmul}, ParameterVector{data0, data1});}std::shared_ptr<ov::Model> TransposeMatMulBiasFunction::initOriginal() const {- auto data0 = std::make_shared<op::v0::Parameter>(precision, input_shapes[0]);- auto data1 = std::make_shared<op::v0::Parameter>(precision, input_shapes[1]);- auto data2 = std::make_shared<op::v0::Parameter>(precision, input_shapes[2]);+ auto data0 = std::make_shared<op::v0::Parameter>(precisions[0], input_shapes[0]);+ auto data1 = std::make_shared<op::v0::Parameter>(precisions[1], input_shapes[1]);+ const auto bias_precision = precisions[1] == ov::element::i8 ? ov::element::f32 : precisions[1];+ auto data2 = std::make_shared<op::v0::Parameter>(bias_precision, input_shapes[2]);auto const_order = std::make_shared<op::v0::Constant>(ov::element::i32, Shape {4}, std::vector<int>{0, 2, 3, 1});auto transpose = std::make_shared<op::v1::Transpose>(data1, const_order);- auto matmul = std::make_shared<op::v0::MatMul>(data0, transpose);+ std::shared_ptr<Node> matmul;+ if (precisions[1] == ov::element::i8) {+ matmul = std::make_shared<op::TypeRelaxed<op::v0::MatMul>>(+ std::vector<element::Type>{ov::element::f32, element::f32},+ std::vector<element::Type>{element::f32},+ ov::op::TemporaryReplaceOutputType(data0, element::f32).get(),+ ov::op::TemporaryReplaceOutputType(transpose, element::f32).get());+ } else {+ matmul = std::make_shared<op::v0::MatMul>(data0, transpose);+ }auto bias = std::make_shared<op::v1::Add>(matmul, data2);return std::make_shared<ov::Model>(OutputVector{bias}, ParameterVector{data0, data1, data2});}