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
[NPUW] LLMCompiledModel refactoring part 1 (#34290)
Alexander Kalistratove0ab22568f26
diff --git a/src/plugins/intel_npu/src/plugin/npuw/embedding_infer_request.cpp b/src/plugins/intel_npu/src/plugin/npuw/embedding_infer_request.cppindex 8dfab01e7d6..e0d90c0095f 100644--- a/src/plugins/intel_npu/src/plugin/npuw/embedding_infer_request.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/embedding_infer_request.cpp@@ -1,4 +1,4 @@-// Copyright (C) 2025 Intel Corporation+// Copyright (C) 2018-2026 Intel Corporation// SPDX-License-Identifier: Apache-2.0//diff --git a/src/plugins/intel_npu/src/plugin/npuw/embedding_infer_request.hpp b/src/plugins/intel_npu/src/plugin/npuw/embedding_infer_request.hppindex b4bf2316afe..86129a94a33 100644--- a/src/plugins/intel_npu/src/plugin/npuw/embedding_infer_request.hpp+++ b/src/plugins/intel_npu/src/plugin/npuw/embedding_infer_request.hpp@@ -1,4 +1,4 @@-// Copyright (C) 2025 Intel Corporation+// Copyright (C) 2018-2026 Intel Corporation// SPDX-License-Identifier: Apache-2.0//diff --git a/src/plugins/intel_npu/src/plugin/npuw/embedding_model_utils.cpp b/src/plugins/intel_npu/src/plugin/npuw/embedding_model_utils.cppindex 142bb840b2c..6d25376ce69 100644--- a/src/plugins/intel_npu/src/plugin/npuw/embedding_model_utils.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/embedding_model_utils.cpp@@ -370,9 +370,10 @@ private:} // namespace-void ov::npuw::util::prepare_text_embedding_model(std::shared_ptr<ov::Model> model, uint32_t seq_len_dim) {+bool ov::npuw::util::PrepareTextEmbeddingModel::run_on_model(const std::shared_ptr<ov::Model>& model) {ov::pass::Manager manager("prepare-embedding");manager.set_per_pass_validation(true);- manager.register_pass<ReConstructEmbeddingModel>(seq_len_dim);- manager.run_passes(model);+ manager.register_pass<ReConstructEmbeddingModel>(m_seq_len_dim);++ return manager.run_passes(model);}diff --git a/src/plugins/intel_npu/src/plugin/npuw/embedding_model_utils.hpp b/src/plugins/intel_npu/src/plugin/npuw/embedding_model_utils.hppindex 422c5684d3d..0e9c9c5ee5a 100644--- a/src/plugins/intel_npu/src/plugin/npuw/embedding_model_utils.hpp+++ b/src/plugins/intel_npu/src/plugin/npuw/embedding_model_utils.hpp@@ -1,4 +1,4 @@-// Copyright (C) 2025 Intel Corporation+// Copyright (C) 2018-2026 Intel Corporation// SPDX-License-Identifier: Apache-2.0//@@ -8,6 +8,15 @@namespace ov ::npuw ::util {-void prepare_text_embedding_model(std::shared_ptr<ov::Model> model, uint32_t seq_len_dim);+class PrepareTextEmbeddingModel : public ov::pass::ModelPass {+ uint32_t m_seq_len_dim;++public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::PrepareTextEmbeddingModel");++ explicit PrepareTextEmbeddingModel(uint32_t seq_len_dim) : m_seq_len_dim(seq_len_dim) {}++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override;+};} // namespace ov::npuw::utildiff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.cpp b/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.cppindex 42913cefd79..223d456c081 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@@ -352,9 +352,11 @@ public:}};-class RedirectNewKvToOutput : public ov::pass::MatcherPass {+class RedirectNewKvToOutputMatcher : public ov::pass::MatcherPass {public:- RedirectNewKvToOutput() {+ OPENVINO_MATCHER_PASS_RTTI("ov::npuw::patterns::RedirectNewKvToOutputMatcher");++ RedirectNewKvToOutputMatcher() {// example of fp8 inputs to concat// input0 : float8e4m3[1,32,1151,96]// input1 : float8e4m3[1,32,1,96]@@ -401,13 +403,13 @@ public:return true;};- register_matcher(std::make_shared<opp::Matcher>(result_or, "RedirectNewKvToOutput"), callback);+ register_matcher(std::make_shared<opp::Matcher>(result_or, "RedirectNewKvToOutputMatcher"), callback);}};class OldPhi3SlidingMaskMatcher : public ov::pass::MatcherPass {public:- OPENVINO_MATCHER_PASS_RTTI("npuw::LLMCompiledModel::OldPhi3SlidingMaskMatcher");+ OPENVINO_MATCHER_PASS_RTTI("ov::npuw::patterns::OldPhi3SlidingMaskMatcher");OldPhi3SlidingMaskMatcher() {// Search for the Phi3 old sliding mask pattern to extend it to work with right-padded@@ -601,7 +603,7 @@ public:class Phi3SlidingMaskMatcher : public ov::pass::MatcherPass {public:- OPENVINO_MATCHER_PASS_RTTI("npuw::LLMCompiledModel::Phi3SlidingMaskMatcher");+ OPENVINO_MATCHER_PASS_RTTI("ov::npuw::patterns::Phi3SlidingMaskMatcher");Phi3SlidingMaskMatcher(const std::shared_ptr<ov::Node>& attention_mask_node_ptr,const std::shared_ptr<ov::Node>& position_ids_node_ptr) {@@ -791,9 +793,10 @@ public:register_matcher(std::make_shared<opp::Matcher>(pattern, "ConvertTypeRelaxedToRegular"), callback);}};+class Phi3SlidingMask : public ov::pass::ModelPass {public:- OPENVINO_MODEL_PASS_RTTI("ov::npuw::LLMCompiledModel::Phi3SlidingMask");+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::Phi3SlidingMask");Phi3SlidingMask() = default;bool run_on_model(const std::shared_ptr<ov::Model>& model) override {std::shared_ptr<ov::Node> attention_mask_node_ptr = nullptr;@@ -827,10 +830,12 @@ public:};namespace {-uint32_t align_to(uint32_t value, uint32_t alignment) {+template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>+T align_to(T value, T alignment) {return (value + alignment - 1) & ~(alignment - 1);}-bool is_aligned_to(uint32_t value, uint32_t alignment) {+template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>+bool is_aligned_to(T value, T alignment) {return value % alignment == 0;}@@ -890,13 +895,13 @@ ov::element::Type optimize_kv_cache_storage(const std::shared_ptr<ov::Model>& moreturn kv_kache_storage_type;}-std::shared_ptr<ov::Model> redirect_new_kv_to_output(const std::shared_ptr<ov::Model>& model) {+bool redirect_new_kv_to_output(const std::shared_ptr<ov::Model>& model) {ov::pass::Manager manager("redirect_new_kv_to_output");- manager.register_pass<RedirectNewKvToOutput>();- manager.run_passes(model);+ manager.register_pass<RedirectNewKvToOutputMatcher>();+ bool result = manager.run_passes(model);model->validate_nodes_and_infer_types();- return model;+ return result;}bool remove_empty_kv_inputs(std::shared_ptr<ov::Model> model) {@@ -912,24 +917,84 @@ bool remove_empty_kv_inputs(std::shared_ptr<ov::Model> model) {return !ctx.old_params.empty();}-void decompose_GQA(std::shared_ptr<ov::Model> model, bool is_prefill_model) {+bool decompose_GQA(std::shared_ptr<ov::Model> model, bool is_prefill_model) {ov::pass::GraphRewrite rewr;rewr.add_matcher<GroupQueryAttentionDecomposition>(is_prefill_model);- rewr.run_on_model(model);+ return rewr.run_on_model(model);}-void patch_phi3_sliding_mask(const std::shared_ptr<ov::Model>& model) {+bool patch_phi3_sliding_mask(const std::shared_ptr<ov::Model>& model) {ov::pass::Manager manager;manager.register_pass<Phi3SlidingMask>();- manager.run_passes(model);+ return manager.run_passes(model);}} // namespace+class ConvertKVCacheToPrecision : public ov::pass::ModelPass {+ ov::element::Type m_lp_type;++public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::ConvertKVCacheToPrecision");+ explicit ConvertKVCacheToPrecision(const ov::element::Type lptype) : m_lp_type(lptype) {}++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override {+ auto ppp_result = cvt_kvcache_to_low_precision(model, m_lp_type);+ // PrePostProcessor currently always modifies the model in-place and returns the same model pointer, but let's+ // be defensive here and check it just in case+ OPENVINO_ASSERT(ppp_result == model,+ "PrePostProcessor should not create a new model, but returned a different one.");++ return true;+ }+};++class RedirectNewKvToOutput : public ov::pass::ModelPass {+public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::RedirectNewKvToOutput");+ RedirectNewKvToOutput() = default;++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override {+ return redirect_new_kv_to_output(model);+ }+};++class RemoveEmptyKVInputs : public ov::pass::ModelPass {+public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::RemoveEmptyKVInputs");+ RemoveEmptyKVInputs() = default;++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override {+ return remove_empty_kv_inputs(model);+ }+};++class DecomposeGQA : public ov::pass::ModelPass {+ bool m_is_prefill_model;++public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::DecomposeGQA");+ explicit DecomposeGQA(bool is_prefill_model) : m_is_prefill_model(is_prefill_model) {}++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override {+ return decompose_GQA(model, m_is_prefill_model);+ }+};++class PatchPhi3SlidingMask : public ov::pass::ModelPass {+public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::PatchPhi3SlidingMask");+ explicit PatchPhi3SlidingMask() = default;++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override {+ return patch_phi3_sliding_mask(model);+ }+};+class CutLMHead : public ov::pass::MatcherPass {public:- OPENVINO_MATCHER_PASS_RTTI("npuw::patterns::CutLMHead");- CutLMHead(std::shared_ptr<ov::Model>& lm_head_model) {+ OPENVINO_MATCHER_PASS_RTTI("ov::npuw::CutLMHead");+ explicit CutLMHead(std::shared_ptr<ov::Model>& lm_head_model) {// We are interested at first input to MatMul as a cut pointauto matmul = opp::wrap_type<ov::op::v0::MatMul>({opp::any_input(), opp::any_input()});@@ -1011,7 +1076,7 @@ public:};namespace {-std::shared_ptr<ov::Model> cut_lm_head(std::shared_ptr<ov::Model>& model) {+std::shared_ptr<ov::Model> cut_lm_head(const std::shared_ptr<ov::Model>& model) {ov::pass::GraphRewrite rewr;std::shared_ptr<ov::Model> lm_head_model = nullptr;rewr.add_matcher<CutLMHead>(lm_head_model);@@ -1469,25 +1534,43 @@ void apply_moe_config(ov::AnyMap& stage_config,}// Apply DEVICE_ROUTED MoE transformations to models-void apply_moe_device_routed_transforms(std::vector<std::shared_ptr<ov::Model>>& model_variants) {- LOG_INFO("Applying DEVICE_ROUTED MoE transformations...");+void apply_moe_device_routed_transforms(const std::shared_ptr<ov::Model>& model) {ov::npuw::pass::DeviceRoutedMoETransform moe_transform;ov::npuw::pass::GatherTo2DGather gather_transform;- for (auto& model : model_variants) {- moe_transform.run_on_model(model);- LOG_DEBUG(" Applied DEVICE_ROUTED transformations to model variant");+ moe_transform.run_on_model(model);+ LOG_DEBUG(" Applied DEVICE_ROUTED transformations to model variant");- // Apply Gather to 2D Gather transformation for HW optimization- gather_transform.run_on_model(model);- LOG_DEBUG(" Applied GatherTo2DGather transformation to model variant");- }- LOG_INFO("DEVICE_ROUTED MoE transformations completed");+ // Apply Gather to 2D Gather transformation for HW optimization+ gather_transform.run_on_model(model);+ LOG_DEBUG(" Applied GatherTo2DGather transformation to model variant");}-} // namespace+ov::element::Type choose_kv_cache_storage_type(const std::shared_ptr<ov::Model>& model,+ const ::intel_npu::Config& cfg,+ ov::AnyMap& other_props) {+ auto kv_kache_storage_type = ov::element::f16;++ // kv-cache-precision changes to fp8 does make sense unconditionally only if LPT passes succesfully applied+ if (cfg.get<::intel_npu::NPUW_LLM_OPTIMIZE_FP8>()) {+ kv_kache_storage_type = optimize_kv_cache_storage(model);+ }++ auto kv_cache_precision_hint = pop_option(other_props, ov::hint::kv_cache_precision.name());+ // ov::kv_cache_precision hint can additionally change kv-cache precision, but it might lead to less accurate+ // results+ if (kv_cache_precision_hint.has_value()) {+ auto suggested_kv_cache_precision = kv_cache_precision_hint.value().as<ov::element::Type>();+ if (kv_kache_storage_type != suggested_kv_cache_precision) {+ LOG_WARN("KV-cache precision HINT: " << suggested_kv_cache_precision << " applied");+ kv_kache_storage_type = suggested_kv_cache_precision;+ }+ }++ return kv_kache_storage_type;+}-void ov::npuw::LLMCompiledModel::convert_stateful_lora_to_stateless(std::shared_ptr<ov::Model>& model) {+void convert_stateful_lora_to_stateless(const std::shared_ptr<ov::Model>& model) {typedef std::shared_ptr<ov::op::util::AssignBase> PAssign;typedef std::shared_ptr<ov::op::util::ReadValueBase> PReadValue;std::vector<PReadValue> readValues;@@ -1530,6 +1613,114 @@ void ov::npuw::LLMCompiledModel::convert_stateful_lora_to_stateless(std::shared_model->add_parameters(new_parameters);}+std::shared_ptr<ov::Model> check_and_cut_lm_head(const std::shared_ptr<ov::Model>& m, const ::intel_npu::Config& cfg) {+ bool shared_head_enabled = cfg.get<::intel_npu::NPUW_LLM_SHARED_HEAD>();+ std::shared_ptr<ov::Model> lm_head_model = nullptr;+ if (shared_head_enabled) {+ LOG_DEBUG("Trying to separate Vocabulary matrix multiplication op into additional model...");+ lm_head_model = cut_lm_head(m);+ if (lm_head_model) {+ LOG_INFO("Three-model pipeline will be created: LM head will be shared between prefill and generate.");+ } else {+ LOG_WARN("Three-model pipeline is requested, but LM head cutting is failed,"+ " two-model pipeline will be created!");+ }+ } else {+ LOG_INFO("Two-model pipeline will be created.");+ }++ return lm_head_model;+}++} // namespace++class ReshapeToStatic : public ov::pass::ModelPass {+ uint32_t m_input_size;+ uint32_t m_kvcache_size;+ KVAxesPosition m_kv_axes_position;+ uint32_t m_lora_rank;+ uint32_t m_lhs_seq_size;++public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::ReshapeToStatic");+ explicit ReshapeToStatic(const uint32_t input_size,+ const uint32_t kvcache_size,+ const KVAxesPosition& kv_axes_position,+ const uint32_t lora_rank,+ const uint32_t lhs_seq_size = 0)+ : m_input_size(input_size),+ m_kvcache_size(kvcache_size),+ m_kv_axes_position(kv_axes_position),+ m_lora_rank(lora_rank),+ m_lhs_seq_size(lhs_seq_size) {}++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override {+ reshape_to_static(model, m_input_size, m_kvcache_size, m_kv_axes_position, m_lora_rank, m_lhs_seq_size);++ return true;+ }+};++class ReshapeSlicedHeadToStatic : public ov::pass::ModelPass {+ uint32_t m_batch_dim;+ std::size_t m_max_generation_token_len;++public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::ReshapeSlicedHeadToStatic");+ explicit ReshapeSlicedHeadToStatic(uint32_t batch_dim, std::size_t max_generation_token_len)+ : m_batch_dim(batch_dim),+ m_max_generation_token_len(max_generation_token_len) {}++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override {+ reshape_sliced_head_to_static(model, m_batch_dim, m_max_generation_token_len);++ return true;+ }+};++class SliceOutEmbeds : public ov::pass::ModelPass {+ uint32_t m_batch_dim;+ std::size_t m_max_generation_token_len;++public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::SliceOutEmbeds");+ explicit SliceOutEmbeds(uint32_t batch_dim, std::size_t max_generation_token_len)+ : m_batch_dim(batch_dim),+ m_max_generation_token_len(max_generation_token_len) {}++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override {+ slice_out_embeds(model, m_batch_dim, m_max_generation_token_len);++ return true;+ }+};++// Apply DEVICE_ROUTED MoE transformations to models+class ApplyMoEDeviceRoutedTransforms : public ov::pass::ModelPass {+public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::ApplyMoEDeviceRoutedTransforms");+ ApplyMoEDeviceRoutedTransforms() = default;++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override {+ apply_moe_device_routed_transforms(model);++ return true;+ }+};++class LoraStatefulToStatelessPass : public ov::pass::ModelPass {+public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::LoraStatefulToStatelessPass");++ explicit LoraStatefulToStatelessPass() = default;++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override {+ convert_stateful_lora_to_stateless(model);++ return true;+ }+};+std::vector<std::shared_ptr<ov::Model>> ov::npuw::LLMCompiledModel::create_generate_model_variants(const std::shared_ptr<ov::Model>& generate_model,const KVAxesPosition& axes,@@ -1582,12 +1773,8 @@ std::vector<std::shared_ptr<ov::Model>> ov::npuw::LLMCompiledModel::create_gener<< "): reshaping to static");// Reshape to target size- reshape_to_static(generate_variant,- max_generation_token_len,- kv_size,- axes,- m_max_lora_rank,- whisper_lhs_seq_size);+ ReshapeToStatic(max_generation_token_len, kv_size, axes, m_max_lora_rank, whisper_lhs_seq_size)+ .run_on_model(generate_variant);// Set unique name for this variantgenerate_variant->set_friendly_name(generate_model->get_friendly_name() + "_kv" + std::to_string(kv_size));@@ -1646,7 +1833,8 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& mauto use_whisper_key = pop_option(other_props, std::string("NPUW_WHISPER"));auto whisper_eos_token = pop_option(other_props, std::string("NPUW_WHISPER_EOS_TOKEN"));auto use_eagle_key = pop_option(other_props, std::string("NPUW_EAGLE"));- auto kv_cache_precision_hint = pop_option(other_props, ov::hint::kv_cache_precision.name());++ auto kv_kache_storage_type = choose_kv_cache_storage_type(model, m_cfg, other_props);// Solely used for serialization at the momentm_non_llm_props = other_props;@@ -1664,23 +1852,6 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& mrefine_dynamic_props(npuw_llm_props, npudesc);m_cfg.update(any_copy(npuw_llm_props));- auto kv_kache_storage_type = ov::element::f16;-- // kv-cache-precision changes to fp8 does make sense unconditionally only if LPT passes succesfully applied- if (m_cfg.get<::intel_npu::NPUW_LLM_OPTIMIZE_FP8>()) {- kv_kache_storage_type = optimize_kv_cache_storage(model);- }-- // ov::kv_cache_precision hint can additionally change kv-cache precision, but it might lead to less accurate- // results- if (kv_cache_precision_hint.has_value()) {- auto suggested_kv_cache_precision = kv_cache_precision_hint.value().as<ov::element::Type>();- if (kv_kache_storage_type != suggested_kv_cache_precision) {- LOG_WARN("KV-cache precision HINT: " << suggested_kv_cache_precision << " applied");- kv_kache_storage_type = suggested_kv_cache_precision;- }- }-// Decide on using fused flash attention tile based on provided option and NPU capabilities.// If hardware supports and attention hint is set to HFA, then we can use fused flash attention implementation// automatically, unless user explicitly disables it via NPUW_ATTN_HFA_FUSED=NO option.@@ -1791,13 +1962,13 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& mif (m_is_embedding) {LOG_DEBUG("Text-embedding model rebuild");- ov::npuw::util::prepare_text_embedding_model(kvcache_model, seq_len_dim);+ ov::npuw::util::PrepareTextEmbeddingModel(seq_len_dim).run_on_model(kvcache_model);} else {LOG_DEBUG("Transform kvcache model from stateful to stateless.");ov::pass::StatefulToStateless().run_on_model(kvcache_model);}- convert_stateful_lora_to_stateless(kvcache_model);+ LoraStatefulToStatelessPass().run_on_model(kvcache_model);LOG_DEBUG(" ...also convert BF16 to FP16");// Note: we need to identify original bf16 constants for potential weightless deserialization later@@ -1805,24 +1976,11 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& mm_bf16_consts = ov::npuw::s11n::get_bf16_consts(model);ov::pass::ConvertPrecision(ov::element::bf16, ov::element::f16).run_on_model(kvcache_model);- bool shared_head_enabled = m_cfg.get<::intel_npu::NPUW_LLM_SHARED_HEAD>();- std::shared_ptr<ov::Model> lm_head_model = nullptr;- if (shared_head_enabled) {- LOG_DEBUG("Trying to separate Vocabulary matrix multiplication op into additional model...");- lm_head_model = cut_lm_head(kvcache_model);- if (lm_head_model) {- LOG_INFO("Three-model pipeline will be created: LM head will be shared between prefill and generate.");- } else {- LOG_WARN("Three-model pipeline is requested, but LM head cutting is failed,"- " two-model pipeline will be created!");- }- } else {- LOG_INFO("Two-model pipeline will be created.");- }+ auto lm_head_model = check_and_cut_lm_head(kvcache_model, m_cfg);if (!m_is_whisper) {LOG_DEBUG("Try patch Phi-3 sliding window mask, if it exists.");- patch_phi3_sliding_mask(kvcache_model);+ PatchPhi3SlidingMask().run_on_model(kvcache_model);}LOG_DEBUG("Creating prefill model as clone of transformed kvcache one.");@@ -1839,27 +1997,27 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& mwhisper_lhs_seq_size =static_cast<uint32_t>(prefill_model->input("encoder_hidden_states").get_partial_shape()[1].get_length());- ov::npuw::util::prepare_whisper_prefill_model(prefill_model,- m_kvcache_desc.max_prompt_size,- whisper_lhs_seq_size); // Whisper decoder model- ov::npuw::util::prepare_whisper_kvcache_model(kvcache_model); // Whisper decoder_with_past model+ ov::npuw::util::PrepareWhisperPrefillModel(m_kvcache_desc.max_prompt_size,+ whisper_lhs_seq_size)+ .run_on_model(prefill_model); // Whisper decoder model+ ov::npuw::util::PrepareWhisperKVCacheModel().run_on_model(kvcache_model); // Whisper decoder_with_past model}LOG_DEBUG("Make prefill model with static shapes");m_max_lora_rank = m_cfg.get<::intel_npu::NPUW_LLM_MAX_LORA_RANK>();if (m_use_chunk_prefill) {- reshape_to_static(prefill_model,- static_cast<uint32_t>(m_prefill_chunk_size),- m_kvcache_desc.max_prompt_size,- axes,- m_max_lora_rank);+ ReshapeToStatic(static_cast<uint32_t>(m_prefill_chunk_size),+ m_kvcache_desc.max_prompt_size,+ axes,+ m_max_lora_rank)+ .run_on_model(prefill_model);} else {- reshape_to_static(prefill_model,- m_kvcache_desc.max_prompt_size,- m_kvcache_desc.max_prompt_size,- axes,- m_max_lora_rank,- whisper_lhs_seq_size);+ ReshapeToStatic(m_kvcache_desc.max_prompt_size,+ m_kvcache_desc.max_prompt_size,+ axes,+ m_max_lora_rank,+ whisper_lhs_seq_size)+ .run_on_model(prefill_model);}LOG_DEBUG("Make kvcache model with static shapes");@@ -1870,15 +2028,15 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& mLOG_DEBUG("Shared LM head: slice the prefill output");// KVCache model is already reshaped to [1, max_generation_token_len, embed size],// so only apply slice to the Prefill model:- slice_out_embeds(prefill_model, axes.batch, m_kvcache_desc.max_generation_token_len);+ SliceOutEmbeds(axes.batch, m_kvcache_desc.max_generation_token_len).run_on_model(prefill_model);LOG_DEBUG("Make LM head model with static shapes");- reshape_sliced_head_to_static(lm_head_model, axes.batch, m_kvcache_desc.max_generation_token_len);+ ReshapeSlicedHeadToStatic(axes.batch, m_kvcache_desc.max_generation_token_len).run_on_model(lm_head_model);}LOG_DEBUG("5.1, decompose GroupQueryAttention OP");- decompose_GQA(prefill_model, true);+ DecomposeGQA(true).run_on_model(prefill_model);for (auto& model_variant : generate_model_variants) {- decompose_GQA(model_variant, false);+ DecomposeGQA(false).run_on_model(model_variant);}const auto prefill_attn_hint = m_cfg.get<::intel_npu::NPUW_LLM_PREFILL_ATTENTION_HINT>();@@ -1901,7 +2059,7 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m// Apply optimization to all variants and track resultssize_t optimized_count = 0;for (auto& model_variant : generate_model_variants) {- if (ov::npuw::util::optimize_value_tensors(model_variant, false)) {+ if (ov::npuw::util::OptimizeValueTensors(false).run_on_model(model_variant)) {++optimized_count;}}@@ -1923,7 +2081,7 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m" variants were optimized, which is not allowed.");}}- if (!prefill_attn_dyn && ov::npuw::util::optimize_value_tensors(prefill_model, true)) {+ if (!prefill_attn_dyn && ov::npuw::util::OptimizeValueTensors(true).run_on_model(prefill_model)) {LOG_DEBUG("V-tensors tranposed in prefill model");m_kvcache_desc.v_tensors_transposed_pre = true;}@@ -1933,25 +2091,25 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& mif (!m_is_embedding) {if (!m_use_chunk_prefill) {- NPUW_ASSERT(remove_empty_kv_inputs(prefill_model));+ NPUW_ASSERT(RemoveEmptyKVInputs().run_on_model(prefill_model));} else {LOG_DEBUG("Don't remove input key/values from prefill model.");LOG_DEBUG("Ask prefill model to output key/values for prefill chunk size tokens.");- prefill_model = redirect_new_kv_to_output(prefill_model);+ RedirectNewKvToOutput().run_on_model(prefill_model);}LOG_DEBUG("Optimize generate model to output key/values for new token.");for (size_t i = 0; i < generate_model_variants.size(); ++i) {- generate_model_variants[i] = redirect_new_kv_to_output(generate_model_variants[i]);+ RedirectNewKvToOutput().run_on_model(generate_model_variants[i]);}}LOG_DEBUG("Converting KV-cache in generate model to FP16.");for (size_t i = 0; i < generate_model_variants.size(); ++i) {- generate_model_variants[i] = cvt_kvcache_to_low_precision(generate_model_variants[i], kv_kache_storage_type);+ ConvertKVCacheToPrecision(kv_kache_storage_type).run_on_model(generate_model_variants[i]);}LOG_DEBUG("Converting KV-cache in prefill model to FP16.");- prefill_model = cvt_kvcache_to_low_precision(prefill_model, kv_kache_storage_type);+ ConvertKVCacheToPrecision(kv_kache_storage_type).run_on_model(prefill_model);auto prefill_config =prefill_config_opt.value_or(get_default_prefill_config(prefill_model, npudesc)).as<ov::AnyMap>();@@ -2014,7 +2172,11 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m// Apply model transformations only to GENERATE stage (PREFILL doesn't support DEVICE_ROUTED transformations)if (generate_moe_hint == ::intel_npu::npuw::llm::MoEHint::DEVICE_ROUTED) {- apply_moe_device_routed_transforms(generate_model_variants);+ LOG_INFO("Applying DEVICE_ROUTED MoE transformations to " << generate_model_variants.size() << " variants");+ for (auto&& model_variant : generate_model_variants) {+ ApplyMoEDeviceRoutedTransforms().run_on_model(model_variant);+ }+ LOG_INFO("DEVICE_ROUTED MoE transformations completed");}}@@ -2072,27 +2234,13 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m// Regularize models for the better partitioning assuming it is a transformer// Apply these transformations to all variant models{- ov::pass::GraphRewrite rewr;- rewr.add_matcher<ov::npuw::patterns::regularize::AttentionBroadcast>();- rewr.add_matcher<ov::npuw::patterns::regularize::AttentionBroadcast2>();- if (generate_attn_dyn || generate_attn_pyramid || generate_attn_hfa) {- for (auto& model_variant : generate_model_variants) {- rewr.run_on_model(model_variant);- }- }- if (prefill_attn_dyn || prefill_attn_pyramid || prefill_attn_hfa) {- rewr.run_on_model(prefill_model);- }-- // FIXME: generally all these patterns are supposed to improve the partitioning - thus- // the performance. However, ShapeOfParameter seems to be working fine for all known case,- // while AttentionBroadcast patterns might break the partitioning (related to F16IC).- ov::pass::GraphRewrite rewr2;- rewr2.add_matcher<ov::npuw::patterns::regularize::ShapeOfParameter>();+ ov::npuw::patterns::regularize::RegularizeSDPA(prefill_attn_dyn || prefill_attn_pyramid || prefill_attn_hfa)+ .run_on_model(prefill_model);for (auto& model_variant : generate_model_variants) {- rewr2.run_on_model(model_variant);+ ov::npuw::patterns::regularize::RegularizeSDPA(generate_attn_dyn || generate_attn_pyramid ||+ generate_attn_hfa)+ .run_on_model(model_variant);}- rewr2.run_on_model(prefill_model);}// Compile multiple generate model variants with different sizesdiff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.hpp b/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.hppindex f5a0c415305..cc216f0de9d 100644--- a/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.hpp+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.hpp@@ -101,7 +101,6 @@ private:std::vector<uint32_t> m_kvcache_sizes; // Corresponding KV cache sizes for each variant// Support LoRA- void convert_stateful_lora_to_stateless(std::shared_ptr<ov::Model>& model);uint32_t m_max_lora_rank = 32;// Support prefix cachingdiff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model_utils.cpp b/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model_utils.cppindex 2e7ad698d63..e8f4e57668f 100644--- a/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model_utils.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model_utils.cpp@@ -514,7 +514,7 @@ bool ov::npuw::util::has_input(const std::shared_ptr<ov::Model>& model, const streturn it != inputs.end();}-bool ov::npuw::util::optimize_value_tensors(std::shared_ptr<ov::Model> model, bool isPrefill) {+bool ov::npuw::util::OptimizeValueTensors::run_on_model(const std::shared_ptr<ov::Model>& model) {ov::pass::GraphRewrite rewr;// Check if any SDPA has sink input@@ -532,7 +532,7 @@ bool ov::npuw::util::optimize_value_tensors(std::shared_ptr<ov::Model> model, bo// TODO: evaluate performance by older npu-driversrewr.add_matcher<ov::pass::ScaledDotProductAttentionDecomposition>();} else {- rewr.add_matcher<ScaledDotProductAttentionDecomposition>(isPrefill);+ rewr.add_matcher<ScaledDotProductAttentionDecomposition>(m_is_prefill);}TransposeValueTensors::Context ctx;@@ -595,7 +595,7 @@ bool is_fake_cvt_to_key_tensor(const ov::Input<ov::Node>& reader) {return fc_reader.begin()->get_index() == 1;}-void expose_runtime_states_as_outputs(std::shared_ptr<ov::Model>& model) {+void expose_runtime_states_as_outputs(const std::shared_ptr<ov::Model>& model) {// Find all ReadValue nodesov::NodeVector read_value_nodes;for (const auto& op : model->get_ops()) {@@ -650,7 +650,7 @@ void expose_runtime_states_as_outputs(std::shared_ptr<ov::Model>& model) {model->validate_nodes_and_infer_types();}-void remove_cache_position(std::shared_ptr<ov::Model>& model) {+void remove_cache_position(const std::shared_ptr<ov::Model>& model) {// Build subgraph that will replace cache_posauto input_ids = model->input("input_ids").get_node();auto shape_of_node = std::make_shared<ov::op::v3::ShapeOf>(input_ids->outputs()[0]);@@ -683,7 +683,7 @@ void remove_cache_position(std::shared_ptr<ov::Model>& model) {model->validate_nodes_and_infer_types();}-void expose_runtime_states_as_inputs(std::shared_ptr<ov::Model>& model) {+void expose_runtime_states_as_inputs(const std::shared_ptr<ov::Model>& model) {// Store Assign nodes to perform remove_sink later onov::SinkVector assigns;// To add new Params to the model@@ -734,7 +734,7 @@ void expose_runtime_states_as_inputs(std::shared_ptr<ov::Model>& model) {}}-void normalize_input_key_value_names(std::shared_ptr<ov::Model>& model) {+void normalize_input_key_value_names(const std::shared_ptr<ov::Model>& model) {ov::ResultVector new_results, old_results;for (const auto& in : model->inputs()) {if (in.get_any_name().find("decoder") == std::string::npos) {@@ -750,7 +750,7 @@ void normalize_input_key_value_names(std::shared_ptr<ov::Model>& model) {model->validate_nodes_and_infer_types();}-void normalize_output_key_value_names(std::shared_ptr<ov::Model>& model) {+void normalize_output_key_value_names(const std::shared_ptr<ov::Model>& model) {ov::ResultVector new_results, old_results;for (const auto& out : model->outputs()) {if (out.get_any_name().find("decoder") == std::string::npos) {@@ -765,7 +765,7 @@ void normalize_output_key_value_names(std::shared_ptr<ov::Model>& model) {model->validate_nodes_and_infer_types();}-void add_attention_mask_input(std::shared_ptr<ov::Model> model,+void add_attention_mask_input(const std::shared_ptr<ov::Model>& model,const uint32_t& max_prompt_size = 0,const uint32_t& lhs_seq_size = 0,bool transform_cross_attn = false) {@@ -782,7 +782,7 @@ void add_attention_mask_input(std::shared_ptr<ov::Model> model,ov::pass::Validate().run_on_model(model);}-void add_cache_position_input(std::shared_ptr<ov::Model> model) {+void add_cache_position_input(const std::shared_ptr<ov::Model>& model) {ov::pass::GraphRewrite rewr;rewr.add_matcher<CachePositionInput>(model);rewr.run_on_model(model);@@ -791,9 +791,7 @@ void add_cache_position_input(std::shared_ptr<ov::Model> model) {}} // namespace-std::shared_ptr<ov::Model> ov::npuw::util::prepare_whisper_prefill_model(std::shared_ptr<ov::Model>& model,- const uint32_t& max_prompt_size,- const uint32_t& lhs_seq_size) {+bool ov::npuw::util::PrepareWhisperPrefillModel::run_on_model(const std::shared_ptr<ov::Model>& model) {// 2) Remove all non-runtime states from inputs (they empty on first iteration)// remove_input_kv_tensors(model); -> Done for LLM also// 3) Expose all states that requires initialization on the first run as outputs@@ -805,14 +803,14 @@ std::shared_ptr<ov::Model> ov::npuw::util::prepare_whisper_prefill_model(std::sh// 5) Normalize output names - should be done in stateful_to_stateless_transformationnormalize_output_key_value_names(model);- add_attention_mask_input(model, max_prompt_size, lhs_seq_size, true);+ add_attention_mask_input(model, m_max_prompt_size, m_lhs_seq_size, true);model->validate_nodes_and_infer_types();- return model;++ return true;}-std::shared_ptr<ov::Model> ov::npuw::util::prepare_whisper_kvcache_model(std::shared_ptr<ov::Model>& model) {- // FIXME: normalization should be done inside stateful_to_stateless_transformation+bool ov::npuw::util::PrepareWhisperKVCacheModel::run_on_model(const std::shared_ptr<ov::Model>& model) {normalize_input_key_value_names(model);normalize_output_key_value_names(model);expose_runtime_states_as_inputs(model);@@ -826,5 +824,6 @@ std::shared_ptr<ov::Model> ov::npuw::util::prepare_whisper_kvcache_model(std::shmodel->reshape({{"input_ids", ov::PartialShape({-1, 1})}});model->validate_nodes_and_infer_types();- return model;++ return true;}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.hppindex d963c7b279e..3ce5b9934be 100644--- 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@@ -26,13 +26,36 @@ public:bool has_input(const std::shared_ptr<ov::Model>& model, const std::string& name);// SDPA-unroll and transpose transformations-bool optimize_value_tensors(std::shared_ptr<ov::Model> model, bool isPrefill);+class OptimizeValueTensors : public ov::pass::ModelPass {+ bool m_is_prefill;-std::shared_ptr<ov::Model> prepare_whisper_prefill_model(std::shared_ptr<ov::Model>& model,- const uint32_t& max_prompt_size,- const uint32_t& lhs_seq_size);+public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::OptimizeValueTensors");+ explicit OptimizeValueTensors(bool is_prefill) : m_is_prefill(is_prefill) {}++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override;+};++class PrepareWhisperPrefillModel : public ov::pass::ModelPass {+ uint32_t m_max_prompt_size;+ uint32_t m_lhs_seq_size;++public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::PrepareWhisperPrefillModel");+ explicit PrepareWhisperPrefillModel(uint32_t max_prompt_size, uint32_t lhs_seq_size)+ : m_max_prompt_size(max_prompt_size),+ m_lhs_seq_size(lhs_seq_size) {}-std::shared_ptr<ov::Model> prepare_whisper_kvcache_model(std::shared_ptr<ov::Model>& model);+ bool run_on_model(const std::shared_ptr<ov::Model>& model) override;+};++class PrepareWhisperKVCacheModel : public ov::pass::ModelPass {+public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::PrepareWhisperKVCacheModel");+ PrepareWhisperKVCacheModel() = default;++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override;+};// clang-format off} // namespace ovdiff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/sdpa.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/sdpa.cppindex f1fc3e31449..708454c20d9 100644--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/sdpa.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/sdpa.cpp@@ -275,6 +275,26 @@ ShapeOfParameter::ShapeOfParameter() {register_matcher(std::make_shared<opp::Matcher>(param_shp, "ShapeOfParameter"), std::move(callback));}+bool RegularizeSDPA::run_on_model(const std::shared_ptr<ov::Model>& model) {+ bool model_changed = false;+ if (m_run_broadcast_pattern) {+ ov::pass::GraphRewrite rewr;+ rewr.add_matcher<ov::npuw::patterns::regularize::AttentionBroadcast>();+ rewr.add_matcher<ov::npuw::patterns::regularize::AttentionBroadcast2>();++ model_changed |= rewr.run_on_model(model);+ }++ // FIXME: generally all these patterns are supposed to improve the partitioning - thus+ // the performance. However, ShapeOfParameter seems to be working fine for all known case,+ // while AttentionBroadcast patterns might break the partitioning (related to F16IC).+ ov::pass::GraphRewrite rewr2;+ rewr2.add_matcher<ov::npuw::patterns::regularize::ShapeOfParameter>();+ model_changed |= rewr2.run_on_model(model);++ return model_changed;+}+} // namespace regularize} // namespace patternsdiff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/sdpa.hpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/sdpa.hppindex 2b4d9cd83bb..7bb70827000 100644--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/sdpa.hpp+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/sdpa.hpp@@ -56,6 +56,16 @@ public:ShapeOfParameter();};+class RegularizeSDPA : public ov::pass::ModelPass {+ bool m_run_broadcast_pattern = false;++public:+ OPENVINO_MODEL_PASS_RTTI("ov::npuw::RegularizeSDPA");+ explicit RegularizeSDPA(bool run_broadcast_pattern) : m_run_broadcast_pattern(run_broadcast_pattern) {};++ bool run_on_model(const std::shared_ptr<ov::Model>& model) override;+};+} // namespace regularize} // namespace patternsdiff --git a/src/plugins/intel_npu/tests/unit/npuw/transpose_vt.cpp b/src/plugins/intel_npu/tests/unit/npuw/transpose_vt.cppindex bb599eaa2de..56ea6003299 100644--- a/src/plugins/intel_npu/tests/unit/npuw/transpose_vt.cpp+++ b/src/plugins/intel_npu/tests/unit/npuw/transpose_vt.cpp@@ -35,7 +35,7 @@ typedef std::tuple <> OptimizeVTTestParamsTuple;struct OptimizeVTTestParams {- #define _AT(idx) std::tuple_element<idx, OptimizeVTTestParamsTuple>::type+ #define _AT(idx) std::tuple_element<idx, OptimizeVTTestParamsTuple>::type_AT(0) inputShape;_AT(1) withConvert;@@ -58,9 +58,9 @@ class TransposeVTTest : public testing::WithParamInterface<OptimizeVTTestParamsTpublic:void Validate() const {auto test = OptimizeVTTestParams{GetParam()};-+auto isValidSubgraph = test.withTranspose;- ASSERT_EQ(isValidSubgraph, ov::npuw::util::optimize_value_tensors(model, test.withHpAttenMask));+ ASSERT_EQ(isValidSubgraph, ov::npuw::util::OptimizeValueTensors(test.withHpAttenMask).run_on_model(model));//std::shared_ptr<ov::Model> model = ...; // your model@@ -75,8 +75,8 @@ public:serialize_pass.run_on_model(model);#endif-- // validation of High Precision attention mask - implies enabling SDPA layer to be unrolled,++ // validation of High Precision attention mask - implies enabling SDPA layer to be unrolled,// and also specific FP16 activation transformation in partitioning// Note: When withSink=true, standard OpenVINO SDPA decomposition is used which doesn't support HPif (test.withSDPA && !test.withSink) {@@ -94,7 +94,7 @@ public:// input to add is 32b via convert / or via 32b parameterbool 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;});};@@ -108,7 +108,7 @@ public: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 modelov::pass::Serialize serialize_pass(xml_path, bin_path);serialize_pass.run_on_model(partitioned_model);@@ -123,16 +123,16 @@ public:// assume in lhs we have a maskauto 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{"+ 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);}@@ -149,7 +149,7 @@ public: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+ // should be only one add as atention_maskbAttentionMaskVerified = true;}@@ -174,9 +174,9 @@ public: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+ // should be only one add as atention_maskbAttentionMaskResultVerified = true;- }+ }}}@@ -189,7 +189,7 @@ public:auto test = OptimizeVTTestParams{obj.param};std::ostringstream result;- result << "npuw_llm_pipeline_" << test.inputShape << "_"+ result << "npuw_llm_pipeline_" << test.inputShape << "_"<< (test.kind == NetworkKind::MHA ? "MHA" : "GQA")<< (test.withConvert ? "_with_convert" : "")<< (test.withSDPA ? "_SDPA" : "")@@ -197,7 +197,7 @@ public:<< (test.withHpAttenMask ? "_HP" : "")<< (!test.withTranspose ? "_NEGATIVE" : "");return result.str();- }+ }protected:@@ -208,7 +208,7 @@ protected: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");@@ -227,8 +227,8 @@ protected: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 = test.withConvert ?- std::static_pointer_cast<ov::Node>(std::make_shared<ov::op::v0::Convert>(param, ov::element::f32)) :+ 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 (test.withConvert) {convert->set_friendly_name("convert");@@ -261,12 +261,12 @@ protected:std::shared_ptr<ov::Node> concat_or_reshape = concat;if (test.kind == NetworkKind::GQA) {- auto unsqueeze_pattern = create_shape_constant({2}, "unsqueese_pattern");+ 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");- auto broadcast_pattern = create_shape_constant({1, 8, 4, input_2 + 1, input_3}, "broadcast_pattern");+ auto broadcast_pattern = create_shape_constant({1, 8, 4, input_2 + 1, input_3}, "broadcast_pattern");//TODO: v1::Broadcast not workingauto broadcast = std::make_shared<ov::op::v3::Broadcast>(unsqueeze, broadcast_pattern, ov::op::BroadcastType::BIDIRECTIONAL);broadcast->set_friendly_name("broadcast");@@ -331,9 +331,9 @@ protected: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;};@@ -342,7 +342,7 @@ protected:TEST_P(TransposeVTTest, smoke_Run_MatchAndTransposeVT) {Validate();}-+namespace {// eliminate direct shape dependency to match llama2, as in test and in optimize functionconst std::vector<ov::Shape> input_shapes{{1, 0, 1151, 128}, {1, 0, 1141, 64}};@@ -365,8 +365,8 @@ const std::vector<NetworkKind> networkKind = {INSTANTIATE_TEST_SUITE_P(smoke_Run_MatchAndTransposeVT,TransposeVTTest,::testing::Combine(- ::testing::ValuesIn(input_shapes),- ::testing::ValuesIn(withTranspose),+ ::testing::ValuesIn(input_shapes),+ ::testing::ValuesIn(withTranspose),::testing::ValuesIn(withBroadCast),::testing::ValuesIn(withSDPA),::testing::ValuesIn(withHpAttenMask),