Skip to content

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

[NPUW] Set properties for all NPUW compiled models if possible (#38554)

Bogdan Pereanuaccd915ec463
diff --git a/src/plugins/intel_npu/src/plugin/npuw/attn/attn_subgraph.cpp b/src/plugins/intel_npu/src/plugin/npuw/attn/attn_subgraph.cpp
index 94b611c122e..181208befc6 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/attn/attn_subgraph.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/attn/attn_subgraph.cpp
@@ -1437,6 +1437,29 @@ void attach_runtime_behavior(ov::npuw::v1::subgraphs::CompiledPipeline& compiled
spec.factory = make_runtime_factory();
spec.handles_function_prologue = true;
compiled_pipeline.runtime_behavior = std::move(spec);
+
+ // Looked up when called: at compile time this runs before the extra models are compiled
+ compiled_pipeline.for_each_extra_compiled_model = [kind](
+ const ov::npuw::v1::subgraphs::Context& context,
+ const ov::npuw::v1::subgraphs::CompiledModelVisitor& visit) {
+ switch (kind) {
+ case BehaviorKind::Pyramid:
+ if (const auto* pyramid = get_compiled_pyramid(context)) {
+ for (const auto& cm : pyramid->_compiled_models) {
+ visit(cm);
+ }
+ }
+ break;
+ case BehaviorKind::HFA:
+ if (const auto* hfa = get_compiled_hfa(context)) {
+ visit(hfa->_compiled_tile_model);
+ visit(hfa->_compiled_final_tile_model);
+ }
+ break;
+ case BehaviorKind::Dynamic:
+ break; // runs on the subgraph's own compiled model only
+ }
+ };
}
std::vector<ov::npuw::v1::subgraphs::ScopedPatternRegistration> register_patterns(
diff --git a/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp b/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp
index b9fd0548eba..340331a9003 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp
@@ -35,8 +35,9 @@ ov::npuw::IBaseInferRequest::IBaseInferRequest(const std::shared_ptr<ov::npuw::C
// Cache device check and strided ports for hot-path lookups in set_tensor
m_is_npu_global_mem = (m_npuw_model->global_mem_device() == "NPU");
- auto it = m_npuw_model->m_non_npuw_props.find(ov::intel_npu::enable_strides_for.name());
- if (it != m_npuw_model->m_non_npuw_props.end()) {
+ const auto non_npuw_props = m_npuw_model->non_npuw_props();
+ auto it = non_npuw_props.find(ov::intel_npu::enable_strides_for.name());
+ if (it != non_npuw_props.end()) {
const auto& strides_csv = it->second.as<std::string>();
std::istringstream ss(strides_csv);
std::string token;
diff --git a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
index 610a5adac1f..9e10cfb4124 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
@@ -8,6 +8,7 @@
#include <memory>
#include <set>
#include <string>
+#include <unordered_map>
#include "accuracy/comparator.hpp"
#include "attn/attn_subgraph.hpp"
@@ -1443,7 +1444,7 @@ void ov::npuw::CompiledModel::ensure_phase0_compatibility() const {
void ov::npuw::CompiledModel::serialize_orc(std::ostream& stream) const {
ov::npuw::orc::write_file_header(stream, ov::npuw::orc::schema_npuw::NPUW_ORC_PARTITIONED_SCHEMA);
- serialize_orc_container(stream, true, get_encrypt_callback(m_non_npuw_props));
+ serialize_orc_container(stream, true, get_encrypt_callback(non_npuw_props()));
}
void ov::npuw::CompiledModel::serialize_orc_container(std::ostream& stream,
@@ -1462,7 +1463,8 @@ void ov::npuw::CompiledModel::serialize_orc_container(std::ostream& stream,
ensure_phase0_compatibility();
}
- bool is_weightless = should_use_weightless_flow(m_non_npuw_props, m_cfg, m_const_to_offset);
+ ov::AnyMap serializable_props = non_npuw_props();
+ bool is_weightless = should_use_weightless_flow(serializable_props, m_cfg, m_const_to_offset);
LOG_INFO("Serialization will be done via " << (is_weightless ? "weightless" : "flow with weights") << ".");
// For top-level CompiledModel export we serialize this model's own BF16 cache.
// For nested export (e.g. inside LLMCompiledModel) the parent may provide a
@@ -1470,7 +1472,6 @@ void ov::npuw::CompiledModel::serialize_orc_container(std::ostream& stream,
// propagated view must win so weightless import can reconstruct tensors correctly.
const auto& bf16_cache = bf16_consts != nullptr ? *bf16_consts : m_bf16_consts;
- ov::AnyMap serializable_props = m_non_npuw_props;
serializable_props.erase(ov::cache_encryption_callbacks.name());
s11n::WeightsContext weights_ctx(is_weightless, m_const_to_offset);
@@ -1582,6 +1583,9 @@ std::shared_ptr<ov::npuw::CompiledModel> ov::npuw::CompiledModel::deserialize_or
meta_stream & compiled->m_cfg;
compiled->m_cfg.parseEnvVars();
meta_stream & compiled->m_non_npuw_props;
+ // Model priority is a runtime-only property: the submodels are imported with the default one,
+ // so drop the value saved at export time to report what they actually use
+ compiled->m_non_npuw_props.erase(ov::hint::model_priority.name());
meta_stream & is_weightless;
meta_stream & compiled->m_bf16_consts;
if (encrypted) {
@@ -2307,6 +2311,7 @@ bool ov::npuw::CompiledModel::compile_for_success(std::size_t id, const std::vec
const auto& first_model = pyramid_attn_models[0];
npu_device_str = device;
const auto& strides_key = ov::intel_npu::enable_strides_for.name();
+ std::lock_guard<std::mutex> lock(m_props_mutex);
const ov::Any existing_any =
ov::npuw::util::at::_(m_meta_devices[npu_device_str]).at_or(strides_key, std::string{});
saved_strides = existing_any.as<std::string>();
@@ -2342,6 +2347,7 @@ bool ov::npuw::CompiledModel::compile_for_success(std::size_t id, const std::vec
if (support_strides_for && !npu_device_str.empty()) {
const auto& strides_key = ov::intel_npu::enable_strides_for.name();
+ std::lock_guard<std::mutex> lock(m_props_mutex);
if (saved_strides.empty()) {
m_meta_devices[npu_device_str].erase(strides_key);
} else {
@@ -2378,6 +2384,7 @@ bool ov::npuw::CompiledModel::compile_for_success(std::size_t id, const std::vec
hfa->_can_use_tensor_view = true;
npu_device_str = device;
const auto& strides_key = ov::intel_npu::enable_strides_for.name();
+ std::lock_guard<std::mutex> lock(m_props_mutex);
const ov::Any existing_any =
ov::npuw::util::at::_(m_meta_devices[device]).at_or(strides_key, std::string{});
saved_strides = existing_any.as<std::string>();
@@ -2398,6 +2405,7 @@ bool ov::npuw::CompiledModel::compile_for_success(std::size_t id, const std::vec
if (supports_strides_for && !npu_device_str.empty()) {
const auto& strides_key = ov::intel_npu::enable_strides_for.name();
+ std::lock_guard<std::mutex> lock(m_props_mutex);
if (saved_strides.empty()) {
m_meta_devices[npu_device_str].erase(strides_key);
} else {
@@ -2417,8 +2425,15 @@ ov::SoPtr<ov::ICompiledModel> ov::npuw::CompiledModel::compile_submodel(const st
// set exclusive_async_requests in case when model is split
// NOTE(dm): Not sure if it is required for the NPUW plugin, but likely it is
- // Make a device config COPY here!
- auto device_config = m_meta_devices[device];
+ // Make a device config COPY here! It may be called at runtime (failsafe fallback) while
+ // set_property() updates the per-device configs
+ ov::AnyMap device_config;
+ {
+ std::lock_guard<std::mutex> lock(m_props_mutex);
+ if (auto it = m_meta_devices.find(device); it != m_meta_devices.end()) {
+ device_config = it->second;
+ }
+ }
if (ov::npuw::util::starts_with(device, "NPU") && m_cfg.get<::intel_npu::NPUW_UNFOLD_IREQS>()) {
device_config["NPU_RUN_INFERENCES_SEQUENTIALLY"] = "YES";
@@ -2748,8 +2763,132 @@ std::shared_ptr<ov::IAsyncInferRequest> ov::npuw::CompiledModel::create_infer_re
return wrap_async_infer_request(create_base_infer_request());
}
+namespace {
+// Validates a user-supplied value and returns it in the property's typed form
+using PropertyNormalizer = ov::Any (*)(const ov::Any&);
+
+template <typename T, ov::PropertyMutability M>
+std::pair<std::string, PropertyNormalizer> typed_property(const ov::Property<T, M>& property) {
+ return {property.name(), [](const ov::Any& value) {
+ return ov::Any(value.as<T>());
+ }};
+}
+} // anonymous namespace
+
void ov::npuw::CompiledModel::set_property(const ov::AnyMap& properties) {
- OPENVINO_NOT_IMPLEMENTED;
+ // Properties which can be changed after compilation.
+ static const std::unordered_map<std::string, PropertyNormalizer> runtime_mutable = {
+ typed_property(ov::hint::model_priority)};
+
+ ov::AnyMap updates;
+ for (const auto& [key, value] : properties) {
+ const auto it = runtime_mutable.find(key);
+ if (it == runtime_mutable.end()) {
+ OPENVINO_THROW("NPUW CompiledModel: '", key, "' cannot be changed after the model is compiled");
+ }
+ updates.emplace(key, it->second(value));
+ }
+ if (updates.empty()) {
+ return;
+ }
+
+ std::lock_guard<std::mutex> set_property_lock(m_set_property_mutex);
+
+ // Each device config gets only the keys its device can change (e.g. CPU can't change any).
+ // Query the devices outside of m_props_mutex, take it only to access the maps.
+ std::vector<std::string> devices;
+ {
+ std::lock_guard<std::mutex> props_lock(m_props_mutex);
+ for (const auto& [device, device_props] : m_meta_devices) {
+ devices.push_back(device);
+ }
+ }
+ auto core = get_npuw_plugin()->get_core();
+ std::unordered_map<std::string, ov::AnyMap> device_updates;
+ for (const auto& device : devices) {
+ const auto device_mutable =
+ ov::npuw::util::mutable_properties(core->get_property(device, ov::supported_properties));
+ for (const auto& [key, value] : updates) {
+ if (device_mutable.count(key)) {
+ device_updates[device][key] = value;
+ }
+ }
+ }
+
+ // Collect every device-level compiled model owned by this partitioned model, once.
+ // Function calls have neither a compiled model nor extra models of their own (they run
+ // their body's), so each model appears only in the submodel which owns it. The extra
+ // models may reuse that submodel's own compiled model (e.g. the last pyramid model or
+ // the HFA final tile), so skip those.
+ std::vector<ov::SoPtr<ov::ICompiledModel>> targets;
+ for (const auto& desc : m_compiled_submodels) {
+ if (desc.compiled_model) {
+ targets.push_back(desc.compiled_model);
+ }
+ if (desc.pipeline.for_each_extra_compiled_model) {
+ desc.pipeline.for_each_extra_compiled_model(desc.pipeline.context,
+ [&](const ov::SoPtr<ov::ICompiledModel>& cm) {
+ if (cm && cm._ptr != desc.compiled_model._ptr) {
+ targets.push_back(cm);
+ }
+ });
+ }
+ }
+
+ // Keys which at least one compiled submodel can change at runtime. Only those are
+ // remembered, so get_property never reports a value no submodel uses.
+ ov::AnyMap applied;
+
+ // Same for the compiled submodels
+ std::vector<std::pair<ov::SoPtr<ov::ICompiledModel>, ov::AnyMap>> cm_updates;
+ for (const auto& cm : targets) {
+ const auto cm_mutable = ov::npuw::util::mutable_properties(
+ cm->get_property(ov::supported_properties.name()).as<std::vector<ov::PropertyName>>());
+ ov::AnyMap props;
+ for (const auto& [key, value] : updates) {
+ if (cm_mutable.count(key)) {
+ props.emplace(key, value);
+ applied[key] = value;
+ }
+ }
+ if (props.empty()) {
+ LOG_DEBUG("Skipping a submodel which can't change any of the requested properties");
+ continue;
+ }
+ cm_updates.emplace_back(cm, std::move(props));
+ }
+
+ for (const auto& [key, value] : updates) {
+ if (!applied.count(key)) {
+ LOG_WARN("NPUW CompiledModel: '" << key << "' can't be changed by any of the submodels, ignoring it");
+ }
+ }
+
+ // Update the per-device configs first, so submodels compiled from now on (e.g. failsafe
+ // fallbacks) inherit the new values, and remember them for get_property/export. A fallback
+ // which already took the old config holds its failsafe lock until it's done, so the
+ // propagation below waits for it and then reaches the newly compiled model.
+ {
+ std::lock_guard<std::mutex> props_lock(m_props_mutex);
+ for (const auto& [device, props] : device_updates) {
+ auto& device_props = m_meta_devices.at(device);
+ for (const auto& [key, value] : props) {
+ device_props[key] = value;
+ }
+ }
+ for (const auto& [key, value] : applied) {
+ m_non_npuw_props[key] = value;
+ }
+ }
+
+ for (const auto& [cm, props] : cm_updates) {
+ cm->set_property(props);
+ }
+}
+
+ov::AnyMap ov::npuw::CompiledModel::non_npuw_props() const {
+ std::lock_guard<std::mutex> lock(m_props_mutex);
+ return m_non_npuw_props;
}
std::shared_ptr<const ov::Model> ov::npuw::CompiledModel::get_runtime_model() const {
@@ -2769,8 +2908,12 @@ ov::Any ov::npuw::CompiledModel::get_property(const std::string& name) const {
auto&& configIterator = m_prop_to_opt.find(name);
if (configIterator != m_prop_to_opt.cend()) {
return std::get<1>(configIterator->second)(m_cfg);
- } else if (m_non_npuw_props.count(name)) {
- return m_non_npuw_props.at(name);
+ }
+ {
+ std::lock_guard<std::mutex> lock(m_props_mutex);
+ if (auto it = m_non_npuw_props.find(name); it != m_non_npuw_props.end()) {
+ return it->second;
+ }
}
OPENVINO_THROW("Unsupported configuration key: ", name);
@@ -2881,70 +3024,85 @@ void ov::npuw::CompiledModel::implement_properties() {
// 1.
// OV Public
- m_prop_to_opt = {{ov::supported_properties.name(),
- {ov::PropertyMutability::RO,
- [&](const ::intel_npu::Config&) -> std::vector<PropertyName>& {
- return m_all_supported_props;
- }}},
- {ov::device::id.name(),
- {ov::PropertyMutability::RO,
- [&](const ::intel_npu::Config&) {
- GET_PLUGIN_PROP(ov::device::id);
- }}},
- {ov::enable_profiling.name(),
- {ov::PropertyMutability::RO,
- [&](const ::intel_npu::Config&) {
- GET_PLUGIN_PROP(ov::enable_profiling);
- }}},
- {ov::model_name.name(),
- {ov::PropertyMutability::RO,
- [&](const ::intel_npu::Config&) -> std::string& {
- return m_name;
- }}},
- {ov::optimal_number_of_infer_requests.name(),
- {ov::PropertyMutability::RO,
- [&](const ::intel_npu::Config&) {
- return 1u;
- }}},
- {ov::execution_devices.name(),
- {ov::PropertyMutability::RO,
- [&](const ::intel_npu::Config&) {
- return "NPU";
- }}},
- {ov::loaded_from_cache.name(),
- {ov::PropertyMutability::RO,
- [&](const ::intel_npu::Config&) {
- return m_loaded_from_cache;
- }}},
- // OV Public Hints
- {ov::hint::performance_mode.name(),
- {ov::PropertyMutability::RO,
- [&](const ::intel_npu::Config&) {
- GET_PLUGIN_PROP(ov::hint::performance_mode);
- }}},
- {ov::hint::execution_mode.name(),
- {ov::PropertyMutability::RO,
- [&](const ::intel_npu::Config&) {
- GET_PLUGIN_PROP(ov::hint::execution_mode);
- }}},
- {ov::hint::num_requests.name(),
- {ov::PropertyMutability::RO,
- [&](const ::intel_npu::Config&) {
- GET_PLUGIN_PROP(ov::hint::num_requests);
- }}},
- {ov::hint::inference_precision.name(),
- {ov::PropertyMutability::RO,
- [&](const ::intel_npu::Config&) {
- GET_PLUGIN_PROP(ov::hint::inference_precision);
- }}},
- {ov::hint::enable_cpu_pinning.name(),
- {ov::PropertyMutability::RO,
- [&](const ::intel_npu::Config&) {
- GET_PLUGIN_PROP(ov::hint::enable_cpu_pinning);
- }}},
- {ov::hint::model_priority.name(), {ov::PropertyMutability::RO, [&](const ::intel_npu::Config&) {
- GET_PLUGIN_PROP(ov::hint::model_priority);
- }}}};
+
+ m_prop_to_opt = {
+ {ov::supported_properties.name(),
+ {ov::PropertyMutability::RO,
+ [&](const ::intel_npu::Config&) -> std::vector<PropertyName>& {
+ return m_all_supported_props;
+ }}},
+ {ov::device::id.name(),
+ {ov::PropertyMutability::RO,
+ [&](const ::intel_npu::Config&) {
+ GET_PLUGIN_PROP(ov::device::id);
+ }}},
+ {ov::enable_profiling.name(),
+ {ov::PropertyMutability::RO,
+ [&](const ::intel_npu::Config&) {
+ GET_PLUGIN_PROP(ov::enable_profiling);
+ }}},
+ {ov::model_name.name(),
+ {ov::PropertyMutability::RO,
+ [&](const ::intel_npu::Config&) -> std::string& {
+ return m_name;
+ }}},
+ {ov::optimal_number_of_infer_requests.name(),
+ {ov::PropertyMutability::RO,
+ [&](const ::intel_npu::Config&) {
+ return 1u;
+ }}},
+ {ov::execution_devices.name(),
+ {ov::PropertyMutability::RO,
+ [&](const ::intel_npu::Config&) {
+ return "NPU";
+ }}},
+ {ov::loaded_from_cache.name(),
+ {ov::PropertyMutability::RO,
+ [&](const ::intel_npu::Config&) {
+ return m_loaded_from_cache;
+ }}},
+ // OV Public Hints
+ {ov::hint::performance_mode.name(),
+ {ov::PropertyMutability::RO,
+ [&](const ::intel_npu::Config&) {
+ GET_PLUGIN_PROP(ov::hint::performance_mode);
+ }}},
+ {ov::hint::execution_mode.name(),
+ {ov::PropertyMutability::RO,
+ [&](const ::intel_npu::Config&) {
+ GET_PLUGIN_PROP(ov::hint::execution_mode);
+ }}},
+ {ov::hint::num_requests.name(),
+ {ov::PropertyMutability::RO,
+ [&](const ::intel_npu::Config&) {
+ GET_PLUGIN_PROP(ov::hint::num_requests);
+ }}},
+ {ov::hint::inference_precision.name(),
+ {ov::PropertyMutability::RO,
+ [&](const ::intel_npu::Config&) {
+ GET_PLUGIN_PROP(ov::hint::inference_precision);
+ }}},
+ {ov::hint::enable_cpu_pinning.name(),
+ {ov::PropertyMutability::RO,
+ [&](const ::intel_npu::Config&) {
+ GET_PLUGIN_PROP(ov::hint::enable_cpu_pinning);
+ }}},
+ // clang-format off
+ {ov::hint::model_priority.name(),
+ {ov::PropertyMutability::RW,
+ [&](const ::intel_npu::Config&) -> ov::Any {
+ // Report the priority the submodels actually use (set at compile time or via set_property), falling back to the plugin's default
+ {
+ std::lock_guard<std::mutex> lock(m_props_mutex);
+ if (auto it = m_non_npuw_props.find(ov::hint::model_priority.name()); it != m_non_npuw_props.end()) {
+ return it->second.as<ov::hint::Priority>();
+ }
+ }
+ GET_PLUGIN_PROP(ov::hint::model_priority);
+ }}}
+ // clang-format on
+ };
+
#undef GET_PLUGIN_PROP
// 2.
diff --git a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp
index c1b2d7ea8fe..cf84784df42 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp
@@ -4,6 +4,7 @@
#pragma once
+#include <mutex>
#include <optional>
#include "attention.hpp"
@@ -246,6 +247,16 @@ private:
DeviceProperties m_meta_devices;
+ // set_property() updates m_meta_devices and m_non_npuw_props at runtime, while failsafe
+ // fallback compilation, infer request creation, get_property() and export may read them
+ // concurrently. m_props_mutex guards both maps and is held only for short map accesses, never
+ // while calling into the submodels: failsafe calls back into compile_submodel() under its own
+ // lock, so the lock order is m_set_property_mutex -> failsafe lock -> m_props_mutex.
+ mutable std::mutex m_props_mutex;
+ // Serializes set_property() calls so the submodels and the configs end up with the same values
+ std::mutex m_set_property_mutex;
+ ov::AnyMap non_npuw_props() const;
+
DevList m_dev_list;
struct execution_stats {
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 9f52c2d304e..57ec02e1d73 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
@@ -1885,7 +1885,22 @@ std::shared_ptr<const ov::Model> ov::npuw::LLMCompiledModel::get_runtime_model()
}
void ov::npuw::LLMCompiledModel::set_property(const ov::AnyMap& properties) {
- OPENVINO_NOT_IMPLEMENTED;
+ // Propagate to every inner compiled model once; they validate which keys are mutable
+ std::lock_guard<std::mutex> lock(m_set_property_mutex);
+ auto apply = [&](const std::shared_ptr<ov::npuw::ICompiledModel_v0>& cm) {
+ if (cm) {
+ cm->set_property(properties);
+ }
+ };
+ apply(m_prefill_compiled);
+ for (const auto& variant : m_generate_compiled_variants) {
+ apply(variant);
+ }
+ // m_kvcache_compiled is the last generate variant when variants are used
+ if (m_generate_compiled_variants.empty()) {
+ apply(m_kvcache_compiled);
+ }
+ apply(m_lm_head_compiled);
}
void ov::npuw::LLMCompiledModel::resolve_continuous_prefill() {
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.hpp
index be297182829..f01a359ee46 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
@@ -5,6 +5,7 @@
#pragma once
#include <memory>
+#include <mutex>
#include "compiled_model.hpp"
#include "npuw_transformations/kv_axes_position.hpp"
@@ -136,6 +137,10 @@ protected:
// This model is optional, so can be null.
std::shared_ptr<ov::npuw::ICompiledModel_v0> m_lm_head_compiled;
+ // Each stage serializes only its own update, so set_property() holds this for the whole
+ // propagation: concurrent calls can't leave the stages with different values
+ std::mutex m_set_property_mutex;
+
CompiledModelFactory m_compiled_model_factory;
// Multiple generate models with different static KV cache shapes (1K, 2K, 4K, 8K stepping)
diff --git a/src/plugins/intel_npu/src/plugin/npuw/moe/moe_subgraph.cpp b/src/plugins/intel_npu/src/plugin/npuw/moe/moe_subgraph.cpp
index b8aedaf8f37..30528da29bb 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/moe/moe_subgraph.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/moe/moe_subgraph.cpp
@@ -74,6 +74,25 @@ void attach_runtime_behavior(v1::subgraphs::CompiledPipeline& compiled_pipeline,
spec.factory = make_runtime_factory();
spec.handles_function_prologue = handles_function_prologue;
compiled_pipeline.runtime_behavior = std::move(spec);
+
+ // Looked up when called: at compile time this runs before the extra models are compiled
+ compiled_pipeline.for_each_extra_compiled_model = [role](const v1::subgraphs::Context& context,
+ const v1::subgraphs::CompiledModelVisitor& visit) {
+ switch (role) {
+ case BehaviorRole::EXPERTS:
+ if (const auto* experts = get_compiled_experts(context)) {
+ for (const auto& [chunk_size, cm] : experts->_compiled_models) {
+ visit(cm);
+ }
+ }
+ break;
+ case BehaviorRole::DOWNSTREAM:
+ if (const auto* downstream = get_compiled_downstream(context)) {
+ visit(downstream->_compiled_model);
+ }
+ break;
+ }
+ };
}
namespace {
diff --git a/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_compiled_model.cpp b/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_compiled_model.cpp
index 438ba5a6570..5238cd16b60 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_compiled_model.cpp
@@ -142,9 +142,15 @@ std::shared_ptr<const ov::Model> ov::npuw::KokoroCompiledModel::get_runtime_mode
}
void ov::npuw::KokoroCompiledModel::set_property(const ov::AnyMap& properties) {
- // FIXME Not implemented
LOG_DEBUG("Setting properties to KokoroCompiledModel");
- OPENVINO_NOT_IMPLEMENTED;
+ // Both models are NPUW compiled models, they validate which keys are mutable
+ std::lock_guard<std::mutex> lock(m_set_property_mutex);
+ if (m_model_a_compiled) {
+ m_model_a_compiled->set_property(properties);
+ }
+ if (m_model_b_compiled) {
+ m_model_b_compiled->set_property(properties);
+ }
}
ov::Any ov::npuw::KokoroCompiledModel::get_property(const std::string& name) const {
diff --git a/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_compiled_model.hpp b/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_compiled_model.hpp
index 4045f8b20d4..3df31b00f8d 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_compiled_model.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/pipelines/kokoro/kokoro_compiled_model.hpp
@@ -1,10 +1,11 @@
-// Copyright (C) 2025 Intel Corporation
+// Copyright (C) 2018-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <cstdint>
+#include <mutex>
#include "npuw/compiled_model.hpp"
@@ -65,6 +66,10 @@ private:
ov::SoPtr<ov::ICompiledModel> m_model_a_compiled;
std::shared_ptr<ov::npuw::ICompiledModel> m_model_b_compiled;
+
+ // Each model serializes only its own update, so set_property() holds this for both:
+ // concurrent calls can't leave the two models with different values
+ std::mutex m_set_property_mutex;
};
} // namespace npuw
diff --git a/src/plugins/intel_npu/src/plugin/npuw/util.cpp b/src/plugins/intel_npu/src/plugin/npuw/util.cpp
index 19a224f08bb..4f3c20b9452 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/util.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/util.cpp
@@ -195,6 +195,17 @@ bool ov::npuw::util::starts_with(const std::string& str, const std::string& pref
return str.substr(0, prefix.size()) == prefix;
}
+std::unordered_set<std::string> ov::npuw::util::mutable_properties(
+ const std::vector<ov::PropertyName>& supported_properties) {
+ std::unordered_set<std::string> result;
+ for (const auto& p : supported_properties) {
+ if (p.is_mutable()) {
+ result.insert(p);
+ }
+ }
+ return result;
+}
+
bool ov::npuw::util::is_supported_position_ids_input(const ov::Output<const ov::Node>& p) {
const auto& shape = p.get_shape();
return p.get_node()->get_friendly_name() == "position_ids" &&
diff --git a/src/plugins/intel_npu/src/plugin/npuw/util.hpp b/src/plugins/intel_npu/src/plugin/npuw/util.hpp
index f24d6bc4f92..b842d7272b7 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/util.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/util.hpp
@@ -8,11 +8,13 @@
#include <optional>
#include <random>
#include <string>
+#include <unordered_set>
#include "llm_compiled_model_utils.hpp"
#include "logging.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/parameter.hpp"
+#include "openvino/runtime/icompiled_model.hpp"
#include "openvino/runtime/iplugin.hpp"
#include "openvino/runtime/itensor.hpp"
#include "openvino/runtime/so_ptr.hpp"
@@ -36,6 +38,9 @@ ov::Tensor copy_tensor_from_const(const std::shared_ptr<ov::Node>& node);
bool starts_with(const std::string& str, const std::string& prefix);
+// Names of all RW entries of an ov::supported_properties list (of a compiled model or a plugin)
+std::unordered_set<std::string> mutable_properties(const std::vector<ov::PropertyName>& supported_properties);
+
// Shared by the attention/pyramid_attention/host_flash_attention runtime selectors:
// matches a "position_ids" input of a supported shape - flat [seq_len], regular
// [1, seq_len], or 3D mrope [num_sections, 1, seq_len] (e.g. Qwen2.5-VL uses 3
diff --git a/src/plugins/intel_npu/src/plugin/npuw/v1/elements/accuracy_checked.cpp b/src/plugins/intel_npu/src/plugin/npuw/v1/elements/accuracy_checked.cpp
index f713f1f4a1f..27a401d0751 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/v1/elements/accuracy_checked.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/v1/elements/accuracy_checked.cpp
@@ -67,6 +67,10 @@ std::shared_ptr<const ov::Model> CompiledModel::get_runtime_model() const {
void CompiledModel::set_property(const ov::AnyMap& properties) {
std::lock_guard<std::mutex> lock(m_mutex);
+ // This debug wrapper doesn't handle runtime property changes (e.g. ov::hint::model_priority)
+ // itself: they only reach the currently active model. The inactive one keeps its
+ // compile-time values. After a switch to a reference which can't change a property
+ // (e.g. CPU), ov::supported_properties reports it as read-only, so NPUW skips this wrapper.
active_compiled_model_locked()->set_property(properties);
}
diff --git a/src/plugins/intel_npu/src/plugin/npuw/v1/subgraph_pipeline.hpp b/src/plugins/intel_npu/src/plugin/npuw/v1/subgraph_pipeline.hpp
index d1e43371f8a..a9666cc36a8 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/v1/subgraph_pipeline.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/v1/subgraph_pipeline.hpp
@@ -163,6 +163,11 @@ public:
using RuntimeBehaviorFactory = std::function<ISubgraphBehavior::Ptr(const Context&)>;
using CompileExecutor = std::function<void(CompileContext&)>;
+using CompiledModelVisitor = std::function<void(const ov::SoPtr<ov::ICompiledModel>&)>;
+// Visits the extra device-level compiled models a pipeline owns besides the subgraph's own
+// compiled model (e.g. pyramid attention levels, HFA tiles, MoE experts), looked up in the
+// given pipeline context. Some of them may be the subgraph's own compiled model, reused.
+using ExtraCompiledModelsVisitor = std::function<void(const Context&, const CompiledModelVisitor&)>;
struct RuntimeBehaviorSpec {
Registration registration;
@@ -176,6 +181,7 @@ struct CompiledPipeline {
Context context;
CompileExecutor compile_executor;
std::optional<RuntimeBehaviorSpec> runtime_behavior;
+ ExtraCompiledModelsVisitor for_each_extra_compiled_model;
bool is_function_call = false;
std::optional<std::size_t> function_body_subgraph_idx;
};
diff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/behavior_tests.cpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/behavior_tests.cpp
index 85515d0a6c8..7ce09705ec5 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/npuw/behavior_tests.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/behavior_tests.cpp
@@ -686,3 +686,156 @@ TEST_F(BehaviorTestsNPUW, CanSayNoToPMMProperty) {
auto prop = compiled_model.get_property(partitioning::par_matmul_merge_dims.name());
EXPECT_EQ("NO", prop.as<std::string>());
}
+
+namespace {
+// By default mock compiled models don't list ov::hint::model_priority and throw from set_property.
+// This makes one behave like an NPU compiled model: priority is RW and can be updated.
+void allow_model_priority_updates(MockCompiledModel& model) {
+ ON_CALL(model, get_property(StrEq(ov::supported_properties.name())))
+ .WillByDefault(Return(ov::Any(std::vector<ov::PropertyName>{
+ ov::PropertyName(ov::num_streams.name()),
+ ov::PropertyName(ov::enable_profiling.name()),
+ ov::PropertyName(ov::hint::model_priority.name(), ov::PropertyMutability::RW)})));
+ ON_CALL(model, set_property(_)).WillByDefault(Return());
+}
+
+Matcher<const ov::AnyMap&> IsModelPriority(ov::hint::Priority priority) {
+ return Truly([priority](const ov::AnyMap& props) {
+ const auto it = props.find(ov::hint::model_priority.name());
+ return props.size() == 1 && it != props.end() && it->second.as<ov::hint::Priority>() == priority;
+ });
+}
+} // anonymous namespace
+
+TEST_F(BehaviorTestsNPUWOnlinePartitioning, ModelPriorityIsPropagatedToAllSubmodels) {
+ model = model_builder.get_model_with_repeated_blocks();
+
+ // Set expectations first:
+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(12));
+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));
+ for (int i = 0; i < 12; i++) {
+ mock_npu_plugin->set_expectations_to_comp_models(MODEL(i), [](MockCompiledModel& model) {
+ allow_model_priority_updates(model);
+ EXPECT_CALL(model, set_property(IsModelPriority(ov::hint::Priority::HIGH))).Times(1);
+ });
+ }
+
+ // Register mock objects as plugins in OpenVINO:
+ register_mock_plugins_in_ov();
+
+ // Do the actual test:
+ use_npuw_props.emplace(devices("MockNPU"));
+ use_npuw_props.emplace(partitioning::online::min_size(12));
+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);
+ EXPECT_NO_THROW(compiled_model.set_property(ov::hint::model_priority(ov::hint::Priority::HIGH)));
+ EXPECT_EQ(ov::hint::Priority::HIGH, compiled_model.get_property(ov::hint::model_priority));
+}
+
+TEST_F(BehaviorTestsNPUWOnlinePartitioning, ModelPriorityIsSkippedForSubmodelsWhichCannotChangeIt) {
+ model = model_builder.get_model_with_repeated_blocks();
+
+ // Set expectations first:
+ // the 1st subgraph falls back to MockCPU, the remaining 11 stay on MockNPU
+ {
+ InSequence s;
+
+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1), THROW("Compilation on MockNPU is failed"));
+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(1));
+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(11));
+ }
+ for (int i = 0; i < 11; i++) {
+ mock_npu_plugin->set_expectations_to_comp_models(MODEL(i), [](MockCompiledModel& model) {
+ allow_model_priority_updates(model);
+ EXPECT_CALL(model, set_property(IsModelPriority(ov::hint::Priority::LOW))).Times(1);
+ });
+ }
+ // MockCPU keeps the default behavior (priority isn't RW, set_property throws),
+ // like the real CPU plugin, so it must not be touched
+ mock_cpu_plugin->set_expectations_to_comp_models(MODEL(0), [](MockCompiledModel& model) {
+ EXPECT_CALL(model, set_property(_)).Times(0);
+ });
+
+ // Register mock objects as plugins in OpenVINO:
+ register_mock_plugins_in_ov();
+
+ // Do the actual test:
+ use_npuw_props.emplace(devices("MockNPU,MockCPU"));
+ use_npuw_props.emplace(partitioning::online::min_size(12));
+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);
+ EXPECT_NO_THROW(compiled_model.set_property(ov::hint::model_priority(ov::hint::Priority::LOW)));
+ EXPECT_EQ(ov::hint::Priority::LOW, compiled_model.get_property(ov::hint::model_priority));
+}
+
+TEST_F(BehaviorTestsNPUW, ModelPriorityIsNotRememberedWhenNoSubmodelCanChangeIt) {
+ model = model_builder.get_model_with_one_op();
+
+ // Set expectations first:
+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1));
+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));
+ // The compiled model keeps the default mock behavior (priority isn't RW, set_property throws),
+ // like a device which can't change it. NB: MockNPU is used rather than a MockCPU-only list on
+ // purpose: the mock engines hand out the injected plugins in creation order on Linux, so MockNPU
+ // must be created first.
+ mock_npu_plugin->set_expectations_to_comp_models(MODEL(0), [](MockCompiledModel& model) {
+ EXPECT_CALL(model, set_property(_)).Times(0);
+ });
+
+ // Register mock objects as plugins in OpenVINO:
+ register_mock_plugins_in_ov();
+
+ // Do the actual test:
+ use_npuw_props.emplace(devices("MockNPU"));
+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);
+ EXPECT_NO_THROW(compiled_model.set_property(ov::hint::model_priority(ov::hint::Priority::HIGH)));
+ EXPECT_NE(ov::hint::Priority::HIGH, compiled_model.get_property(ov::hint::model_priority));
+}
+
+TEST_F(BehaviorTestsNPUW, SettingNonPriorityPropertyAfterCompilationThrows) {
+ model = model_builder.get_model_with_one_op();
+
+ // Set expectations first:
+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(1));
+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));
+ mock_npu_plugin->set_expectations_to_comp_models(MODEL(0), [](MockCompiledModel& model) {
+ allow_model_priority_updates(model);
+ EXPECT_CALL(model, set_property(_)).Times(0);
+ });
+
+ // Register mock objects as plugins in OpenVINO:
+ register_mock_plugins_in_ov();
+
+ // Do the actual test:
+ use_npuw_props.emplace(devices("MockNPU"));
+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);
+ EXPECT_ANY_THROW(compiled_model.set_property(partitioning::fold(true)));
+ // Nothing is applied when the same call also contains an unsupported key
+ EXPECT_ANY_THROW(compiled_model.set_property(
+ ov::AnyMap{ov::hint::model_priority(ov::hint::Priority::HIGH), partitioning::fold(true)}));
+ EXPECT_NE(ov::hint::Priority::HIGH, compiled_model.get_property(ov::hint::model_priority));
+}
+
+TEST_F(BehaviorTestsNPUWOnlinePartitioning, ModelPriorityIsSetOnceForFoldedFunction) {
+ model = model_builder.get_model_with_repeated_blocks();
+
+ // Set expectations first:
+ // head, function body (shared by all repeated blocks) and tail
+ EXPECT_COMPILE_MODEL(mock_npu, TIMES(3));
+ EXPECT_COMPILE_MODEL(mock_cpu, TIMES(0));
+ for (int i = 0; i < 3; i++) {
+ mock_npu_plugin->set_expectations_to_comp_models(MODEL(i), [](MockCompiledModel& model) {
+ allow_model_priority_updates(model);
+ EXPECT_CALL(model, set_property(IsModelPriority(ov::hint::Priority::HIGH))).Times(1);
+ });
+ }
+
+ // Register mock objects as plugins in OpenVINO:
+ register_mock_plugins_in_ov();
+
+ // Do the actual test:
+ use_npuw_props.emplace(devices("MockNPU"));
+ use_npuw_props.emplace(partitioning::online::min_size(12));
+ use_npuw_props.emplace(partitioning::fold(true));
+ auto compiled_model = core.compile_model(model, "NPU", use_npuw_props);
+ EXPECT_NO_THROW(compiled_model.set_property(ov::hint::model_priority(ov::hint::Priority::HIGH)));
+ EXPECT_EQ(ov::hint::Priority::HIGH, compiled_model.get_property(ov::hint::model_priority));
+}
diff --git a/src/plugins/intel_npu/tests/unit/CMakeLists.txt b/src/plugins/intel_npu/tests/unit/CMakeLists.txt
index 2b6ae5d411a..b4dc6836a87 100644
--- a/src/plugins/intel_npu/tests/unit/CMakeLists.txt
+++ b/src/plugins/intel_npu/tests/unit/CMakeLists.txt
@@ -176,6 +176,7 @@ target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/npu/option_support_cache_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npu/state_tensor_binding_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_compiled_model_graph_options_test.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_compiled_model_set_property_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/flux2_compiled_model_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/gqa_compiled_model_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/gather_sub128_matcher_test.cpp
diff --git a/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_set_property_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_set_property_test.cpp
new file mode 100644
index 00000000000..11f31e67aad
--- /dev/null
+++ b/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_set_property_test.cpp
@@ -0,0 +1,95 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <vector>
+
+#include "llm_test_helpers.hpp"
+#include "openvino/runtime/properties.hpp"
+
+namespace {
+using ov::test::npuw::MockSubCompiledModel;
+using ov::test::npuw::NullPlugin;
+
+// Stage model which records every set_property call it receives
+class PropertyRecordingSubCompiledModel final : public MockSubCompiledModel {
+public:
+ using MockSubCompiledModel::MockSubCompiledModel;
+
+ void set_property(const ov::AnyMap& properties) override {
+ if (reject) {
+ OPENVINO_THROW("Rejected: property can't be changed");
+ }
+ set_calls.push_back(properties);
+ }
+
+ bool reject = false;
+ std::vector<ov::AnyMap> set_calls;
+};
+
+class LLMCompiledModelSetPropertyTest : public ::testing::Test {
+protected:
+ void SetUp() override {
+ m_plugin = std::make_shared<NullPlugin>();
+ }
+
+ // Prefill, two generate variants (pyramid) and the shared LM head: every kind of
+ // inner model LLMCompiledModel keeps. m_kvcache_compiled aliases the last variant.
+ std::unique_ptr<ov::npuw::LLMCompiledModel> create_compiled_model() {
+ ov::AnyMap props = {{"NPUW_LLM", "YES"},
+ {"NPUW_LLM_MAX_PROMPT_LEN", "2048"},
+ {"NPUW_LLM_MIN_RESPONSE_LEN", "128"},
+ {"NPUW_LLM_GENERATE_PYRAMID", "YES"},
+ {"NPUW_LLM_SHARED_HEAD", "YES"}};
+ auto factory = [this](const std::shared_ptr<ov::Model>& model,
+ const std::shared_ptr<const ov::IPlugin>& plugin,
+ const ov::AnyMap& props) -> std::shared_ptr<ov::npuw::ICompiledModel_v0> {
+ auto stage = std::make_shared<PropertyRecordingSubCompiledModel>(model, plugin, props);
+ m_stages.push_back(stage);
+ return stage;
+ };
+ return std::make_unique<ov::npuw::LLMCompiledModel>(ov::test::npuw::build_llm_test_model(),
+ m_plugin,
+ props,
+ factory);
+ }
+
+ std::shared_ptr<ov::IPlugin> m_plugin;
+ std::vector<std::shared_ptr<PropertyRecordingSubCompiledModel>> m_stages;
+};
+
+TEST_F(LLMCompiledModelSetPropertyTest, ModelPriorityIsForwardedOnceToEveryStage) {
+ std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;
+ ASSERT_NO_THROW(compiled = create_compiled_model());
+ ASSERT_NE(compiled, nullptr);
+ // prefill + 2 generate variants + lm head
+ ASSERT_EQ(m_stages.size(), 4u);
+
+ const ov::AnyMap priority = {{ov::hint::model_priority.name(), ov::hint::Priority::HIGH}};
+ ASSERT_NO_THROW(compiled->set_property(priority));
+
+ for (std::size_t i = 0; i < m_stages.size(); ++i) {
+ ASSERT_EQ(m_stages[i]->set_calls.size(), 1u) << "Stage #" << i;
+ const auto& props = m_stages[i]->set_calls.front();
+ ASSERT_EQ(props.size(), 1u);
+ EXPECT_EQ(props.at(ov::hint::model_priority.name()).as<ov::hint::Priority>(), ov::hint::Priority::HIGH);
+ }
+}
+
+TEST_F(LLMCompiledModelSetPropertyTest, StageErrorIsPropagated) {
+ std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;
+ ASSERT_NO_THROW(compiled = create_compiled_model());
+ ASSERT_NE(compiled, nullptr);
+ ASSERT_FALSE(m_stages.empty());
+
+ // Stages validate which keys can be changed; a rejection must reach the caller
+ for (const auto& stage : m_stages) {
+ stage->reject = true;
+ }
+ EXPECT_ANY_THROW(compiled->set_property({{"NPUW_FOLD", true}}));
+}
+
+} // namespace
diff --git a/src/plugins/intel_npu/tests/unit/npuw/subgraph_pipeline.cpp b/src/plugins/intel_npu/tests/unit/npuw/subgraph_pipeline.cpp
index 58d9a10b674..81617a2b4f7 100644
--- a/src/plugins/intel_npu/tests/unit/npuw/subgraph_pipeline.cpp
+++ b/src/plugins/intel_npu/tests/unit/npuw/subgraph_pipeline.cpp
@@ -7,12 +7,19 @@
#include <gtest/gtest.h>
#include <string>
+#include <vector>
#include "attn/attn_subgraph.hpp"
+#include "host_flash_attention.hpp"
#include "moe/moe_executor.hpp"
+#include "moe/moe_subgraph.hpp"
+#include "moe_transformations/moe_transformation.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/result.hpp"
#include "partitioning/partitioning.hpp"
#include "partitioning/patterns/moe.hpp"
#include "partitioning/patterns/sdpa.hpp"
+#include "pyramid_attention.hpp"
namespace {
@@ -24,6 +31,85 @@ struct TestPayload {
TestPayload(int value, std::string name) : value(value), name(std::move(name)) {}
};
+class NullPlugin final : 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 {};
+ }
+};
+
+// Stands in for a device-level compiled model: only its identity matters to these tests
+class FakeCompiledModel final : public ov::ICompiledModel {
+public:
+ FakeCompiledModel(const std::shared_ptr<ov::Model>& model, const std::shared_ptr<const ov::IPlugin>& plugin)
+ : ov::ICompiledModel(model, plugin) {}
+
+ void export_model(std::ostream&) const override {}
+ std::shared_ptr<const ov::Model> get_runtime_model() const override {
+ return nullptr;
+ }
+ 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 nullptr;
+ }
+};
+
+ov::SoPtr<ov::ICompiledModel> make_fake_compiled_model() {
+ static const auto plugin = std::make_shared<NullPlugin>();
+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1});
+ auto result = std::make_shared<ov::op::v0::Result>(param);
+ auto model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{param});
+ return {std::make_shared<FakeCompiledModel>(model, plugin), {}};
+}
+
+// Runs the pipeline's extra-compiled-models hook and returns what it visited, in order
+std::vector<const ov::ICompiledModel*> visit_extra_compiled_models(
+ const ov::npuw::v1::subgraphs::CompiledPipeline& pipeline) {
+ std::vector<const ov::ICompiledModel*> visited;
+ pipeline.for_each_extra_compiled_model(pipeline.context, [&](const ov::SoPtr<ov::ICompiledModel>& cm) {
+ visited.push_back(cm._ptr.get());
+ });
+ return visited;
+}
+
} // namespace
TEST(SubgraphPipelineContextTest, StoresAndRetrievesTypedValues) {
@@ -208,3 +294,79 @@ TEST(SubgraphPipelineBehaviorTest, AttnCompileStageAttachesHFABehaviorWhenHintIs
auto behavior = compiled.runtime_behavior->factory(compiled.runtime_behavior->context);
EXPECT_NE(behavior, nullptr);
}
+
+// The extra-compiled-models hook is set by attach_runtime_behavior(), which runs both at
+// compile time (before the extra models are compiled) and on import (after the state is
+// restored). In every test below the models are filled in only after attaching, so the
+// hook must look them up when it is called rather than capture them when it is set.
+
+TEST(SubgraphPipelineExtraCompiledModelsTest, AttnPyramidVisitsAllPyramidModels) {
+ ov::npuw::v1::subgraphs::CompiledPipeline pipeline;
+ auto pyramid = std::make_shared<ov::npuw::compiled::PyramidAttentionContiguous>();
+ ov::npuw::attn::put_compiled_pyramid(pipeline.context, pyramid);
+ ov::npuw::attn::attach_runtime_behavior(pipeline, pipeline.context, ov::npuw::attn::BehaviorKind::Pyramid);
+ ASSERT_TRUE(static_cast<bool>(pipeline.for_each_extra_compiled_model));
+
+ const auto level_0 = make_fake_compiled_model();
+ const auto level_1 = make_fake_compiled_model();
+ const auto level_2 = make_fake_compiled_model();
+ pyramid->_compiled_models = {level_0, level_1, level_2};
+
+ EXPECT_EQ(visit_extra_compiled_models(pipeline),
+ (std::vector<const ov::ICompiledModel*>{level_0._ptr.get(), level_1._ptr.get(), level_2._ptr.get()}));
+}
+
+TEST(SubgraphPipelineExtraCompiledModelsTest, AttnHfaVisitsRegularAndFinalTiles) {
+ ov::npuw::v1::subgraphs::CompiledPipeline pipeline;
+ auto hfa = std::make_shared<ov::npuw::compiled::HostFlashAttention>();
+ ov::npuw::attn::put_compiled_hfa(pipeline.context, hfa);
+ ov::npuw::attn::attach_runtime_behavior(pipeline, pipeline.context, ov::npuw::attn::BehaviorKind::HFA);
+ ASSERT_TRUE(static_cast<bool>(pipeline.for_each_extra_compiled_model));
+
+ const auto tile = make_fake_compiled_model();
+ const auto final_tile = make_fake_compiled_model();
+ hfa->set_compiled_tile_model(tile);
+ hfa->set_compiled_final_tile_model(final_tile);
+
+ EXPECT_EQ(visit_extra_compiled_models(pipeline),
+ (std::vector<const ov::ICompiledModel*>{tile._ptr.get(), final_tile._ptr.get()}));
+}
+
+TEST(SubgraphPipelineExtraCompiledModelsTest, AttnDynamicVisitsNothing) {
+ ov::npuw::v1::subgraphs::CompiledPipeline pipeline;
+ ov::npuw::attn::attach_runtime_behavior(pipeline, pipeline.context, ov::npuw::attn::BehaviorKind::Dynamic);
+ ASSERT_TRUE(static_cast<bool>(pipeline.for_each_extra_compiled_model));
+
+ // Dynamic attention runs on the subgraph's own compiled model only
+ EXPECT_TRUE(visit_extra_compiled_models(pipeline).empty());
+}
+
+TEST(SubgraphPipelineExtraCompiledModelsTest, MoeExpertsVisitsEveryChunkModel) {
+ ov::npuw::v1::subgraphs::CompiledPipeline pipeline;
+ auto experts = std::make_shared<ov::npuw::compiled::MoEExperts>();
+ ov::npuw::moe::put_compiled_experts(pipeline.context, experts);
+ ov::npuw::moe::attach_runtime_behavior(pipeline, pipeline.context, ov::npuw::moe::BehaviorRole::EXPERTS, true);
+ ASSERT_TRUE(static_cast<bool>(pipeline.for_each_extra_compiled_model));
+
+ const auto chunk_64 = make_fake_compiled_model();
+ const auto chunk_128 = make_fake_compiled_model();
+ experts->_compiled_models[64] = chunk_64;
+ experts->_compiled_models[128] = chunk_128;
+
+ EXPECT_EQ(visit_extra_compiled_models(pipeline),
+ (std::vector<const ov::ICompiledModel*>{chunk_64._ptr.get(), chunk_128._ptr.get()}));
+}
+
+TEST(SubgraphPipelineExtraCompiledModelsTest, MoeDownstreamVisitsItsModel) {
+ ov::npuw::v1::subgraphs::CompiledPipeline pipeline;
+ auto downstream = std::make_shared<ov::npuw::compiled::MoEDownstream>();
+ ov::npuw::moe::put_compiled_downstream(pipeline.context, downstream);
+ ov::npuw::moe::attach_runtime_behavior(pipeline, pipeline.context, ov::npuw::moe::BehaviorRole::DOWNSTREAM, true);
+ ASSERT_TRUE(static_cast<bool>(pipeline.for_each_extra_compiled_model));
+
+ const auto downstream_model = make_fake_compiled_model();
+ downstream->_compiled_model = downstream_model;
+
+ EXPECT_EQ(visit_extra_compiled_models(pipeline),
+ (std::vector<const ov::ICompiledModel*>{downstream_model._ptr.get()}));
+}