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
[CPU][BF16] Keep certain input integer subgraphs in the original precision (#32739)
Maksim Kutakov89956b264df8
diff --git a/src/plugins/intel_cpu/src/graph.cpp b/src/plugins/intel_cpu/src/graph.cppindex 1c2cee63aea..b2d3548fcf3 100644--- a/src/plugins/intel_cpu/src/graph.cpp+++ b/src/plugins/intel_cpu/src/graph.cpp@@ -51,6 +51,7 @@#include "nodes/input.h"#include "nodes/memory.hpp"#include "nodes/reorder.h"+#include "nodes/subgraph.h"#include "nodes/tensoriterator.h"#include "openvino/core/except.hpp"#include "openvino/core/model.hpp"@@ -391,7 +392,7 @@ void Graph::Init(const std::shared_ptr<const ov::Model>& model,void Graph::Activate() {// @todo It is possible that execution graph is already created in scope of// the allocation context collection from the outer graph so the state for inner graph is "Ready"- // We probably want to avoid such uncertancy+ // We probably want to avoid such uncertainty// OPENVINO_ASSERT(status == Status::Initialized, "Invalid graph status: ", static_cast<int>(status));Allocate();@@ -1989,7 +1990,7 @@ bool Graph::InsertNode(const NodePtr& parent,}// Apply inference precision configuration-void Graph::EnforceInferencePrecision() {+void Graph::EnforceInferencePrecision() const {CPU_DEBUG_CAP_ENABLE(EnforceInferPrcDebug inferPrecDebug);const auto inferPrec = getConfig().inferencePrecision;@@ -1997,33 +1998,72 @@ void Graph::EnforceInferencePrecision() {return; // nothing to do, only precision reduction is currently allowed}- std::function<void(const NodePtr&, std::unordered_set<NodePtr>& skipNodes)> searchForNodesToSkip;- searchForNodesToSkip = [&](const NodePtr& node, std::unordered_set<NodePtr>& skipNodes) -> void {+ // These node types must be forced to be executed in BF16 precision for performance gains+ auto isMandatoryBF16Node = [](const NodePtr& node) -> bool {+ const auto type = node->getType();+ // Subgraph may contain mandatory BF16 nodes inside (e.g. MatMuls),+ if (type == Type::Subgraph) {+ const auto subgraph = std::dynamic_pointer_cast<node::Subgraph>(node);+ OPENVINO_ASSERT(subgraph, "Node with Subgraph type can't be casted to Subgraph node");+ return subgraph->has_domain_sensitive_ops();+ }+ return any_of(type,+ Type::Convolution, // conv nets+ Type::FullyConnected, // conv / bert nets+ Type::RNNCell, // recurrent nets+ Type::RNNSeq, // recurrent nets+ Type::MatMul, // bert nets+ Type::ROIPooling, // object detection nets+ Type::Interpolate, // super resolution nets+ Type::PagedAttention, // page attention+ Type::ScaledDotProductAttention,+ Type::QKVProjection,+ Type::GatherMatmul,+ Type::LLMMLP);+ };++ // Backward DFS: traverse from node to its parents, stopping at mandatory BF16 nodes+ std::function<void(const NodePtr&, std::unordered_set<NodePtr>&)> backwardSkipSearch;+ backwardSkipSearch = [&](const NodePtr& node, std::unordered_set<NodePtr>& skipNodes) -> void {for (size_t i = 0; i < node->getParentEdges().size(); i++) {const auto& parent = node->getParentEdgeAt(i)->getParent();- if (inferPrec == ov::element::bf16) {- /* list of node types that must be forced to be executed in BF16 precision- * because of performance gains */- if (any_of(parent->getType(),- Type::Convolution, // conv nets- Type::FullyConnected, // conv / bert nets- Type::RNNCell, // recurrent nets- Type::RNNSeq, // recurrent nets- Type::MatMul, // bert nets- Type::ROIPooling, // object detection nets- Type::Interpolate, // super resolution nets- Type::PagedAttention, // page attention- Type::QKVProjection,- Type::GatherMatmul,- Type::LLMMLP)) {- continue; // stop at significant nodes- }++ // Stop at mandatory BF16 nodes+ if (inferPrec == ov::element::bf16 && isMandatoryBF16Node(parent)) {+ continue;}const auto res = skipNodes.insert(parent);if (res.second) { // node not visited yet- searchForNodesToSkip(parent, skipNodes);+ backwardSkipSearch(parent, skipNodes);+ }+ }+ };++ // Forward DFS: traverse from node to its children, stopping at mandatory BF16 nodes+ std::function<void(const NodePtr&, std::unordered_set<NodePtr>&)> forwardSkipSearch;+ forwardSkipSearch = [&](const NodePtr& node, std::unordered_set<NodePtr>& skipNodes) -> void {+ const size_t numberOfChildPorts = node->outputShapes.size();+ for (size_t port = 0; port < numberOfChildPorts; port++) {+ const auto& childEdgesAtPort = node->getChildEdgesAtPort(port);+ for (const auto& childEdge : childEdgesAtPort) {+ const auto& child = childEdge->getChild();+ // ShapeOf subgraphs are kept in integer precision+ if (child->getType() == Type::ShapeOf) {+ continue;+ }++ // Stop at mandatory BF16 nodes (don't add them to nodesToSkip)+ if (isMandatoryBF16Node(child)) {+ continue;+ }++ // Add current node to skipNodes+ const auto res = skipNodes.insert(child);+ if (res.second) { // node not visited yet+ forwardSkipSearch(child, skipNodes);+ }}}};@@ -2039,7 +2079,51 @@ void Graph::EnforceInferencePrecision() {continue;}- searchForNodesToSkip(output, nodesToSkip);+ backwardSkipSearch(output, nodesToSkip);+ }++ // Pattern-based node skipping for BF16 precision enforcement+ if (inferPrec == ov::element::bf16) {+ for (const auto& node : graphNodes) {+ // Pattern 1: MatMul with Convert from integer to floating point on any input. This basically means that+ // converting such an integer input to bf16 leads to loosing accuracy, as bf16 can only exactly represent+ // numbers in range [-128, 127]. Therefore we have to skip this Matmul and keep the result in floating point+ // precision as deep as possible given the performance implications+ if (node->getType() == Type::MatMul) {+ for (size_t i = 0; i < node->getParentEdges().size(); i++) {+ const auto& parent = node->getParentEdgeAt(i)->getParent();+ if (parent->getType() == Type::Convert) {+ // Check if Convert is from integer to floating point+ const auto inputPrec = parent->getOriginalInputPrecisionAtPort(0);+ const auto outputPrec = parent->getOriginalOutputPrecisionAtPort(0);++ if (inputPrec.is_integral_number() && outputPrec.is_real()) {+ nodesToSkip.insert(node);++ // keep the parent subtree and the child subtree in the original precision+ backwardSkipSearch(node, nodesToSkip);+ forwardSkipSearch(node, nodesToSkip);+ }+ }+ }+ }++ // Pattern 2: Gather with an integer type on data input is usually encountered in token embeddings (when+ // compressed). It's better to preserve token embeddings preprocessing (e.g., normalization) in fp32+ if (node->getType() == Type::Gather) {+ // Note: ShapeOf subgraphs are excluded from skipping markup+ // since they are always kept in integer precision+ const bool shapeOfSubgraph = node->getParentEdgeAt(0)->getParent()->getType() == Type::ShapeOf;+ const auto inputPrec = node->getOriginalInputPrecisionAtPort(0);+ if (!shapeOfSubgraph && inputPrec.is_integral_number()) {+ // Add Gather node to nodesToSkip+ nodesToSkip.insert(node);++ // keep the child subtree in the original precision+ forwardSkipSearch(node, nodesToSkip);+ }+ }+ }}for (const auto& node : graphNodes) {diff --git a/src/plugins/intel_cpu/src/graph.h b/src/plugins/intel_cpu/src/graph.hindex 31157e0599a..9cf0c2900f1 100644--- a/src/plugins/intel_cpu/src/graph.h+++ b/src/plugins/intel_cpu/src/graph.h@@ -357,8 +357,7 @@ protected:private:using event_t = void (Graph::*)();- void EnforceInferencePrecision();- void EnforceBF16();+ void EnforceInferencePrecision() const;void insertReorder(EdgePtr& edge, bool isOptimized, std::unordered_set<std::string>& uniqueLayerNames);void insertConvert(EdgePtr& edge);diff --git a/src/plugins/intel_cpu/src/nodes/subgraph.cpp b/src/plugins/intel_cpu/src/nodes/subgraph.cppindex 3a5675debff..bb0b547ac54 100644--- a/src/plugins/intel_cpu/src/nodes/subgraph.cpp+++ b/src/plugins/intel_cpu/src/nodes/subgraph.cpp@@ -265,7 +265,7 @@ void Subgraph::initSupportedPrimitiveDescriptors() {const size_t ndims = outputShapes[0].getRank();// Domain sensitive operations and dynamic Subgraphs support only Planar layout- const bool isOnlyPlanarApplicable = subgraph_attrs->snippet->has_domain_sensitive_ops();+ const bool isOnlyPlanarApplicable = has_domain_sensitive_ops();const bool isChannelsFirstApplicable =any_of(ndims, 1U, 2U, 3U, 4U, 5U) && dimRanksAreEqual && !isOnlyPlanarApplicable && !isDynamic;// Todo: Subgraphs currently don't support per-channel broadcasting of Blocked descriptors because@@ -553,7 +553,7 @@ Subgraph::DataFlowPasses Subgraph::getDataFlowPasses() {broadcastable_inputs);if (any_of(context->getConfig().inferencePrecision, ov::element::bf16, ov::element::f16) &&- subgraph_attrs->snippet->has_domain_sensitive_ops()) {+ has_domain_sensitive_ops()) {SNIPPETS_REGISTER_PASS_RELATIVE_X86_64(Place::After,ov::snippets::pass::FuseTransposeBrgemm,@@ -592,7 +592,7 @@ Subgraph::DataFlowPasses Subgraph::getDataFlowPasses() {ov::snippets::pass::PropagatePrecision,ov::intel_cpu::pass::BrgemmToBrgemmCPU,getConstantInputIndexes());- if (subgraph_attrs->snippet->has_domain_sensitive_ops()) {+ if (has_domain_sensitive_ops()) {#if defined(OPENVINO_ARCH_X86_64)const auto cpu_config =ov::as_type_ptr<CPURuntimeConfig>(subgraph_attrs->snippet->get_runtime_configurator()->get_config());@@ -924,4 +924,8 @@ void Subgraph::executeDynamicImpl(const dnnl::stream& strm) {execute(strm);}+bool Subgraph::has_domain_sensitive_ops() const {+ return subgraph_attrs->snippet->has_domain_sensitive_ops();+}+} // namespace ov::intel_cpu::nodediff --git a/src/plugins/intel_cpu/src/nodes/subgraph.h b/src/plugins/intel_cpu/src/nodes/subgraph.hindex bf028541874..53872dae387 100644--- a/src/plugins/intel_cpu/src/nodes/subgraph.h+++ b/src/plugins/intel_cpu/src/nodes/subgraph.h@@ -54,6 +54,8 @@ public:void execute(const dnnl::stream& strm) override;void executeDynamicImpl(const dnnl::stream& strm) override;+ bool has_domain_sensitive_ops() const;+protected:IShapeInfer::Result shapeInfer() const override;diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/bf16_embed_tokens_rms.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/bf16_embed_tokens_rms.cppnew file mode 100644index 00000000000..7142ba0c2b2--- /dev/null+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/bf16_embed_tokens_rms.cpp@@ -0,0 +1,165 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <cmath>+#include <functional>++#include "common_test_utils/node_builders/constant.hpp"+#include "common_test_utils/ov_tensor_utils.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"+#include "openvino/op/add.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/divide.hpp"+#include "openvino/op/gather.hpp"+#include "openvino/op/matmul.hpp"+#include "openvino/op/multiply.hpp"+#include "openvino/op/parameter.hpp"+#include "openvino/op/power.hpp"+#include "openvino/op/reduce_mean.hpp"+#include "openvino/op/sqrt.hpp"+#include "openvino/op/subtract.hpp"+#include "openvino/runtime/exec_model_info.hpp"+#include "shared_test_classes/base/ov_subgraph.hpp"+#include "transformations/rt_info/decompression.hpp"++namespace ov::test {++// Here we test a common pattern in LLMs - Token embeddings selection.+// In this particular tests embeddings are also quantized to u8.+// The idea is that such a subgraph (before the attention) must be preserved in fp32 to avoid accuracy loss.++class BF16EmbedTokensRMS : public SubgraphBaseTest {+public:+ void SetUp() override {+ const std::vector<InputShape> input_shapes = {+ {{-1, -1}, {{1, 32}, {2, 32}}}, // param 0+ {{-1, -1, EMBEDDINGS_SIZE}, {{1, 32, EMBEDDINGS_SIZE}, {2, 32, EMBEDDINGS_SIZE}}}};++ init_input_shapes(input_shapes);++ ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(ov::element::i32, inputDynamicShapes[0]),+ std::make_shared<ov::op::v0::Parameter>(ov::element::f32, inputDynamicShapes[1])};++ auto decompression_subgraph =+ utils::initGatherDecompressionSubgraph(ov::Shape{DICTIONARY_SIZE, EMBEDDINGS_SIZE},+ -1 /*disable group quantization*/,+ ov::element::u8 /*data prc*/,+ ov::element::f32 /*output prc*/,+ true /*add_subtract*/,+ false /*add reshape*/,+ false /*per tensor zp*/,+ false /*per tensor scale*/);++ auto gather_axis = utils::make_constant(ov::element::i32, {1}, std::vector<int>{0});++ auto gather = std::make_shared<ov::op::v8::Gather>(decompression_subgraph, params.front(), gather_axis);++ auto sum = std::make_shared<ov::op::v1::Add>(gather, params[1]);++ // RMS pattern+ auto sqr = utils::make_constant(ov::element::f32, ov::Shape{1, 1, 1}, std::vector<float>{2.f});+ sqr = std::make_shared<ov::op::v1::Power>(sum, sqr);+ auto reduce_mean = std::make_shared<ov::op::v1::ReduceMean>(+ sqr,+ utils::make_constant(ov::element::i32, ov::Shape{1}, std::vector<int>{-1}),+ true /*keep dims*/);++ auto add_op = std::make_shared<ov::op::v1::Add>(+ reduce_mean,+ utils::make_constant(ov::element::f32, ov::Shape{1, 1, 1}, std::vector<float>{1.f}));++ auto sqrt_op = std::make_shared<ov::op::v0::Sqrt>(add_op);+ auto one = utils::make_constant(ov::element::f32, ov::Shape{1, 1, 1}, std::vector<float>{1});++ auto divide = std::make_shared<ov::op::v1::Divide>(one, sqrt_op);++ auto norm = std::make_shared<ov::op::v1::Multiply>(sum, divide);++ auto gamma = utils::make_constant(ov::element::f32, ov::Shape{1, 1, EMBEDDINGS_SIZE});++ norm = std::make_shared<ov::op::v1::Multiply>(norm, gamma);++ // here we insert FC layer to trigger BF16 markup++ auto fc_weights = utils::make_constant(ov::element::f32, ov::Shape{EMBEDDINGS_SIZE, EMBEDDINGS_SIZE});+ auto matmul = std::make_shared<ov::op::v0::MatMul>(norm, fc_weights);++ function = std::make_shared<ov::Model>(ov::OutputVector{std::make_shared<ov::op::v0::Result>(matmul)},+ params,+ "BF16_EmbedTokens_RMS");+ targetDevice = utils::DEVICE_CPU;++ rel_threshold = abs_threshold = 0.002;++ configuration.insert({ov::hint::inference_precision.name(), ov::element::bf16});+ }++ void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override {+ inputs.clear();+ const auto& funcInputs = function->inputs();+ for (size_t i = 0; i < funcInputs.size(); ++i) {+ const auto& funcInput = funcInputs[i];++ ov::Tensor tensor;++ if (funcInput.get_element_type().is_integral()) {+ utils::InputGenerateData in_data;+ in_data.start_from = 0;+ in_data.range = DICTIONARY_SIZE;+ in_data.resolution = 1;+ tensor =+ utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);+ } else {+ utils::InputGenerateData in_data;+ in_data.start_from = 0;+ in_data.range = 10;+ in_data.resolution = 1000;+ tensor =+ utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);+ }+ inputs.insert({funcInput.get_node_shared_ptr(), tensor});+ }+ }++private:+ void check_subgraph_precision() {+ auto runtime_model = compiledModel.get_runtime_model();+ for (const auto& node : runtime_model->get_ordered_ops()) {+ if (node->get_rt_info().at(ov::exec_model_info::LAYER_TYPE).as<std::string>() == "Gather") {+ GTEST_ASSERT_EQ(node->get_output_element_type(0), ov::element::f32)+ << "Gather node output type is expected to be fp32";++ std::function<void(const ov::Node*)> check_fp32_path;+ check_fp32_path = [&check_fp32_path](const ov::Node* node) {+ const auto& outputs = node->get_output_target_inputs(0);+ if (outputs.empty()) {+ // we reached output+ return;+ }+ auto* next_node = outputs.begin()->get_node();+ if (node->get_rt_info().at(ov::exec_model_info::LAYER_TYPE).as<std::string>() == "Reorder") {+ return;+ }+ GTEST_ASSERT_EQ(node->get_output_element_type(0), ov::element::f32)+ << node->get_type_name() << " node output type is expected to be fp32";+ check_fp32_path(next_node);+ };+ check_fp32_path(node.get());+ }+ }+ }++private:+ static constexpr size_t DICTIONARY_SIZE = 512;+ static constexpr size_t EMBEDDINGS_SIZE = 128;+};++TEST_F(BF16EmbedTokensRMS, smoke_BF16EmbedTokensRMS_CPU) {+ if (!ov::with_cpu_x86_bfloat16()) {+ GTEST_SKIP();+ }+ run();+}++} // namespace ov::test\ No newline at end of filediff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/bf16_rotary_emb_matmul.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/bf16_rotary_emb_matmul.cppnew file mode 100644index 00000000000..5dbe90fb025--- /dev/null+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/bf16_rotary_emb_matmul.cpp@@ -0,0 +1,113 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "common_test_utils/node_builders/activation.hpp"+#include "common_test_utils/node_builders/constant.hpp"+#include "common_test_utils/ov_tensor_utils.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/matmul.hpp"+#include "openvino/op/parameter.hpp"+#include "shared_test_classes/base/ov_subgraph.hpp"++namespace ov::test {++// Here we test BF16 path for the LLM rotary embedding matmul operation which has one of the inputs converted from+// int64 to bf16. In the CPU plugin we have a special pattern matcher that prevents bf16 markup in this particular case.++// ┌──────────────┐ ┌──────────────┐+// │ │ │ │+// │ Param 1 int64│ │ Param 2 float│+// │ │ │ │+// └──────┬───────┘ └───────┬──────┘+// │ │+// │ │+// ┌──────┴───────┐ │+// │ │ │+// │ Convert float│ │+// │ │ │+// └──────┬───────┘ │+// │ │+// │ │+// │ │+// │ ┌──────────────┐ │+// │ │ │ │+// └───────┤ MatMul1 float├───┘+// │ │+// └──────┬───────┘+// │+// │+// │+// ┌──────┴────────┐+// │ │+// │ Cos float │+// │ │+// └──────┬────────┘+// │+// │+// ┌──────┴───────┐+// │ │+// │ Result1 float│+// │ │+// └──────────────┘++class BF16RotaryEmbMatMul : public SubgraphBaseTest {+public:+ void SetUp() override {+ const std::vector<InputShape> input_shapes = {+ {{-1, 1, -1}, {{2, 1, 32}}}, // param 0+ {{-1, 32, -1}, {{2, 32, 32}}}, // param 1+ };++ init_input_shapes(input_shapes);++ ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(ov::element::i64, inputDynamicShapes[0]),+ std::make_shared<ov::op::v0::Parameter>(ov::element::f32, inputDynamicShapes[1])};++ auto convert = std::make_shared<ov::op::v0::Convert>(params.front(), ov::element::f32);+ auto matmul = std::make_shared<ov::op::v0::MatMul>(convert, params[1]);+ auto cos = utils::make_activation(matmul, ov::element::f32, utils::ActivationTypes::Cos);+ function = std::make_shared<ov::Model>(ov::OutputVector{std::make_shared<ov::op::v0::Result>(cos)},+ params,+ "BF16RotaryEmbMatMul");+ targetDevice = utils::DEVICE_CPU;++ configuration.insert({ov::hint::inference_precision.name(), ov::element::bf16});+ }++ void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override {+ inputs.clear();+ const auto& funcInputs = function->inputs();+ for (size_t i = 0; i < funcInputs.size(); ++i) {+ const auto& funcInput = funcInputs[i];++ ov::Tensor tensor;++ if (funcInput.get_element_type() == ov::element::i64) {+ utils::InputGenerateData in_data;+ in_data.start_from = 128;+ in_data.range = 256;+ in_data.resolution = 1;+ tensor =+ utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);+ } else {+ utils::InputGenerateData in_data;+ in_data.start_from = 0;+ in_data.range = 15;+ in_data.resolution = 32;+ tensor =+ utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data);+ }+ inputs.insert({funcInput.get_node_shared_ptr(), tensor});+ }+ }+};++TEST_F(BF16RotaryEmbMatMul, smoke_BF16RotaryEmbMatMul_CPU) {+ if (!ov::with_cpu_x86_bfloat16()) {+ GTEST_SKIP();+ }+ run();+}++} // namespace ov::test\ No newline at end of filediff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/mha.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/mha.cppindex 16945776045..cd6d62c74f7 100644--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/mha.cpp+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/mha.cpp@@ -53,26 +53,24 @@ std::vector<std::vector<InputShape>> transposedShape_4D(bool with_static = true,}std::vector<std::vector<InputShape>> transposedShape_3D(bool with_dynamic = true) {- auto shapes = SNIPPETS_TESTS_STATIC_SHAPES(- {{128, 12, 64}, {128, 12, 64}, {12, 128, 128}, {128, 12, 64}},- {{68, 6, 92}, {68, 6, 92}, {1, 68, 68}, {68, 6, 92}},- {{16, 2, 92}, {68, 2, 92}, {1, 16, 68}, {68, 2, 92}});+ auto shapes = SNIPPETS_TESTS_STATIC_SHAPES({{128, 12, 64}, {128, 12, 64}, {12, 128, 128}, {128, 12, 64}},+ {{68, 6, 92}, {68, 6, 92}, {1, 68, 68}, {68, 6, 92}},+ {{16, 2, 92}, {68, 2, 92}, {1, 16, 68}, {68, 2, 92}});if (with_dynamic) {shapes.push_back({- {PartialShape{-1, -1, -1}, {{128, 3, 64}, {128, 3, 64}, {68, 6, 87}}},- {PartialShape{-1, -1, -1}, {{128, 1, 64}, {128, 1, 64}, {13, 6, 87}}},+ {PartialShape{-1, -1, -1}, {{128, 3, 64}, {128, 3, 64}, {68, 6, 87}}},+ {PartialShape{-1, -1, -1}, {{128, 1, 64}, {128, 1, 64}, {13, 6, 87}}},{PartialShape{-1, -1, -1}, {{1, 128, 128}, {1, 128, 128}, {1, 68, 13}}},- {PartialShape{-1, -1, -1}, {{128, 3, 64}, {128, 3, 64}, {13, 6, 87}}},+ {PartialShape{-1, -1, -1}, {{128, 3, 64}, {128, 3, 64}, {13, 6, 87}}},});}return shapes;}std::vector<std::vector<InputShape>> transposedShape_2D(bool with_dynamic = true) {- auto shapes = SNIPPETS_TESTS_STATIC_SHAPES(- {{12, 64}, {64, 12}, {12, 12}, {12, 64}},- {{16, 32}, {32, 16}, {16, 16}, {16, 32}},- {{8, 128}, {128, 8}, {8, 8}, {8, 128}});+ auto shapes = SNIPPETS_TESTS_STATIC_SHAPES({{12, 64}, {64, 12}, {12, 12}, {12, 64}},+ {{16, 32}, {32, 16}, {16, 16}, {16, 32}},+ {{8, 128}, {128, 8}, {8, 8}, {8, 128}});if (with_dynamic) {shapes.push_back({{PartialShape{-1, -1}, {{12, 64}, {16, 32}, {8, 128}}},@@ -99,7 +97,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_MHA_4D,::testing::Values(false),::testing::Values(MHA::default_thread_count),::testing::Values(expected_nodes_mha_4d_f32),- ::testing::Values(2), // decomposed Transpose + MHA+ ::testing::Values(2), // decomposed Transpose + MHA::testing::Values(ov::test::utils::DEVICE_CPU),::testing::Values(CPUTestUtils::empty_plugin_config)),MHA::getTestCaseName);@@ -112,7 +110,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_MHA_4D_WithScalarMul,::testing::Values(true),::testing::Values(MHA::default_thread_count),::testing::Values(expected_nodes_mha_4d_f32),- ::testing::Values(2), // decomposed Transpose, Mul + MHA+ ::testing::Values(2), // decomposed Transpose, Mul + MHA::testing::Values(ov::test::utils::DEVICE_CPU),::testing::Values(CPUTestUtils::empty_plugin_config)),MHA::getTestCaseName);@@ -169,18 +167,19 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_MHABF16_4D,::testing::Values(CPUTestUtils::empty_plugin_config)),MHA::getTestCaseName);-INSTANTIATE_TEST_SUITE_P(smoke_Snippets_MHAEnforceBF16,- MHA,- ::testing::Combine(::testing::ValuesIn(transposedShape_4D()),- ::testing::ValuesIn(precision_f32(4)),- ::testing::Values(ov::element::bf16),- ::testing::ValuesIn({false}),- ::testing::Values(MHA::default_thread_count),- ::testing::Values(8), // decomposed Transpose + MHA + 5 Converts + 1 Transpose on output- ::testing::Values(6), // MHA + 5 Reorders on inputs and output- ::testing::Values(ov::test::utils::DEVICE_CPU),- ::testing::Values(CPUTestUtils::cpu_bf16_plugin_config)),- MHA::getTestCaseName);+INSTANTIATE_TEST_SUITE_P(+ smoke_Snippets_MHAEnforceBF16,+ MHA,+ ::testing::Combine(::testing::ValuesIn(transposedShape_4D()),+ ::testing::ValuesIn(precision_f32(4)),+ ::testing::Values(ov::element::bf16),+ ::testing::ValuesIn({false}),+ ::testing::Values(MHA::default_thread_count),+ ::testing::Values(8), // decomposed Transpose + MHA + 5 Converts + 1 Transpose on output+ ::testing::Values(6), // MHA + 5 Reorders on inputs and output+ ::testing::Values(ov::test::utils::DEVICE_CPU),+ ::testing::Values(CPUTestUtils::cpu_bf16_plugin_config)),+ MHA::getTestCaseName);INSTANTIATE_TEST_SUITE_P(smoke_Snippets_MHAEnforceBF16_f32_in_prc,MHA,@@ -189,7 +188,8 @@ INSTANTIATE_TEST_SUITE_P(smoke_Snippets_MHAEnforceBF16_f32_in_prc,::testing::Values(ov::element::f32),::testing::ValuesIn({false}),::testing::Values(MHA::default_thread_count),- ::testing::Values(3), // decomposed Transpose + MHA + 1 Transpose on output+ ::testing::Values(4), // decomposed Transpose + MHA + Reorder (bf16->fp32)+ // + 1 Transpose on output::testing::Values(2), // decomposed Transpose + MHA::testing::Values(ov::test::utils::DEVICE_CPU),::testing::Values(CPUTestUtils::cpu_bf16_plugin_config)),