Skip to content

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

[NPUW] added high precision flag for specific ADD layer input during SDPA unroll (#30018)

Eugene Smirnov4b4a1965bf18
diff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.cpp b/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.cpp
index a946d32bdff..cb5ff455fd8 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.cpp
@@ -221,7 +221,7 @@ private:
class ScaledDotProductAttentionDecomposition : public ov::pass::MatcherPass {
public:
OPENVINO_MATCHER_PASS_RTTI("npuw::LLMCompiledModel::ScaledDotProductAttentionDecomposition");
- ScaledDotProductAttentionDecomposition() {
+ explicit ScaledDotProductAttentionDecomposition(bool use_high_precision_on_add) {
auto pattern_node = ov::pass::pattern::wrap_type<ov::op::v13::ScaledDotProductAttention>();
ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {
@@ -233,7 +233,7 @@ public:
return false;
}
- auto new_output_node = decompose(node);
+ auto new_output_node = decompose(node, use_high_precision_on_add);
ov::replace_node(node, new_output_node);
return true;
};
@@ -241,7 +241,8 @@ public:
auto m = std::make_shared<ov::pass::pattern::Matcher>(pattern_node, "ScaledDotProductAttentionDecomposition");
register_matcher(m, std::move(callback));
}
- std::shared_ptr<ov::Node> decompose(std::shared_ptr<ov::op::v13::ScaledDotProductAttention> node) {
+ std::shared_ptr<ov::Node> decompose(std::shared_ptr<ov::op::v13::ScaledDotProductAttention> node,
+ bool use_high_precision_on_add) {
using namespace ov::op;
using namespace ov;
auto query = node->input_value(0);
@@ -312,6 +313,12 @@ public:
auto triu = register_new_node<v1::GreaterEqual>(horizontal_range, vertical_range);
atten_mask = register_new_node<v1::Select>(triu, mask, zero_f);
}
+ if (use_high_precision_on_add) {
+ npuw::util::HighPrecisionAttr attr_hp;
+ attr_hp.compute_precision_type = ov::element::f32;
+ atten_mask.get_rt_info()[npuw::util::HighPrecisionAttr::get_type_info_static()] = attr_hp;
+ }
+
scaled_atten = register_new_node<v1::Add>(scaled_atten, atten_mask);
}
@@ -374,11 +381,10 @@ bool remove_empty_kv_inputs(std::shared_ptr<ov::Model> model) {
}
} // namespace
-// testability - should we have interface for that or move matchers to another file?
-bool optimize_value_tensors(std::shared_ptr<ov::Model> model);
-bool optimize_value_tensors(std::shared_ptr<ov::Model> model) {
+namespace ov::npuw::util {
+bool optimize_value_tensors(std::shared_ptr<ov::Model> model, bool isPrefill) {
ov::pass::GraphRewrite rewr;
- rewr.add_matcher<ScaledDotProductAttentionDecomposition>();
+ rewr.add_matcher<ScaledDotProductAttentionDecomposition>(isPrefill);
TransposeValueTensors::Context ctx;
rewr.add_matcher<TransposeValueTensors_llama2>(std::ref(ctx));
rewr.add_matcher<TransposeValueTensors_llama3>(std::ref(ctx));
@@ -389,6 +395,7 @@ bool optimize_value_tensors(std::shared_ptr<ov::Model> model) {
// NB: matmul parameters gets transposed, if pass applied
return ctx.bTransposed;
}
+} // namespace ov::npuw::util
namespace {
struct KVAxesPosition {
@@ -642,8 +649,8 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
if (optimize_v_tensors) {
LOG_DEBUG("6. Check and apply opt layout");
LOG_BLOCK();
- if (optimize_value_tensors(kvcache_model)) {
- NPUW_ASSERT(optimize_value_tensors(prefill_model));
+ if (ov::npuw::util::optimize_value_tensors(kvcache_model, false)) {
+ NPUW_ASSERT(ov::npuw::util::optimize_value_tensors(prefill_model, true));
m_kvcache_desc.v_tensors_transposed = true;
} else {
LOG_DEBUG("vtensors optimisation not applied");
diff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model_utils.hpp b/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model_utils.hpp
new file mode 100644
index 00000000000..2407a9a1f2c
--- /dev/null
+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model_utils.hpp
@@ -0,0 +1,31 @@
+// Copyright (C) 2024-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+#include <memory>
+
+#include "openvino/openvino.hpp"
+
+namespace ov ::npuw ::util {
+
+/*
+ * special mark on nodes to be remain in high-precision for optimal processing
+ */
+class HighPrecisionAttr : public RuntimeAttribute {
+public:
+ OPENVINO_RTTI("HighPrecisionAttr", "0", RuntimeAttribute);
+ ov::element::Type compute_precision_type;
+
+ bool visit_attributes(AttributeVisitor& visitor) override {
+ visitor.on_attribute("compute_precision", compute_precision_type);
+ return true;
+ }
+};
+
+// SDPA-unroll and transpose transformations
+bool optimize_value_tensors(std::shared_ptr<ov::Model> model, bool isPrefill);
+
+// clang-format off
+} // namespace ov
+// clang-format on
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp
index 2b67d842ccb..f303e17672a 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp
@@ -442,7 +442,16 @@ void Partitioner::identifySubgraphs() {
input_mapping[orig_node] = orig_node;
return orig_node;
};
- auto parameter_from = [&input_mapping, connect_in_f16](ov::Output<ov::Node> output) {
+ auto is_hp_tag = [](auto node) {
+ auto hptag = node.get_rt_info().find(ov::npuw::util::HighPrecisionAttr::get_type_info_static());
+ if (hptag == node.get_rt_info().end() ||
+ hptag->second.template as<ov::npuw::util::HighPrecisionAttr>().compute_precision_type !=
+ ov::element::f32) {
+ return false;
+ }
+ return true;
+ };
+ auto parameter_from = [&input_mapping, is_hp_tag, connect_in_f16](ov::Output<ov::Node> output) {
auto orig_node = output.get_node_shared_ptr();
auto it = input_mapping.find(output);
if (it != input_mapping.end()) {
@@ -468,7 +477,12 @@ void Partitioner::identifySubgraphs() {
// to maintain graph contracts. See handling where parameter_from is called.
auto otype = output.get_element_type();
if (otype == ov::element::f32 && connect_in_f16) {
- otype = ov::element::f16;
+ if (!is_hp_tag(output)) {
+ otype = ov::element::f16;
+ LOG_DEBUG("Found parameter " << output << ", will be computed in fp16 precision");
+ } else {
+ LOG_DEBUG("Found parameter " << output << ", pinned to compute in fp32 precision");
+ }
}
auto new_param = std::make_shared<ov::op::v0::Parameter>(otype, output.get_partial_shape());
result = std::static_pointer_cast<ov::Node>(new_param);
@@ -717,9 +731,13 @@ void Partitioner::identifySubgraphs() {
// Register a new Result. Optionally, lower it to f16
ov::Output<ov::Node> result_src = output_desc;
if (output_desc.get_element_type() == ov::element::f32 && connect_in_f16) {
- auto new_cvt = new_f16ic_cvt(output_desc, ov::element::f16);
- LOG_DEBUG("Added F16IC Result Convert " << new_cvt << " on top of " << output_desc);
- result_src = new_cvt;
+ if (!is_hp_tag(output_desc)) {
+ auto new_cvt = new_f16ic_cvt(output_desc, ov::element::f16);
+ LOG_VERB("Added F16IC Result Convert " << new_cvt << " on top of " << output_desc);
+ result_src = new_cvt;
+ } else {
+ LOG_VERB("Found result " << output_desc << ", pinned to compute in high precision");
+ }
}
auto new_result = std::make_shared<ov::op::v0::Result>(result_src);
result_cache[output_desc] = LinkPtrFrom{this_group_idx, new_result};
diff --git a/src/plugins/intel_npu/src/plugin/npuw/util.hpp b/src/plugins/intel_npu/src/plugin/npuw/util.hpp
index 729187fe702..5952638ecab 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/util.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/util.hpp
@@ -6,6 +6,7 @@
#include <string>
+#include "llm_compiled_model_utils.hpp"
#include "logging.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/runtime/itensor.hpp"
diff --git a/src/plugins/intel_npu/tests/unit/npuw/transpose_vt.cpp b/src/plugins/intel_npu/tests/unit/npuw/transpose_vt.cpp
index 6625f24d2dd..86af0520e94 100644
--- a/src/plugins/intel_npu/tests/unit/npuw/transpose_vt.cpp
+++ b/src/plugins/intel_npu/tests/unit/npuw/transpose_vt.cpp
@@ -4,66 +4,204 @@
#include <gtest/gtest.h>
#include <common_test_utils/test_common.hpp>
#include "openvino/op/ops.hpp"
+#include "intel_npu/config/npuw.hpp"
+#include "llm_compiled_model_utils.hpp"
+#include "partitioning/partitioning.hpp"
+#include "intel_npu/config/config.hpp"
+
+/*
+* conditional compilation that can be used during test regression debug
+* #define ANALYZE_TEST
+* which in turn will dump subgraphs after partitioning
+*/
namespace npuw_utest{
using NodePtr = std::shared_ptr<ov::Node>;
}
-//TODO: move to header maybe
-bool optimize_value_tensors(std::shared_ptr<ov::Model> model);
-
enum class NetworkKind {
llama2,
llama3
};
-
typedef std::tuple <
ov::Shape,
bool, // withConvert
bool, // withTranspose - without transpose node - matcher shouldnt detect subgraph, easy way to negative case
+ bool, // withSDPA - should SDPA layer present or be already unrolled or simplified
+ bool, // use high precision on attention_mask input
NetworkKind
-> OptimizeVTTestParams;
+> OptimizeVTTestParamsTuple;
+
+struct OptimizeVTTestParams {
+ #define _AT(idx) std::tuple_element<idx, OptimizeVTTestParamsTuple>::type
+
+ _AT(0) inputShape;
+ _AT(1) withConvert;
+ _AT(2) withTranspose;
+ _AT(3) withSDPA;
+ _AT(4) withHpAttenMask;
+ _AT(5) kind;
+ #undef _AT
+
+ OptimizeVTTestParams(const OptimizeVTTestParamsTuple& tup) {
+ std::tie(inputShape, withConvert, withTranspose, withSDPA, withHpAttenMask, kind) = tup;
+ }
+};
+
// based on ConcatWithDifferentChildrenTransformation
-class TransposeVTTest : public testing::WithParamInterface<OptimizeVTTestParams>,
+class TransposeVTTest : public testing::WithParamInterface<OptimizeVTTestParamsTuple>,
public ov::test::TestsCommon {
public:
void Validate() const {
- auto isValidSubgraph = std::get<2>(GetParam());
- ASSERT_EQ(isValidSubgraph, optimize_value_tensors(model));
+ auto test = OptimizeVTTestParams{GetParam()};
+
+ auto isValidSubgraph = test.withTranspose;
+ ASSERT_EQ(isValidSubgraph, ov::npuw::util::optimize_value_tensors(model, test.withHpAttenMask));
+
+ //std::shared_ptr<ov::Model> model = ...; // your model
+
+ auto test_case_name = getTestCaseName(testing::TestParamInfo<OptimizeVTTestParamsTuple>{GetParam(), 0});
+ std::string xml_path = test_case_name + ".xml";
+ std::string bin_path = test_case_name + ".bin";
+
+ // Save the model
+ ov::pass::Serialize serialize_pass(xml_path, bin_path);
+ serialize_pass.run_on_model(model);
+
+
+ // validation of High Precision attention mask - implies enabling SDPA layer to be unrolled,
+ // and also specific FP16 activation transformation in partitioning
+ if (test.withSDPA) {
+ std::shared_ptr<::intel_npu::OptionsDesc> options_desc;
+
+ auto opt_desc = std::make_shared<::intel_npu::OptionsDesc>();
+ auto cfg = ::intel_npu::Config(opt_desc);
+ ::intel_npu::registerNPUWOptions(*opt_desc);
+ std::map<std::string, std::string> cfg_map = {{"NPUW_F16IC", "YES"}};//, {"NPUW_ONLINE_PIPELINE", "NONE"}};
+ cfg.update(cfg_map);
+
+ ov::npuw::Partitioning partitioning;
+ ASSERT_NO_THROW(partitioning = ov::npuw::getPartitioning(model, cfg));
+
+ // input to add is 32b via convert / or via 32b parameter
+ bool bAttentionMaskVerified = false;
+ bool bAttentionMaskResultVerified = false;
+
+ auto get_rank = [](const ov::Shape& sh) {
+ return std::count_if(sh.begin(), sh.end(), [](size_t dim) {return dim != 1;});
+ };
+
+ for (auto & subgraph : partitioning.subgraphs) {
+ auto partitioned_model = std::make_shared<ov::Model>(subgraph._results,
+ subgraph._sinks,
+ subgraph._parameters,
+ "m1");
+#ifdef ANALYZE_TEST
+ auto test_case_name = getTestCaseName(testing::TestParamInfo<OptimizeVTTestParamsTuple>{GetParam(), 0});
+ std::string xml_path = test_case_name + "_"+ std::to_string(idx) +"_partitioned.xml";
+ std::string bin_path = test_case_name + "_"+ std::to_string(idx) +"_partitioned.bin";
+
+ // Save the model
+ ov::pass::Serialize serialize_pass(xml_path, bin_path);
+ serialize_pass.run_on_model(partitioned_model);
+#endif
+
+ for (auto op : partitioned_model->get_ordered_ops()) {
+ // case when only 1 add and 1 negate layer in whole subgraph
+ if (ov::is_type<ov::op::v1::Add>(op)) {
+ ASSERT_FALSE(bAttentionMaskVerified);
+ // check rt_info
+ // should not be any convert operation for this add
+ // assume in lhs we have a mask
+ auto lhs = op->get_input_node_ptr(0);
+ auto rhs = op->get_input_node_ptr(1);
+
+ ASSERT_EQ(lhs->get_output_size(), 1);
+ ASSERT_EQ(rhs->get_output_size(), 1);
+
+ ASSERT_NE(lhs, nullptr) << "Add layer " << op->get_friendly_name() << " need to have two inputs";
+ ASSERT_NE(rhs, nullptr) << "Add layer " << op->get_friendly_name() << " need to have two inputs";
+
+ if (get_rank(lhs->get_output_shape(0)) != 2) {
+ ASSERT_EQ(get_rank(rhs->get_output_shape(0)), 2)
+ << "Add layer " << op->get_friendly_name() << " should have 2D input, but was{"
+ << lhs->get_output_shape(0) << " , " << rhs->get_output_shape(0) << " }";
+ std::swap(lhs, rhs);
+ }
+
+ if (test.withHpAttenMask) {
+ static constexpr char err[] = "in case of high precision, attention_mask has to accept input in fp32 without convert layer";
+ ASSERT_TRUE(ov::is_type<ov::op::v0::Parameter>(lhs)) << err << ", actual type: " << lhs->get_type_name();
+ ASSERT_EQ(ov::as_type<ov::op::v0::Parameter>(lhs)->get_element_type(), ov::element::f32) << err;
+ } else {
+ static constexpr char err[] = "in case of fp16 precision, attention_mask should have preceding convert layer from fp16 to fp32";
+ // input has convert from fp16 to fp32
+ ASSERT_TRUE(ov::is_type<ov::op::v0::Convert>(lhs)) << err << ", actual type: " << lhs->get_type_name();;
+ ASSERT_EQ(ov::as_type<ov::op::v0::Convert>(lhs)->get_destination_type(), ov::element::f32) << err;
+ ASSERT_EQ(ov::as_type<ov::op::v0::Convert>(lhs)->get_input_element_type(0), ov::element::f16) << err;
+ }
+
+ // should be only one add as atention_mask
+ bAttentionMaskVerified = true;
+ }
+
+ if (ov::is_type<ov::op::v0::Negative>(op)) {
+ ASSERT_FALSE(bAttentionMaskResultVerified);
+ // check rt_info
+ // should not be any convert operation after this negate
+ ASSERT_EQ(op->outputs().size(), 1);
+ auto result_s = op->output(0).get_target_inputs();
+
+ ASSERT_EQ(result_s.size(), 1);
+ auto result = result_s.begin()->get_node();
+
+ if (test.withHpAttenMask) {
+ static constexpr char err[] = "in case of high precision, attention_mask producer need to be in fp32";
+ ASSERT_TRUE(ov::is_type<ov::op::v0::Result>(result)) << err << ", expected type Result, actual type: " << result->get_type_name();
+ ASSERT_EQ(ov::as_type<ov::op::v0::Result>(result)->get_element_type(), ov::element::f32) << err;
+ } else {
+ static constexpr char err[] = "in case of fp16 precision, attention_mask producer should have convert layer from fp32 to fp16";
+ ASSERT_TRUE(ov::is_type<ov::op::v0::Convert>(result)) << err << ", actual type: " << result->get_type_name();;
+ ASSERT_EQ(ov::as_type<ov::op::v0::Convert>(result)->get_destination_type(), ov::element::f16) << err;
+ ASSERT_EQ(ov::as_type<ov::op::v0::Convert>(result)->get_input_element_type(0), ov::element::f32) << err;
+ }
+
+ // should be only one add as atention_mask
+ bAttentionMaskResultVerified = true;
+ }
+ }
+ }
+
+ ASSERT_TRUE(bAttentionMaskVerified) << "no attention mask node not detected after applying optimize_value_tensors + run getPartitioning";
+ ASSERT_TRUE(bAttentionMaskResultVerified) << "no attention mask producer node detected after applying optimize_value_tensors + run getPartitioning";
+ }
}
- static std::string getTestCaseName(testing::TestParamInfo<OptimizeVTTestParams> obj) {
- auto inputShape = std::get<0>(obj.param);
- auto withConvert = std::get<1>(obj.param);
- auto withTranspose = std::get<2>(obj.param);
- auto kind = std::get<3>(obj.param);
+ static std::string getTestCaseName(testing::TestParamInfo<OptimizeVTTestParamsTuple> obj) {
+ auto test = OptimizeVTTestParams{obj.param};
std::ostringstream result;
- result << "npuw_llm_pipeline_" << inputShape << "_"
- << (kind == NetworkKind::llama3 ? "LLAMA3" : "LLAMA2")
- << (withConvert ? "_with_convert" : "")
- << (!withTranspose ? "_NEGATIVE" : "");
+ result << "npuw_llm_pipeline_" << test.inputShape << "_"
+ << (test.kind == NetworkKind::llama3 ? "LLAMA3" : "LLAMA2")
+ << (test.withConvert ? "_with_convert" : "")
+ << (test.withSDPA ? "_SDPA" : "")
+ << (test.withHpAttenMask ? "_HP" : "")
+ << (!test.withTranspose ? "_NEGATIVE" : "");
return result.str();
}
protected:
void SetUp() override {
- const auto& inputShape = std::get<0>(GetParam());
- const auto& withConvert = std::get<1>(GetParam());
- const auto& withTranspose = std::get<2>(GetParam());
- const auto& kind = std::get<3>(GetParam());
-
- model = CreateModel(inputShape, withConvert, withTranspose, kind);
+ model = CreateModel();
}
- std::shared_ptr<ov::Model> CreateModel(const ov::Shape& testShape,
- bool withConvert,
- bool withTranspose,
- NetworkKind kind) {
+ std::shared_ptr<ov::Model> CreateModel() {
+ const auto test = OptimizeVTTestParams{GetParam()};
+
auto create_shape_constant = [](const std::vector<int64_t> & const_data, const std::string& name) {
auto pattern = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{const_data.size()}, const_data);
pattern->set_friendly_name("unsqueese_pattern");
@@ -71,21 +209,21 @@ protected:
};
// in case of non broadcast number of input channels significantly smaller
- auto numChannels = (kind == NetworkKind::llama3) ? 8 : 32;
- auto input_shape = testShape;
- auto input_2 = static_cast<int>(testShape[2]);
- auto input_3 = static_cast<int>(testShape[3]);
+ auto numChannels = (test.kind == NetworkKind::llama3) ? 8 : 32;
+ auto input_shape = test.inputShape;
+ auto input_2 = static_cast<int>(test.inputShape[2]);
+ auto input_3 = static_cast<int>(test.inputShape[3]);
input_shape.at(1) = numChannels;
// ov::Model with only a transpose node
- auto param = std::make_shared<ov::op::v0::Parameter>(withConvert ? ov::element::f16 : ov::element::f32, input_shape);
+ auto param = std::make_shared<ov::op::v0::Parameter>(test.withConvert ? ov::element::f16 : ov::element::f32, input_shape);
param->set_friendly_name("past_key_value");
- std::shared_ptr<ov::Node> convert = withConvert ?
+ std::shared_ptr<ov::Node> convert = test.withConvert ?
std::static_pointer_cast<ov::Node>(std::make_shared<ov::op::v0::Convert>(param, ov::element::f32)) :
std::static_pointer_cast<ov::Node>(param);
- if (withConvert) {
+ if (test.withConvert) {
convert->set_friendly_name("convert");
}
@@ -96,12 +234,12 @@ protected:
auto reshape_pattern = create_shape_constant({0, 0, numChannels, input_3}, "reshape_pattern");
auto transpose_pattern = create_shape_constant({1, numChannels, 1, input_3}, "transposed_pattern");
- auto reshape = std::make_shared<ov::op::v1::Reshape>(param2, withTranspose ? reshape_pattern : transpose_pattern, true);
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(param2, test.withTranspose ? reshape_pattern : transpose_pattern, true);
reshape->set_friendly_name("reshape");
std::shared_ptr<ov::Node> transpose_or_reshape;
- if (withTranspose) {
+ if (test.withTranspose) {
auto constOrder = create_shape_constant({0, 2, 1, 3}, "const_order");
auto transpose = std::make_shared<ov::op::v1::Transpose>(reshape, constOrder);
transpose->set_friendly_name("transpose");
@@ -115,7 +253,7 @@ protected:
std::shared_ptr<ov::Node> concat_or_reshape = concat;
- if (kind == NetworkKind::llama3) {
+ if (test.kind == NetworkKind::llama3) {
auto unsqueeze_pattern = create_shape_constant({2}, "unsqueese_pattern");
auto unsqueeze = std::make_shared<ov::op::v0::Unsqueeze>(concat, unsqueeze_pattern);
unsqueeze->set_friendly_name("unsqueeze");
@@ -134,20 +272,53 @@ protected:
}
- auto param3 = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 32, 1, input_shape[2] + 1});
- param3->set_friendly_name("param3");
+ if (test.withSDPA) {
+ auto mask_input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 1, input_shape[2] + 1, input_shape[2] + 1});
+ mask_input->set_friendly_name("mask_input");
+
+ auto mask_input_1 = std::make_shared<ov::op::v0::Negative>(mask_input);
+ mask_input_1->set_friendly_name("mask_input_1");
- // TODO: what if v1 softmax???
- auto softmax = std::make_shared<ov::op::v8::Softmax>(param3, -2);
- softmax->set_friendly_name("softmax");
+ auto k_input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 32, input_shape[2] + 1, input_shape[3]});
+ k_input->set_friendly_name("k_input");
- // entry point matmul for matcher
- auto matmul = std::make_shared<ov::op::v0::MatMul>(softmax, concat_or_reshape);
- matmul->set_friendly_name("matmul");
- auto result = std::make_shared<ov::op::v0::Result>(matmul);
- result->set_friendly_name("res");
- return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{param, param2, param3});
+ auto q_input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 32, input_shape[2] + 1, input_shape[3]});
+ q_input->set_friendly_name("q_input");
+
+ auto scale_node = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1}, {1});
+
+ // TODO: add sdpa subgraph
+ std::shared_ptr<ov::Node> sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(
+ q_input,
+ k_input,
+ concat_or_reshape,
+ mask_input_1,
+ scale_node,
+ false);
+ sdpa->set_friendly_name("sdpa");
+ auto result = std::make_shared<ov::op::v0::Result>(sdpa);
+
+ result->set_friendly_name("res");
+ return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{param, param2, mask_input, k_input, q_input});
+
+ } else {
+ auto param3 = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 32, 1, input_shape[2] + 1});
+ param3->set_friendly_name("param3");
+
+ // TODO: what if v1 softmax???
+ auto softmax = std::make_shared<ov::op::v8::Softmax>(param3, -2);
+ softmax->set_friendly_name("softmax");
+
+ // entry point matmul for matcher
+ auto matmul = std::make_shared<ov::op::v0::MatMul>(softmax, concat_or_reshape);
+ matmul->set_friendly_name("matmul");
+
+ auto result = std::make_shared<ov::op::v0::Result>(matmul);
+ result->set_friendly_name("res");
+ return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{param, param2, param3});
+
+ }
}
std::shared_ptr<ov::Model> model;
@@ -166,6 +337,10 @@ const std::vector<bool> withTranspose{true, false};
const std::vector<bool> withBroadCast{true, false};
+const std::vector<bool> withSDPA{true, false};
+
+const std::vector<bool> withHpAttenMask{true, false};
+
const std::vector<NetworkKind> networkKind = {
// llama2 or llama3 type of concat, with convert layer or without
NetworkKind::llama2, NetworkKind::llama3
@@ -173,10 +348,13 @@ const std::vector<NetworkKind> networkKind = {
INSTANTIATE_TEST_SUITE_P(smoke_Run_MatchAndTransposeVT,
TransposeVTTest,
- ::testing::Combine(::testing::ValuesIn(input_shapes),
- ::testing::ValuesIn(withTranspose),
- ::testing::ValuesIn(withBroadCast),
- ::testing::ValuesIn(networkKind)),
+ ::testing::Combine(
+ ::testing::ValuesIn(input_shapes),
+ ::testing::ValuesIn(withTranspose),
+ ::testing::ValuesIn(withBroadCast),
+ ::testing::ValuesIn(withSDPA),
+ ::testing::ValuesIn(withHpAttenMask),
+ ::testing::ValuesIn(networkKind)),
TransposeVTTest::getTestCaseName);
} // namespace