Skip to content

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

[NPUW][MoE] Fix missing MoE runtime behavior attachment on cache import (#36252)

intelgaoxiongce500e96fff2
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 9ae2ba87828..99ebd4abbb0 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
@@ -912,6 +912,16 @@ void ov::npuw::CompiledModel::CompiledModelDesc::serialize(ov::npuw::s11n::Strea
ov::npuw::attn::BehaviorKind::Pyramid);
} else if (ov::npuw::attn::get_compiled_hfa(pipeline.context) != nullptr) {
ov::npuw::attn::attach_runtime_behavior(pipeline, pipeline.context, ov::npuw::attn::BehaviorKind::HFA);
+ } else if (ov::npuw::moe::get_compiled_experts(pipeline.context) != nullptr) {
+ ov::npuw::moe::attach_runtime_behavior(pipeline,
+ pipeline.context,
+ ov::npuw::moe::BehaviorRole::EXPERTS,
+ true);
+ } else if (ov::npuw::moe::get_compiled_downstream(pipeline.context) != nullptr) {
+ ov::npuw::moe::attach_runtime_behavior(pipeline,
+ pipeline.context,
+ ov::npuw::moe::BehaviorRole::DOWNSTREAM,
+ true);
}
}
}
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 366f6e0856c..a041bbee05a 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
@@ -59,14 +59,16 @@ ov::npuw::v1::subgraphs::RuntimeBehaviorFactory make_runtime_factory() {
};
}
-void attach_runtime_behavior(ov::npuw::v1::subgraphs::CompiledPipeline& compiled_pipeline,
- ov::npuw::v1::subgraphs::Context& compiled_context,
+} // namespace
+
+void attach_runtime_behavior(v1::subgraphs::CompiledPipeline& compiled_pipeline,
+ v1::subgraphs::Context& compiled_context,
const BehaviorRole role,
const bool handles_function_prologue) {
compiled_context.put<BehaviorRole>(role);
compiled_pipeline.registration.group = ov::npuw::patterns::moe::GPTOSSExpert::group_name();
compiled_pipeline.registration.name = behavior_name(role);
- ov::npuw::v1::subgraphs::RuntimeBehaviorSpec spec;
+ v1::subgraphs::RuntimeBehaviorSpec spec;
spec.registration = compiled_pipeline.registration;
spec.context = compiled_context;
spec.factory = make_runtime_factory();
@@ -74,6 +76,8 @@ void attach_runtime_behavior(ov::npuw::v1::subgraphs::CompiledPipeline& compiled
compiled_pipeline.runtime_behavior = std::move(spec);
}
+namespace {
+
template <typename T>
T* get_compiled_state(ov::npuw::v1::subgraphs::Context& context) {
auto* state = context.get_if<std::shared_ptr<T>>();
diff --git a/src/plugins/intel_npu/src/plugin/npuw/moe/moe_subgraph.hpp b/src/plugins/intel_npu/src/plugin/npuw/moe/moe_subgraph.hpp
index 2aa5a8b8b16..c044c876b24 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/moe/moe_subgraph.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/moe/moe_subgraph.hpp
@@ -53,6 +53,11 @@ void serialize_compiled_state(v1::subgraphs::Context& context,
ov::npuw::s11n::Stream& stream,
const ov::npuw::s11n::SubmodelDeserializeCtx* submodel_ctx);
+void attach_runtime_behavior(v1::subgraphs::CompiledPipeline& pipeline,
+ v1::subgraphs::Context& context,
+ BehaviorRole role,
+ bool handles_function_prologue);
+
std::vector<ov::npuw::v1::subgraphs::ScopedPatternRegistration> register_patterns(
ov::npuw::v1::subgraphs::PatternRegistry& registry,
std::size_t moe_chunk_size);