From 2654ef9891beb090d3a49e761bc689c9a63a35bf Mon Sep 17 00:00:00 2001 From: Vladislav Golubev Date: Wed, 26 Jun 2024 15:31:11 +0200 Subject: [PATCH] Added FC precisions check in MatMulDecompressConvertTest --- .../src/matmul_decompress_convert.cpp | 92 +++++++------------ .../tests/functional/utils/cpu_test_utils.cpp | 44 +++++---- .../tests/functional/utils/cpu_test_utils.hpp | 5 + 3 files changed, 64 insertions(+), 77 deletions(-) diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/matmul_decompress_convert.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/matmul_decompress_convert.cpp index e08dd30624930d..03ac44b199e1b1 100644 --- a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/matmul_decompress_convert.cpp +++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/matmul_decompress_convert.cpp @@ -100,24 +100,11 @@ class MatMulDecompressConvertTest : public testing::WithParamInterface std::string { - auto it = rtInfo.find(paramName); - OPENVINO_ASSERT(rtInfo.end() != it); - return it->second.as(); - }; - - const auto execFunction = compiledModel.get_runtime_model(); - ASSERT_NE(nullptr, execFunction); - for (const auto& fcNode : execFunction->get_ops()) { - if (getExecValue(fcNode->get_rt_info(), ov::exec_model_info::LAYER_TYPE) == "FullyConnected") { - const auto& constNode = fcNode->get_input_node_shared_ptr(1); - ov::element::Type expectedType( - getExecValue(constNode->get_rt_info(), ov::exec_model_info::OUTPUT_PRECISIONS)); - ASSERT_EQ(expectedType, expectedWeiElemType); - } - } - } - void SetUp() override { targetDevice = ov::test::utils::DEVICE_CPU; @@ -196,23 +164,23 @@ class MatMulDecompressConvertTest : public testing::WithParamInterfacesecond.as() == ov::element::bf16) { - convertOutType = inType = outType = netType = ElementType::bf16; + netType = ElementType::bf16; weiConstElemType = (weiConstElemType != ElementType::f32) ? weiConstElemType : ElementType::bf16; - } else { - inType = outType = netType; + // Reorder between parameter and FullyConnected + // Note: reorder between FC and Result is not needed since FC primitive supports f32 output natively + reorderCount++; } std::string cpuNodeType = "FullyConnected"; - selectedType = makeSelectedTypeStr(selectedType, outType); + selectedType = makeSelectedTypeStr(selectedType, netType); ov::ParameterVector params{std::make_shared(inType, inShapeA)}; std::shared_ptr inputB = ov::test::utils::make_constant(weiConstElemType, inShapeB.get_shape()); - if (weiConstElemType == ElementType::f16 || weiConstElemType == ElementType::bf16) { - inputB = std::make_shared(inputB, convertOutType); + if (weiConstElemType != inType) { + inputB = std::make_shared(inputB, inType); mark_as_decompression(inputB); } expectedWeiConstElemType = weiConstElemType; @@ -223,17 +191,21 @@ class MatMulDecompressConvertTest : public testing::WithParamInterface> inputShapes3D = { {{{-1, -1, -1}, {{1, 2, 3}, {1, 5, 3}}}, {{1, 3, 4}, {{1, 3, 4}, {1, 3, 4}}}}, }; -ov::AnyMap emptyConfig = {/* empty config */}; - std::vector filter_additional_config_bf16() { std::vector additionalConfig; - if (ov::with_cpu_x86_avx512_core()) { + if (ov::with_cpu_x86_bfloat16()) { additionalConfig.push_back({{ov::hint::inference_precision(ov::element::bf16)}}); } return additionalConfig; @@ -303,7 +273,7 @@ std::vector filter_specific_params_bf16() { const auto testParams2D_FP32_smoke = ::testing::Combine(::testing::ValuesIn(inputShapes2D), ::testing::ValuesIn(transposeParams), ::testing::Values(ElementType::f32), - ::testing::Values(emptyConfig), + ::testing::Values(CPUTestUtils::empty_plugin_config), ::testing::ValuesIn(filter_specific_params(true))); INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_FP32, @@ -314,7 +284,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_FP32, const auto testParams2D_smoke = ::testing::Combine(::testing::ValuesIn(inputShapes2D), ::testing::ValuesIn(transposeParams), ::testing::Values(ElementType::f16, ElementType::bf16), - ::testing::Values(emptyConfig), + ::testing::Values(CPUTestUtils::empty_plugin_config), ::testing::ValuesIn(filter_specific_params(false))); INSTANTIATE_TEST_SUITE_P(smoke_FC_2D, @@ -336,7 +306,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_BF16, const auto testParams3D_FP32_smoke = ::testing::Combine(::testing::ValuesIn(inputShapes3D), ::testing::ValuesIn(transposeParams), ::testing::Values(ElementType::f32), - ::testing::Values(emptyConfig), + ::testing::Values(CPUTestUtils::empty_plugin_config), ::testing::ValuesIn(filter_specific_params(true))); INSTANTIATE_TEST_SUITE_P(smoke_FC_3D_FP32, @@ -347,7 +317,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_FC_3D_FP32, const auto testParams3D_smoke = ::testing::Combine(::testing::ValuesIn(inputShapes3D), ::testing::ValuesIn(transposeParams), ::testing::Values(ElementType::f16, ElementType::bf16), - ::testing::Values(emptyConfig), + ::testing::Values(CPUTestUtils::empty_plugin_config), ::testing::ValuesIn(filter_specific_params(false))); INSTANTIATE_TEST_SUITE_P(smoke_FC_3D, @@ -461,26 +431,26 @@ class MatMulDecompressConvertTest2 : public MatMulDecompressConvertTest { configuration.insert(additionalConfig.begin(), additionalConfig.end()); - ElementType netType = ElementType::f32; - ElementType convertOutType = ElementType::f32; + inType = outType = netType = ElementType::f32; auto it = additionalConfig.find(ov::hint::inference_precision.name()); if (it != additionalConfig.end() && it->second.as() == ov::element::bf16) { - convertOutType = inType = outType = netType = ElementType::bf16; + netType = ElementType::bf16; weiConstElemType = (weiConstElemType != ElementType::f32) ? weiConstElemType : ElementType::bf16; - } else { - inType = outType = netType; + // Reorder between parameter and FullyConnected + // Note: reorder between FC and Result is not needed since FC primitive supports f32 output natively + reorderCount++; } std::string cpuNodeType = "FullyConnected"; - selectedType = makeSelectedTypeStr(selectedType, outType); + selectedType = makeSelectedTypeStr(selectedType, netType); ov::ParameterVector params; for (auto&& shape : {inShapeFC0, inShapeFC1}) { params.push_back(std::make_shared(inType, shape)); } std::shared_ptr inputWeights = ov::test::utils::make_constant(weiConstElemType, inShapeWeights.get_shape()); - if (weiConstElemType == ElementType::f16) { - inputWeights = std::make_shared(inputWeights, convertOutType); + if (weiConstElemType != inType) { + inputWeights = std::make_shared(inputWeights, inType); mark_as_decompression(inputWeights); } expectedWeiConstElemType = weiConstElemType; @@ -506,7 +476,7 @@ const auto testParams2D_FP16_2_smoke = ::testing::Combine(::testing::Values(static_shapes_to_test_representation({{2, 3}, {2, 3}, {3, 4}})), ::testing::Values(std::pair{false, true}), ::testing::Values(ElementType::f16), - ::testing::Values(emptyConfig), + ::testing::Values(CPUTestUtils::empty_plugin_config), ::testing::ValuesIn(filter_specific_params(false))); INSTANTIATE_TEST_SUITE_P(smoke_FC_2D_FP16_2, diff --git a/src/plugins/intel_cpu/tests/functional/utils/cpu_test_utils.cpp b/src/plugins/intel_cpu/tests/functional/utils/cpu_test_utils.cpp index f3fde176331885..c8695dfdcbf153 100644 --- a/src/plugins/intel_cpu/tests/functional/utils/cpu_test_utils.cpp +++ b/src/plugins/intel_cpu/tests/functional/utils/cpu_test_utils.cpp @@ -118,6 +118,12 @@ ov::PrimitivesPriority CPUTestsBase::impls2primProiority(const std::vectorsecond.as(); +} + void CPUTestsBase::CheckPluginRelatedResults(const ov::CompiledModel& execNet, const std::set& nodeType) const { if (!execNet || nodeType.empty()) @@ -137,11 +143,6 @@ void CPUTestsBase::CheckPluginRelatedResultsImpl(const std::shared_ptrget_ops()) { const auto& rtInfo = node->get_rt_info(); - auto getExecValue = [&rtInfo](const std::string& paramName) -> std::string { - auto it = rtInfo.find(paramName); - OPENVINO_ASSERT(rtInfo.end() != it); - return it->second.as(); - }; auto getExecValueOutputsLayout = [](const std::shared_ptr& node) -> std::string { auto rtInfo = node->get_rt_info(); auto it = rtInfo.find(ov::exec_model_info::OUTPUT_LAYOUTS); @@ -162,7 +163,7 @@ void CPUTestsBase::CheckPluginRelatedResultsImpl(const std::shared_ptrget_input_size()); ASSERT_LE(outFmts.size(), node->get_output_size()); for (size_t i = 0; i < inFmts.size(); i++) { @@ -207,7 +208,7 @@ void CPUTestsBase::CheckPluginRelatedResultsImpl(const std::shared_ptrget_output_partial_shape(i); if (should_be_skipped(shape, outFmts[i])) @@ -215,7 +216,7 @@ void CPUTestsBase::CheckPluginRelatedResultsImpl(const std::shared_ptr func ASSERT_NE(nullptr, function); size_t actualNodeCount = 0; for (const auto& node : function->get_ops()) { - const auto& rtInfo = node->get_rt_info(); - auto getExecValue = [&rtInfo](const std::string& paramName) -> std::string { - auto it = rtInfo.find(paramName); - OPENVINO_ASSERT(rtInfo.end() != it); - return it->second.as(); - }; - - if (nodeTypes.count(getExecValue(ov::exec_model_info::LAYER_TYPE))) { + if (nodeTypes.count(getExecValue(node->get_rt_info(), ov::exec_model_info::LAYER_TYPE))) { actualNodeCount++; } } @@ -471,4 +465,22 @@ void CheckNumberOfNodesWithType(const ov::CompiledModel& compiledModel, size_t expectedCount) { CheckNumberOfNodesWithTypes(compiledModel, {nodeType}, expectedCount); } + +void CheckNodePrecisionsWithType(const ov::CompiledModel& compiledModel, + const std::string& nodeType, + ov::element::TypeVector&& inPrecisions, + ov::element::TypeVector&& outPrecisions) { + const auto function = compiledModel.get_runtime_model(); + ASSERT_NE(nullptr, function); + for (const auto& node : function->get_ops()) { + if (getExecValue(node->get_rt_info(), ov::exec_model_info::LAYER_TYPE) == nodeType) { + ASSERT_EQ(inPrecisions.size(), node->get_input_size()); + ASSERT_EQ(outPrecisions.size(), node->get_output_size()); + for (size_t i = 0; i < inPrecisions.size(); ++i) + ASSERT_EQ(inPrecisions[i], node->get_input_element_type(i)) << "i = " << i; + for (size_t i = 0; i < outPrecisions.size(); ++i) + ASSERT_EQ(outPrecisions[i], node->get_output_element_type(i)) << "i = " << i; + } + } +} } // namespace CPUTestUtils diff --git a/src/plugins/intel_cpu/tests/functional/utils/cpu_test_utils.hpp b/src/plugins/intel_cpu/tests/functional/utils/cpu_test_utils.hpp index 2a15f89c72ad85..c7c48cdf936567 100644 --- a/src/plugins/intel_cpu/tests/functional/utils/cpu_test_utils.hpp +++ b/src/plugins/intel_cpu/tests/functional/utils/cpu_test_utils.hpp @@ -182,4 +182,9 @@ void CheckNumberOfNodesWithType(const ov::CompiledModel& compiledModel, void CheckNumberOfNodesWithTypes(const ov::CompiledModel& compiledModel, const std::unordered_set& nodeTypes, size_t expectedCount); + +void CheckNodePrecisionsWithType(const ov::CompiledModel& compiledModel, + const std::string& nodeType, + ov::element::TypeVector&& inPrecisions, + ov::element::TypeVector&& outPrecisions); } // namespace CPUTestUtils