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: Introduce a mock npuw::CompiledModel class injection (#34728)
Dmitry Matveev857e6734ad54
diff --git a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cppindex 8275cf2e17f..d009c0da7a5 100644--- a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp@@ -172,7 +172,7 @@ ov::npuw::ICompiledModel::ICompiledModel(const std::shared_ptr<ov::Model>& modelov::npuw::CompiledModel::CompiledModel(const std::shared_ptr<ov::Model>& model,const std::shared_ptr<const ov::IPlugin>& plugin,const ov::AnyMap& properties)- : ov::npuw::ICompiledModel(model, plugin),+ : ov::npuw::ICompiledModel_v0(model, plugin),m_options_desc(std::make_shared<::intel_npu::OptionsDesc>()),m_cfg(m_options_desc),m_name(model->get_friendly_name()),@@ -595,7 +595,7 @@ ov::npuw::CompiledModel::CompiledModel(const std::shared_ptr<ov::Model>& model,ov::npuw::CompiledModel::CompiledModel(const std::shared_ptr<ov::Model>& model,const std::shared_ptr<const ov::IPlugin>& plugin,const bool serialized)- : ov::npuw::ICompiledModel(model, plugin),+ : ov::npuw::ICompiledModel_v0(model, plugin),m_options_desc(std::make_shared<::intel_npu::OptionsDesc>()),m_cfg(m_options_desc),m_name(model->get_friendly_name()),@@ -1508,6 +1508,18 @@ void ov::npuw::CompiledModel::reconstruct_closure() {}}+std::size_t ov::npuw::CompiledModel::num_submodels() const {+ return m_compiled_submodels.size();+}++std::shared_ptr<ov::npuw::weights::Bank> ov::npuw::CompiledModel::get_weights_bank() const {+ return m_weights_bank;+}++void ov::npuw::CompiledModel::set_weights_bank(std::shared_ptr<ov::npuw::weights::Bank> bank) {+ m_weights_bank = std::move(bank);+}+void ov::npuw::CompiledModel::finalize_weights_bank() {LOG_INFO("Finalizing weights bank...");std::shared_future<void> weights_bank_evaluation = std::async(std::launch::async, [&]() {diff --git a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hppindex 1a2eee32133..ee80060cc77 100644--- a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp+++ b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp@@ -39,6 +39,34 @@ public:ICompiledModel(const std::shared_ptr<ov::Model>& model, const std::shared_ptr<const ov::IPlugin>& plugin);};+// Minimum interface consumed by LLMCompiledModel from its sub-compiled models+// (prefill / generate variants / lm_head). CompiledModel implements this in+// production; tests can inject a lightweight mock that only overrides what it+// actually needs.+class ICompiledModel_v0 : public ov::npuw::ICompiledModel {+public:+ ICompiledModel_v0(const std::shared_ptr<ov::Model>& model, const std::shared_ptr<const ov::IPlugin>& plugin)+ : ov::npuw::ICompiledModel(model, plugin) {}++ // Infer-request lifecycle+ virtual std::shared_ptr<IBaseInferRequest> create_base_infer_request() const = 0;+ virtual std::shared_ptr<ov::IAsyncInferRequest> wrap_async_infer_request(+ std::shared_ptr<IBaseInferRequest> internal_request) const = 0;+ virtual std::string submodel_device(std::size_t idx) const = 0;+ virtual std::size_t num_submodels() const = 0;++ // Weights-bank management (model sharing / weightless serialization)+ virtual std::shared_ptr<weights::Bank> get_weights_bank() const = 0;+ virtual void set_weights_bank(std::shared_ptr<weights::Bank> bank) = 0;+ virtual void finalize_weights_bank() = 0;+ virtual void reconstruct_closure() = 0;++ // Serialization+ virtual void serialize(std::ostream& stream, const s11n::CompiledContext& ctx) const = 0;++ virtual ~ICompiledModel_v0() = default;+};+// Forward declarationsclass InferRequest;@@ -46,7 +74,7 @@ namespace moe {class MoEExecutor;}-class CompiledModel : public ov::npuw::ICompiledModel {+class CompiledModel : public ov::npuw::ICompiledModel_v0 {using DevList = std::vector<std::string>;using GetPropertiesMap =std::map<std::string, std::tuple<ov::PropertyMutability, std::function<ov::Any(const ::intel_npu::Config&)>>>;@@ -73,6 +101,18 @@ public:// Custom destructor to wait for Delayed~CompiledModel();+ // ICompiledModel_v0 overrides+ std::shared_ptr<IBaseInferRequest> create_base_infer_request() const override;+ std::shared_ptr<ov::IAsyncInferRequest> wrap_async_infer_request(+ std::shared_ptr<IBaseInferRequest> internal_request) const override;+ std::string submodel_device(std::size_t idx) const override;+ std::size_t num_submodels() const override;+ std::shared_ptr<weights::Bank> get_weights_bank() const override;+ void set_weights_bank(std::shared_ptr<weights::Bank> bank) override;+ void finalize_weights_bank() override;+ void reconstruct_closure() override;+ void serialize(std::ostream& stream, const s11n::CompiledContext& ctx) const override;+private:// FIXME: This class has many friends..friend class IBaseInferRequest;@@ -100,7 +140,6 @@ private:void report_io() const;- void serialize(std::ostream& stream, const ov::npuw::s11n::CompiledContext& ctx) const;static std::shared_ptr<CompiledModel> deserialize(std::istream& stream,const std::shared_ptr<const ov::IPlugin>& plugin,const ov::AnyMap& properties,@@ -115,12 +154,8 @@ private:std::shared_ptr<const ::intel_npu::Plugin> get_npuw_plugin() const;std::shared_ptr<ov::ISyncInferRequest> create_sync_infer_request() const override;- // API for easily create and manage NPUW infer-requests- std::shared_ptr<ov::npuw::IBaseInferRequest> create_base_infer_request() const;- std::shared_ptr<ov::IAsyncInferRequest> wrap_async_infer_request(- std::shared_ptr<ov::npuw::IBaseInferRequest> internal_request) const;+ // API for easily create and manage NPUW infer-requests (promoted to ICompiledModel_v0)- std::string submodel_device(const std::size_t idx) const;bool is_gather_closure(const std::size_t idx, const std::size_t cidx) const;bool unpack_required(const std::size_t idx) const;bool unpack_required(const std::size_t idx, const std::size_t cidx) const;@@ -130,12 +165,11 @@ private:bool should_use_quantized_host_gather(const std::shared_ptr<ov::Model>& model, const ov::AnyMap& properties) const;- // For full deserialization flow with weights- void reconstruct_closure();+ // For full deserialization flow with weights (promoted to ICompiledModel_v0)// For weightless serialization flowvoid store_const_offsets(const std::shared_ptr<ov::Model>& model);- void finalize_weights_bank();+ // finalize_weights_bank() promoted to ICompiledModel_v0void detach_memory();std::string global_mem_device() const;std::string funcall_mem_device(const std::size_t idx) const;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.cppindex 223d456c081..1a823b36e72 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@@ -1263,6 +1263,9 @@ struct NPUDesc {std::optional<NPUDesc> extract_npu_descriptor(const std::shared_ptr<const ov::IPlugin>& plugin,const ov::AnyMap& config) {+ if (!plugin->get_core()) {+ return std::nullopt;+ }const auto all_devices = plugin->get_core()->get_property("NPU", ov::available_devices);if (all_devices.empty()) {return std::nullopt;@@ -1785,6 +1788,14 @@ std::vector<std::shared_ptr<ov::Model>> ov::npuw::LLMCompiledModel::create_generreturn generate_model_variants;}+std::shared_ptr<ov::npuw::ICompiledModel_v0> ov::npuw::LLMCompiledModel::make_compiled_model(+ const std::shared_ptr<ov::Model>& model,+ const std::shared_ptr<const ov::IPlugin>& plugin,+ const ov::AnyMap& properties) {+ return std::dynamic_pointer_cast<ov::npuw::ICompiledModel_v0>(+ ov::npuw::ICompiledModel::create(model, plugin, properties));+}+void ov::npuw::LLMCompiledModel::compile_generate_model_variants(const std::vector<std::shared_ptr<ov::Model>>& generate_model_variants,const std::shared_ptr<const ov::IPlugin>& plugin,@@ -1802,8 +1813,7 @@ void ov::npuw::LLMCompiledModel::compile_generate_model_variants(auto& generate_variant = generate_model_variants[i];// Compile the variant- auto compiled_variant = std::dynamic_pointer_cast<ov::npuw::CompiledModel>(- ov::npuw::ICompiledModel::create(generate_variant, plugin, generate_config));+ auto compiled_variant = m_compiled_model_factory(generate_variant, plugin, generate_config);NPUW_ASSERT(compiled_variant && "Can't create ov::npuw::CompiledModel for generate variant!");m_generate_compiled_variants.push_back(compiled_variant);@@ -1816,11 +1826,13 @@ void ov::npuw::LLMCompiledModel::compile_generate_model_variants(ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& model,const std::shared_ptr<const ov::IPlugin>& plugin,- const ov::AnyMap& properties)+ const ov::AnyMap& properties,+ CompiledModelFactory factory): ov::npuw::ICompiledModel(model, plugin),m_name(model->get_friendly_name()),m_options_desc(std::make_shared<::intel_npu::OptionsDesc>()),- m_cfg(m_options_desc) {+ m_cfg(m_options_desc),+ m_compiled_model_factory(std::move(factory)) {LOG_DEBUG("Creating LLMCompiledModel");LOG_BLOCK();@@ -2246,8 +2258,7 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m// Compile multiple generate model variants with different sizescompile_generate_model_variants(generate_model_variants, plugin, generate_config);- m_prefill_compiled = std::dynamic_pointer_cast<ov::npuw::CompiledModel>(- ov::npuw::ICompiledModel::create(prefill_model, plugin, prefill_config));+ m_prefill_compiled = m_compiled_model_factory(prefill_model, plugin, prefill_config);NPUW_ASSERT(m_prefill_compiled && "Can't create ov::npuw::CompiledModel for passed prefill ""model and its config, please check passed config.");if (lm_head_model) {@@ -2258,8 +2269,7 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& mapply_weights_bank_name(lm_head_config, weights_bank_name);- m_lm_head_compiled = std::dynamic_pointer_cast<ov::npuw::CompiledModel>(- ov::npuw::ICompiledModel::create(lm_head_model, plugin, lm_head_config));+ m_lm_head_compiled = m_compiled_model_factory(lm_head_model, plugin, lm_head_config);NPUW_ASSERT(m_lm_head_compiled);}@@ -2412,8 +2422,8 @@ void ov::npuw::LLMCompiledModel::serialize(std::ostream& stream, const ov::npuw:}// Serialize bank name- const auto& kv_bank = m_kvcache_compiled->m_weights_bank;- const auto& p_bank = m_prefill_compiled->m_weights_bank;+ const auto& kv_bank = m_kvcache_compiled->get_weights_bank();+ const auto& p_bank = m_prefill_compiled->get_weights_bank();NPUW_ASSERT(kv_bank && p_bank && kv_bank == p_bank && "Prefill and KVCache models' weight bank should be shared!");write(stream, kv_bank->get_name());@@ -2489,32 +2499,32 @@ std::shared_ptr<ov::npuw::LLMCompiledModel> ov::npuw::LLMCompiledModel::import_mauto bank = ov::npuw::weights::bank(bank_name, compiled->get_plugin()->get_core(), "");for (const auto& compiled_variant : compiled->m_generate_compiled_variants) {- compiled_variant->m_weights_bank = bank;+ compiled_variant->set_weights_bank(bank);compiled_variant->finalize_weights_bank();}- compiled->m_prefill_compiled->m_weights_bank = bank;+ compiled->m_prefill_compiled->set_weights_bank(bank);compiled->m_prefill_compiled->finalize_weights_bank();if (compiled->m_lm_head_compiled) {- compiled->m_lm_head_compiled->m_weights_bank = bank;+ compiled->m_lm_head_compiled->set_weights_bank(bank);compiled->m_lm_head_compiled->finalize_weights_bank();}} else {auto bank =ov::npuw::weights::Bank::deserialize(model_stream, compiled->get_plugin()->get_core(), bank_name);- compiled->m_kvcache_compiled->m_weights_bank = bank;+ compiled->m_kvcache_compiled->set_weights_bank(bank);for (const auto& compiled_variant : compiled->m_generate_compiled_variants) {- compiled_variant->m_weights_bank = bank;+ compiled_variant->set_weights_bank(bank);compiled_variant->reconstruct_closure();}- compiled->m_prefill_compiled->m_weights_bank = bank;+ compiled->m_prefill_compiled->set_weights_bank(bank);compiled->m_prefill_compiled->reconstruct_closure();if (compiled->m_lm_head_compiled) {- compiled->m_lm_head_compiled->m_weights_bank = bank;+ compiled->m_lm_head_compiled->set_weights_bank(bank);compiled->m_lm_head_compiled->reconstruct_closure();}}diff --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 cc216f0de9d..b714b704dff 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@@ -43,9 +43,24 @@ public:bool v_tensors_transposed_gen = false; // generate};+ // Factory type for creating sub-compiled-models (prefill / generate / lm_head).+ // The default builds an ov::npuw::CompiledModel via ICompiledModel::create().+ // Tests may inject a custom factory to inspect the transformed IR or stub the+ // compilation stage entirely.+ using CompiledModelFactory =+ std::function<std::shared_ptr<ov::npuw::ICompiledModel_v0>(const std::shared_ptr<ov::Model>&,+ const std::shared_ptr<const ov::IPlugin>&,+ const ov::AnyMap&)>;++ static std::shared_ptr<ov::npuw::ICompiledModel_v0> make_compiled_model(+ const std::shared_ptr<ov::Model>& model,+ const std::shared_ptr<const ov::IPlugin>& plugin,+ const ov::AnyMap& properties);+LLMCompiledModel(const std::shared_ptr<ov::Model>& model,const std::shared_ptr<const ov::IPlugin>& plugin,- const ov::AnyMap& properties);+ const ov::AnyMap& properties,+ CompiledModelFactory factory = make_compiled_model);LLMCompiledModel(const std::shared_ptr<ov::Model>& model,const std::shared_ptr<const ov::IPlugin>& plugin,const bool serialized);@@ -91,13 +106,15 @@ private:KVCacheDesc m_kvcache_desc;uint64_t m_prefill_chunk_size = 0;bool m_use_chunk_prefill = false;- std::shared_ptr<ov::npuw::CompiledModel> m_kvcache_compiled;- std::shared_ptr<ov::npuw::CompiledModel> m_prefill_compiled;+ std::shared_ptr<ov::npuw::ICompiledModel_v0> m_kvcache_compiled;+ std::shared_ptr<ov::npuw::ICompiledModel_v0> m_prefill_compiled;// This model is optional, so can be null.- std::shared_ptr<ov::npuw::CompiledModel> m_lm_head_compiled;+ std::shared_ptr<ov::npuw::ICompiledModel_v0> m_lm_head_compiled;++ CompiledModelFactory m_compiled_model_factory;// Multiple generate models with different static KV cache shapes (1K, 2K, 4K, 8K stepping)- std::vector<std::shared_ptr<ov::npuw::CompiledModel>> m_generate_compiled_variants;+ std::vector<std::shared_ptr<ov::npuw::ICompiledModel_v0>> m_generate_compiled_variants;std::vector<uint32_t> m_kvcache_sizes; // Corresponding KV cache sizes for each variant// Support LoRAdiff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.cpp b/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.cppindex 56de158d444..d7c00612b9d 100644--- a/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.cpp@@ -187,7 +187,7 @@ ov::npuw::LLMInferRequest::LLMInferRequest(const std::shared_ptr<ov::npuw::LLMCo// was in copy_kvcache() call. When it was removed, it broke the import accuracy.bool enable_cpu_wa = false;const auto& kvcache_compiled = m_npuw_llm_compiled_model->m_kvcache_compiled;- for (std::size_t idx = 0; idx < kvcache_compiled->m_compiled_submodels.size(); ++idx) {+ for (std::size_t idx = 0; idx < kvcache_compiled->num_submodels(); ++idx) {if (kvcache_compiled->submodel_device(idx) == "CPU") {enable_cpu_wa = true;break;@@ -228,7 +228,7 @@ ov::npuw::LLMInferRequest::LLMInferRequest(const std::shared_ptr<ov::npuw::LLMCostd::string ov::npuw::LLMInferRequest::init_pre_alloc_device() {bool pre_alloc_on_npu = true;const auto& kvcache_compiled = m_npuw_llm_compiled_model->m_kvcache_compiled;- for (std::size_t idx = 0; idx < kvcache_compiled->m_compiled_submodels.size(); ++idx) {+ for (std::size_t idx = 0; idx < kvcache_compiled->num_submodels(); ++idx) {if (kvcache_compiled->submodel_device(idx) != "NPU") {pre_alloc_on_npu = false;break;diff --git a/src/plugins/intel_npu/tests/unit/CMakeLists.txt b/src/plugins/intel_npu/tests/unit/CMakeLists.txtindex 91b28fbad36..cfa362f3458 100644--- a/src/plugins/intel_npu/tests/unit/CMakeLists.txt+++ b/src/plugins/intel_npu/tests/unit/CMakeLists.txt@@ -29,7 +29,9 @@ ov_add_test_target(${CMAKE_CURRENT_SOURCE_DIR}${CMAKE_CURRENT_SOURCE_DIR}/npuw${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/pipelines${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/utils/include+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/include${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/al/include${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/models@@ -37,8 +39,21 @@ ov_add_test_target(${OpenVINO_SOURCE_DIR}/thirdparty/level_zero/level-zero${OpenVINO_SOURCE_DIR}/thirdparty/level_zero/level-zero/includeOBJECT_FILES+ # plugin/src${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/src/metadata.cpp+ # npuw core+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.cpp${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model_utils.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/llm_infer_base_request.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/llm_eagle3_extension.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/whisper_infer_request.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/embedding_infer_request.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/embedding_model_utils.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/just_sync_infer_request.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/unfold_sync_infer_request.cpp${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/logging.cpp${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/llm_prefix_caching.cpp${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/infer_request_utils.cpp@@ -49,11 +64,25 @@ ov_add_test_target(${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/attention.cpp${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/pyramid_attention.cpp${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/host_flash_attention.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/perf.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/spatial.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/weights_bank.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/accuracy/comparator.cpp+ # moe+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/moe/moe_executor.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/moe/moe_resources.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/moe/moe_infer_utils.cpp${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/moe_transformations/moe_transformation.cpp${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/moe_transformations/moe_unroll_patterns.cpp${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/moe_transformations/device_routed_moe_transform.cpp${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/moe_transformations/gather_to_2d_gather.cpp+ # kokoro pipeline+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_compiled_model.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_infer_request.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_model_transforms.cpp+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_split.cpp${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_utils.cpp+ # model builder (test utility)${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/models/model_builder.cppLINK_LIBRARIES${MANDATORY_UNIT_TESTS_LIBS}diff --git a/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_factory_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_factory_test.cppnew file mode 100644index 00000000000..884057aade4--- /dev/null+++ b/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_factory_test.cpp@@ -0,0 +1,158 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++// Tests for LLMCompiledModel's CompiledModelFactory injection point.+//+// We build a tiny stateful LLM with ModelBuilder, then construct+// LLMCompiledModel with a counting factory that returns MockSubCompiledModel+// instead of a real npuw::CompiledModel. No hardware or ICore is required:+//+// - NullPlugin is a minimal ov::IPlugin stub (no hardware, no core).+// - extract_npu_descriptor() returns std::nullopt when plugin->get_core()+// is null (our null guard), so all NPU-HW-specific branches are skipped.+//+// Expected factory call counts:+// NPUW_LLM_SHARED_HEAD=NO (two-model pipeline) → 2+// NPUW_LLM_SHARED_HEAD=YES (three-model pipeline) → 3++#include <gtest/gtest.h>++#include <atomic>+#include <memory>+#include <string>++#include "compiled_model.hpp" // ov::npuw::ICompiledModel_v0+#include "llm_compiled_model.hpp" // ov::npuw::LLMCompiledModel+#include "model_builder.hpp" // ov::test::npuw::ModelBuilder/Config+#include "openvino/runtime/iplugin.hpp"+#include "serialization.hpp" // ov::npuw::s11n::CompiledContext+#include "weights_bank.hpp" // ov::npuw::weights::Bank++namespace {++// ---------------------------------------------------------------------------+// NullPlugin — the minimum ov::IPlugin needed to construct LLMCompiledModel.+// get_core() returns nullptr → extract_npu_descriptor() skips all HW queries.+// ---------------------------------------------------------------------------+class NullPlugin : public ov::IPlugin {+public:+ std::shared_ptr<ov::ICompiledModel> compile_model(+ const std::shared_ptr<const ov::Model>&, const ov::AnyMap&) const override { return {}; }+ std::shared_ptr<ov::ICompiledModel> compile_model(+ const std::shared_ptr<const ov::Model>&,+ const ov::AnyMap&,+ const ov::SoPtr<ov::IRemoteContext>&) const override { return {}; }+ std::shared_ptr<ov::ICompiledModel> import_model(+ std::istream&, const ov::AnyMap&) const override { return {}; }+ std::shared_ptr<ov::ICompiledModel> import_model(+ std::istream&, const ov::SoPtr<ov::IRemoteContext>&,+ const ov::AnyMap&) const override { return {}; }+ std::shared_ptr<ov::ICompiledModel> import_model(+ const ov::Tensor&, const ov::AnyMap&) const override { return {}; }+ std::shared_ptr<ov::ICompiledModel> import_model(+ const ov::Tensor&, const ov::SoPtr<ov::IRemoteContext>&,+ const ov::AnyMap&) const override { return {}; }+ ov::SupportedOpsMap query_model(const std::shared_ptr<const ov::Model>&,+ const ov::AnyMap&) const override { return {}; }+ void set_property(const ov::AnyMap&) override {}+ ov::Any get_property(const std::string&, const ov::AnyMap&) const override { return {}; }+ ov::SoPtr<ov::IRemoteContext> create_context(const ov::AnyMap&) const override { return {}; }+ ov::SoPtr<ov::IRemoteContext> get_default_context(const ov::AnyMap&) const override { return {}; }+};++// ---------------------------------------------------------------------------+// MockSubCompiledModel — minimal ICompiledModel_v0 returned by the factory.+// LLMCompiledModel only stores the pointer during construction; no methods+// are called on it before the constructor returns.+// ---------------------------------------------------------------------------+class MockSubCompiledModel : public ov::npuw::ICompiledModel_v0 {+public:+ MockSubCompiledModel(const std::shared_ptr<ov::Model>& m,+ const std::shared_ptr<const ov::IPlugin>& p,+ const ov::AnyMap& /*props*/)+ : ov::npuw::ICompiledModel_v0(m, p) {}++ // ov::ICompiledModel pure virtuals+ void export_model(std::ostream&) const override {}+ std::shared_ptr<const ov::Model> get_runtime_model() const override { return {}; }+ void set_property(const ov::AnyMap&) override {}+ ov::Any get_property(const std::string&) const override { return {}; }+ std::shared_ptr<ov::ISyncInferRequest> create_sync_infer_request() const override { return {}; }++ // ov::npuw::ICompiledModel_v0 pure virtuals+ std::shared_ptr<ov::npuw::IBaseInferRequest> create_base_infer_request() const override { return {}; }+ std::shared_ptr<ov::IAsyncInferRequest> wrap_async_infer_request(+ std::shared_ptr<ov::npuw::IBaseInferRequest>) const override { return {}; }+ std::string submodel_device(std::size_t) const override { return "CPU"; }+ std::size_t num_submodels() const override { return 0; }+ std::shared_ptr<ov::npuw::weights::Bank> get_weights_bank() const override { return {}; }+ void set_weights_bank(std::shared_ptr<ov::npuw::weights::Bank>) override {}+ void finalize_weights_bank() override {}+ void reconstruct_closure() override {}+ void serialize(std::ostream&, const ov::npuw::s11n::CompiledContext&) const override {}+};++// ---------------------------------------------------------------------------+// Test fixture+// ---------------------------------------------------------------------------+class LLMCompiledModelFactoryTest : public ::testing::Test {+protected:+ void SetUp() override {+ ov::test::npuw::ModelConfig cfg;+ cfg.num_layers = 2;+ cfg.hidden_size = 64;+ cfg.num_heads = 4;+ cfg.head_dim = 16;+ cfg.num_kv_heads = 4;+ cfg.vocab_size = 256;++ ov::test::npuw::ModelBuilder mb;+ m_model = mb.build_model(cfg);+ m_plugin = std::make_shared<NullPlugin>();+ }++ ov::npuw::LLMCompiledModel::CompiledModelFactory make_counting_factory(std::atomic<int>& n) {+ return [&n](const std::shared_ptr<ov::Model>& m,+ const std::shared_ptr<const ov::IPlugin>& p,+ const ov::AnyMap& props) -> std::shared_ptr<ov::npuw::ICompiledModel_v0> {+ ++n;+ return std::make_shared<MockSubCompiledModel>(m, p, props);+ };+ }++ static ov::AnyMap base_props() {+ return {{"NPUW_LLM", "YES"},+ {"NPUW_LLM_MAX_PROMPT_LEN", "128"},+ {"NPUW_LLM_MIN_RESPONSE_LEN", "64"}};+ }++ std::shared_ptr<ov::Model> m_model;+ std::shared_ptr<ov::IPlugin> m_plugin;+};++// ---------------------------------------------------------------------------+// Tests+// ---------------------------------------------------------------------------++TEST_F(LLMCompiledModelFactoryTest, TwoModelPipeline) {+ std::atomic<int> calls{0};+ auto props = base_props();+ props["NPUW_LLM_SHARED_HEAD"] = std::string("NO");++ ASSERT_NO_THROW(ov::npuw::LLMCompiledModel(m_model, m_plugin, props,+ make_counting_factory(calls)));+ EXPECT_EQ(calls.load(), 2) << "Expected 2 factory calls: generate + prefill";+}++TEST_F(LLMCompiledModelFactoryTest, ThreeModelPipeline) {+ std::atomic<int> calls{0};+ auto props = base_props();+ props["NPUW_LLM_SHARED_HEAD"] = std::string("YES");++ ASSERT_NO_THROW(ov::npuw::LLMCompiledModel(m_model, m_plugin, props,+ make_counting_factory(calls)));+ EXPECT_EQ(calls.load(), 3) << "Expected 3 factory calls: generate + prefill + lm_head";+}++} // namespace