Skip to content

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

[NPUW] Wire generic MoE eligibility into LLM stage configuration (#38126)

Rajath Ravif07025aff4dc
diff --git a/src/plugins/intel_npu/docs/moe-runtime-semantics.md b/src/plugins/intel_npu/docs/moe-runtime-semantics.md
index 78bbc023b1d..a5656b142c4 100644
--- a/src/plugins/intel_npu/docs/moe-runtime-semantics.md
+++ b/src/plugins/intel_npu/docs/moe-runtime-semantics.md
@@ -59,4 +59,22 @@ defaults.
size are drained before reuse. Cleanup does not replace the original exception
or scatter partial results.
- Expert weight slices require a valid leading expert dimension and in-range
- expert index. Four-bit expert boundaries must be byte-aligned.
\ No newline at end of file
+ expert index. Four-bit expert boundaries must be byte-aligned.
+
+## LLM stage configuration
+
+LLM compilation detects compatible batched-MoE graphs structurally and retains
+router/expert name hints for legacy exports. Host-routed stages preserve the
+`expert` partition tag even for small models, without replacing existing tags.
+The existing shape-compute folding runs after stage shapes are prepared.
+
+Without an explicit `NPUW_LLM_GENERATE_MOE_HINT`, automatic device routing requires
+NPU architecture `5010`, compiler version 7.29 or later, single-token generation,
+and a supported batched-MoE boundary in every prepared generate variant. Every
+candidate boundary must pass the shared matcher and device-eligibility checks;
+an unsupported expert body prevents automatic device routing. A name hint alone
+is insufficient. Other cases retain the host-routed default.
+
+Explicit routing hints are preserved. Device routing remains unsupported for
+prefill, and explicit device decode must satisfy the core lowering requirements.
+`DENSE` remains restricted to CPU execution.
\ No newline at end of file
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 929764213db..b3634c3867d 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
@@ -16,6 +16,7 @@
#include "llm_infer_request.hpp"
#include "logging.hpp"
#include "moe_transformations/apply_moe_device_routed_transforms.hpp"
+#include "moe_transformations/moe_topology.hpp"
#include "npuw_transformations/add_position_ids_param.hpp"
#include "npuw_transformations/convert_kvcache_to_precision.hpp"
#include "npuw_transformations/detect_causal_mask.hpp"
@@ -49,6 +50,7 @@
#include "openvino/pass/validate.hpp"
#include "openvino/runtime/iasync_infer_request.hpp"
#include "openvino/runtime/properties.hpp"
+#include "openvino/util/common_util.hpp"
#include "partitioning/patterns/fold_const.hpp"
#include "partitioning/patterns/moe.hpp"
#include "partitioning/patterns/pre_compute.hpp"
@@ -525,10 +527,15 @@ bool has_per_layer_inputs(const std::shared_ptr<ov::Model>& model) {
return false;
}
-// Detect if the model is a Mixture-of-Experts (MoE) architecture
-// by checking if any node name matches MoE patterns: layers.*.mlp.router or layers.*.mlp.experts
+// Prefer structural detection. Keep names as a legacy hint for older exports
+// that still need normalization before their batched experts can be matched.
bool is_moe_model(const std::shared_ptr<ov::Model>& model) {
+ const ov::npuw::moe::BatchedMoEPattern pattern;
for (const auto& op : model->get_ops()) {
+ if (pattern.match(op)) {
+ LOG_INFO("Detected MoE model: supported batched expert topology");
+ return true;
+ }
const std::string& node_name = op->get_friendly_name();
// Check for MoE-specific patterns:
// - layers.*.mlp.router (router network for expert selection)
@@ -540,7 +547,7 @@ bool is_moe_model(const std::shared_ptr<ov::Model>& model) {
return true;
}
}
- LOG_DEBUG("Non-MoE model detected: no .mlp.router or .mlp.expert nodes found");
+ LOG_DEBUG("Non-MoE model detected: no supported topology or legacy router/expert names");
return false;
}
@@ -558,6 +565,18 @@ void apply_moe_config(ov::AnyMap& stage_config,
{"NPUW_UNFOLD_IREQS", "NO"},
};
merge_config_with(stage_config, expert_opts);
+ // Keep isolated experts even below the generic repeated-block threshold.
+ const auto keep_key = "NPUW_ONLINE_KEEP_BLOCKS_TAGGED";
+ auto keep = stage_config.find(keep_key);
+ if (keep == stage_config.end() || keep->second.as<std::string>().empty()) {
+ stage_config[keep_key] = "expert";
+ } else {
+ const auto& value = keep->second.as<std::string>();
+ const auto tags = ov::util::split(value);
+ if (std::find(tags.begin(), tags.end(), "expert") == tags.end()) {
+ keep->second = value + ",expert";
+ }
+ }
auto isol_it = stage_config.find("NPUW_ONLINE_ISOLATE");
if (isol_it != stage_config.end() && !isol_it->second.as<std::string>().empty()) {
isol_it->second = isol_it->second.as<std::string>() + ",MOE";
@@ -813,17 +832,6 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
LOG_INFO("Eagle3 speculative decoding mode enabled");
}
- // Auto-detect MoE model by scanning for router/expert nodes
- const bool is_moe = is_moe_model(model);
- if (is_moe) {
- // Enable DEVICE_ROUTED mode by default for MoE models on newer compiler versions, as it's more efficient than
- // HOST_ROUTED
- if (npuw_llm_props.find("NPUW_LLM_GENERATE_MOE_HINT") == npuw_llm_props.end() && npudesc->arch == "5010" &&
- npudesc->compiler_ver >= ONEAPI_MAKE_VERSION(7, 29)) {
- m_cfg.update({{"NPUW_LLM_GENERATE_MOE_HINT", "DEVICE_ROUTED"}});
- }
- }
-
// NB: PREFILL_HINT is now compatible with the PREFILL_CONFIG section, unlike for
// the generate model they're not mutually exclusive
const ::intel_npu::npuw::llm::PrefillHint prefill_hint = m_cfg.get<::intel_npu::NPUW_LLM_PREFILL_HINT>();
@@ -1351,15 +1359,7 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
m_longrope_tables.rebuild_tables();
}
- if (is_moe) {
- // Apply MoE configuration for prefill stage
- const auto prefill_moe_hint = m_cfg.get<::intel_npu::NPUW_LLM_PREFILL_MOE_HINT>();
- apply_moe_config(prefill_config, prefill_moe_hint, "PREFILL");
-
- // Apply MoE configuration for generate stage
- const auto generate_moe_hint = m_cfg.get<::intel_npu::NPUW_LLM_GENERATE_MOE_HINT>();
- apply_moe_config(generate_config, generate_moe_hint, "GENERATE");
-
+ if (is_moe_model(model)) {
// Fold shape-compute chains (ShapeOf→Gather→Concat etc.) in the prefill model before
// online partitioning runs pattern matching (e.g. GPTOSSRouter). Must run after
// ReshapeToStatic has made all shapes static so that ShapeOf bounds are resolvable.
@@ -1368,6 +1368,36 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
ov::npuw::patterns::util::FoldShapeComputeChain().run_on_model(model_variant);
}
+ const auto eligible = [](const std::shared_ptr<ov::Model>& variant) {
+ bool found = false;
+ const ov::npuw::moe::BatchedMoEPattern pattern;
+ for (const auto& node : variant->get_ordered_ops()) {
+ if (!ov::is_type<ov::op::v1::ReduceSum>(node)) {
+ continue;
+ }
+ opp::Matcher matcher(pattern.root(), "LLMMoEDeviceEligibility");
+ if (matcher.match(node)) {
+ const auto topology = pattern.extract(matcher);
+ if (!topology || !ov::npuw::moe::can_device_route(*topology)) {
+ return false;
+ }
+ found = true;
+ }
+ }
+ return found;
+ };
+ if (npuw_llm_props.count("NPUW_LLM_GENERATE_MOE_HINT") == 0 && npudesc && npudesc->arch == "5010" &&
+ npudesc->compiler_ver >= ONEAPI_MAKE_VERSION(7, 29) &&
+ m_cfg.get<::intel_npu::NPUW_LLM_MAX_GENERATION_TOKEN_LEN>() == 1 && !generate_model_variants.empty() &&
+ std::all_of(generate_model_variants.begin(), generate_model_variants.end(), eligible)) {
+ m_cfg.update({{"NPUW_LLM_GENERATE_MOE_HINT", "DEVICE_ROUTED"}});
+ }
+
+ const auto prefill_moe_hint = m_cfg.get<::intel_npu::NPUW_LLM_PREFILL_MOE_HINT>();
+ apply_moe_config(prefill_config, prefill_moe_hint, "PREFILL");
+ const auto generate_moe_hint = m_cfg.get<::intel_npu::NPUW_LLM_GENERATE_MOE_HINT>();
+ apply_moe_config(generate_config, generate_moe_hint, "GENERATE");
+
if (generate_moe_hint == ::intel_npu::npuw::llm::MoEHint::DEVICE_ROUTED) {
// Apply model transformations only to GENERATE stage (PREFILL doesn't support DEVICE_ROUTED
// transformations)
diff --git a/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_factory_options_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_factory_options_test.cpp
index e49694ad045..0b7b0b852e3 100644
--- a/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_factory_options_test.cpp
+++ b/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_factory_options_test.cpp
@@ -12,14 +12,18 @@
#include <utility>
#include <vector>
+#include "intel_npu/config/npuw.hpp"
#include "llm_compiled_model_utils.hpp"
#include "llm_test_helpers.hpp"
+#include "moe_transformations/moe_topology.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convert.hpp"
#include "openvino/op/gather.hpp"
#include "openvino/op/matmul.hpp"
#include "openvino/op/multiply.hpp"
#include "openvino/op/parameter.hpp"
+#include "openvino/op/relu.hpp"
+#include "openvino/op/reshape.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/pass/stateful_to_stateless.hpp"
#include "openvino/runtime/intel_npu/properties.hpp"
@@ -27,6 +31,7 @@
#include "whisper/prepare_whisper_model.hpp"
namespace {
+using MoEHint = intel_npu::npuw::llm::MoEHint;
using ov::test::npuw::CompileCall;
using ov::test::npuw::NullPlugin;
using ov::test::npuw::RecordingFactory;
@@ -44,7 +49,10 @@ bool has_transposed_value_matmul(const std::shared_ptr<ov::Model>& model, std::s
class ArchAwarePlugin final : public NullPlugin {
public:
- ArchAwarePlugin(std::string arch, int64_t max_tiles) : m_arch(std::move(arch)), m_max_tiles(max_tiles) {}
+ ArchAwarePlugin(std::string arch, int64_t max_tiles, int64_t compiler_version = 0)
+ : m_arch(std::move(arch)),
+ m_max_tiles(max_tiles),
+ m_compiler_version(compiler_version) {}
ov::Any get_property(const std::string& name, const ov::AnyMap&) const override {
if (name == ov::device::architecture.name()) {
@@ -54,7 +62,7 @@ public:
return m_max_tiles;
}
if (name == ov::intel_npu::compiler_version.name()) {
- return static_cast<int64_t>(0);
+ return m_compiler_version;
}
if (name == ov::supported_properties.name()) {
return std::vector<ov::PropertyName>{};
@@ -65,6 +73,7 @@ public:
private:
std::string m_arch;
int64_t m_max_tiles;
+ int64_t m_compiler_version;
};
std::shared_ptr<ov::MockICore> attach_mock_core_with_npu_device(
@@ -83,6 +92,247 @@ std::shared_ptr<ov::MockICore> attach_mock_core_with_npu_device(
return core;
}
+TEST(LLMMoEAutoRoutingTest, UsesDeviceOnlyForSupportedSingleTokenGraphs) {
+ constexpr int64_t compiler_8_3 = (8 << 16) | 3;
+ auto plugin = std::make_shared<ArchAwarePlugin>("5010", 3, compiler_8_3);
+ auto core = attach_mock_core_with_npu_device(plugin);
+ for (const size_t tokens : {size_t{1}, size_t{8}}) {
+ SCOPED_TRACE(tokens);
+ ov::AnyMap props{{"NPUW_LLM", "YES"},
+ {"NPUW_LLM_MAX_PROMPT_LEN", "128"},
+ {"NPUW_LLM_MIN_RESPONSE_LEN", "64"},
+ {"NPUW_LLM_MAX_GENERATION_TOKEN_LEN", std::to_string(tokens)}};
+ RecordingFactory recorder;
+ ov::npuw::LLMCompiledModel compiled(ov::test::npuw::build_qwen3_moe_llm_test_model(),
+ plugin,
+ props,
+ recorder.make_factory());
+ const auto* generate = recorder.find_contains("_kv");
+ ASSERT_NE(generate, nullptr);
+ EXPECT_EQ(compiled.get_property("NPUW_LLM_GENERATE_MOE_HINT").as<MoEHint>(),
+ tokens == 1 ? MoEHint::DEVICE_ROUTED : MoEHint::HOST_ROUTED);
+ EXPECT_EQ(generate->props.at("NPUW_UNFOLD_IREQS").as<std::string>(), tokens == 1 ? "YES" : "NO");
+ const ov::npuw::moe::BatchedMoEPattern pattern;
+ const auto generate_ops = generate->model->get_ops();
+ EXPECT_EQ(std::any_of(generate_ops.begin(),
+ generate_ops.end(),
+ [&](const auto& op) {
+ return pattern.match(op).has_value();
+ }),
+ tokens != 1);
+ if (tokens == 8) {
+ props["NPUW_LLM_GENERATE_MOE_HINT"] = "DEVICE_ROUTED";
+ EXPECT_THROW(ov::npuw::LLMCompiledModel(ov::test::npuw::build_qwen3_moe_llm_test_model(),
+ plugin,
+ props,
+ recorder.make_factory()),
+ ov::Exception);
+ }
+ }
+}
+
+TEST(LLMMoEAutoRoutingTest, NameHintAloneDoesNotSelectDeviceRouting) {
+ constexpr int64_t compiler_8_3 = (8 << 16) | 3;
+ auto plugin = std::make_shared<ArchAwarePlugin>("5010", 3, compiler_8_3);
+ auto core = attach_mock_core_with_npu_device(plugin);
+ auto model = ov::test::npuw::build_llm_test_model();
+ model->get_parameters()[0]->set_friendly_name("legacy.expert_name_without_supported_topology");
+ ov::AnyMap props{{"NPUW_LLM", "YES"}, {"NPUW_LLM_MAX_PROMPT_LEN", "128"}, {"NPUW_LLM_MIN_RESPONSE_LEN", "64"}};
+ RecordingFactory recorder;
+ ov::npuw::LLMCompiledModel compiled(model, plugin, props, recorder.make_factory());
+ const auto* generate = recorder.find_contains("_kv");
+ ASSERT_NE(generate, nullptr);
+ EXPECT_EQ(generate->props.at("NPUW_UNFOLD_IREQS").as<std::string>(), "NO");
+}
+
+TEST(LLMMoEAutoRoutingTest, RetainsArchitectureAndCompilerEligibilityGates) {
+ struct Case {
+ std::string arch;
+ int64_t compiler;
+ bool device_routed;
+ };
+ for (const auto& test : {Case{"5010", (7 << 16) | 28, false},
+ Case{"5010", (7 << 16) | 29, true},
+ Case{"4000", (8 << 16) | 3, false}}) {
+ SCOPED_TRACE(test.arch + "/" + std::to_string(test.compiler));
+ auto plugin = std::make_shared<ArchAwarePlugin>(test.arch, 3, test.compiler);
+ auto core = attach_mock_core_with_npu_device(plugin);
+ ov::AnyMap props{{"NPUW_LLM", "YES"}, {"NPUW_LLM_MAX_PROMPT_LEN", "128"}, {"NPUW_LLM_MIN_RESPONSE_LEN", "64"}};
+ RecordingFactory recorder;
+ ov::npuw::LLMCompiledModel compiled(ov::test::npuw::build_qwen3_moe_llm_test_model(),
+ plugin,
+ props,
+ recorder.make_factory());
+ const auto* generate = recorder.find_contains("_kv");
+ ASSERT_NE(generate, nullptr);
+ EXPECT_EQ(generate->props.at("NPUW_UNFOLD_IREQS").as<std::string>(), test.device_routed ? "YES" : "NO");
+ const auto* prefill = recorder.find_suffix("_prefill");
+ ASSERT_NE(prefill, nullptr);
+ EXPECT_EQ(prefill->props.at("NPUW_UNFOLD_IREQS").as<std::string>(), "NO");
+ }
+}
+
+TEST(LLMMoEAutoRoutingTest, ExplicitHostHintPreservesOtherStageProperties) {
+ auto plugin = std::make_shared<ArchAwarePlugin>("5010", 3, (8 << 16) | 3);
+ auto core = attach_mock_core_with_npu_device(plugin);
+ ov::AnyMap props{{"NPUW_LLM", "YES"},
+ {"NPUW_LLM_MAX_PROMPT_LEN", "128"},
+ {"NPUW_LLM_MIN_RESPONSE_LEN", "64"},
+ {"NPUW_LLM_GENERATE_MOE_HINT", "HOST_ROUTED"},
+ {"NPUW_LLM_PREFILL_MOE_HINT", "HOST_ROUTED"},
+ {"NPUW_ONLINE_KEEP_BLOCKS_TAGGED", "attn,custom"},
+ {"NPUW_FALLBACK_EXEC", "NO"},
+ {"NPUW_FUNCALL_ASYNC", "NO"}};
+ RecordingFactory recorder;
+ ov::npuw::LLMCompiledModel compiled(ov::test::npuw::build_qwen3_moe_llm_test_model(),
+ plugin,
+ props,
+ recorder.make_factory());
+ for (const auto* call : {recorder.find_suffix("_prefill"), recorder.find_contains("_kv")}) {
+ ASSERT_NE(call, nullptr);
+ EXPECT_EQ(call->props.at("NPUW_UNFOLD_IREQS").as<std::string>(), "NO");
+ EXPECT_EQ(call->props.at("NPUW_ONLINE_KEEP_BLOCKS_TAGGED").as<std::string>(), "attn,custom,expert");
+ EXPECT_EQ(call->props.at("NPUW_FALLBACK_EXEC").as<std::string>(), "NO");
+ EXPECT_EQ(call->props.at("NPUW_FUNCALL_ASYNC").as<std::string>(), "NO");
+ }
+}
+
+TEST(LLMMoEAutoRoutingTest, DoesNotDuplicateExistingExpertTag) {
+ auto plugin = std::make_shared<NullPlugin>();
+ for (const std::string tags : {"expert", "attn,expert,custom"}) {
+ SCOPED_TRACE(tags);
+ ov::AnyMap props{{"NPUW_LLM", "YES"},
+ {"NPUW_LLM_MAX_PROMPT_LEN", "128"},
+ {"NPUW_LLM_MIN_RESPONSE_LEN", "64"},
+ {"NPUW_LLM_GENERATE_MOE_HINT", "HOST_ROUTED"},
+ {"NPUW_ONLINE_KEEP_BLOCKS_TAGGED", tags}};
+ RecordingFactory recorder;
+ ov::npuw::LLMCompiledModel compiled(ov::test::npuw::build_qwen3_moe_llm_test_model(),
+ plugin,
+ props,
+ recorder.make_factory());
+ for (const auto* call : {recorder.find_suffix("_prefill"), recorder.find_contains("_kv")}) {
+ ASSERT_NE(call, nullptr);
+ EXPECT_EQ(call->props.at("NPUW_ONLINE_KEEP_BLOCKS_TAGGED").as<std::string>(), tags);
+ }
+ }
+}
+
+TEST(LLMMoEAutoRoutingTest, MixedSupportedAndUnsupportedBlocksKeepHostRouting) {
+ auto plugin = std::make_shared<ArchAwarePlugin>("5010", 3, (8 << 16) | 3);
+ auto core = attach_mock_core_with_npu_device(plugin);
+ auto model = ov::test::npuw::build_qwen3_moe_llm_test_model();
+ const ov::npuw::moe::BatchedMoEPattern pattern;
+ std::vector<ov::npuw::moe::BatchedMoE> blocks;
+ for (const auto& op : model->get_ordered_ops()) {
+ if (const auto moe = pattern.match(op)) {
+ blocks.push_back(*moe);
+ }
+ }
+ ASSERT_GT(blocks.size(), 1u);
+ const auto& block = blocks.front();
+ bool modified = false;
+ for (const auto& op : block.expert_nodes) {
+ const auto matmul = ov::as_type_ptr<ov::op::v0::MatMul>(op);
+ if (!matmul) {
+ continue;
+ }
+ const auto prefix = matmul->input_value(0).get_node_shared_ptr();
+ if (prefix == block.tile ||
+ (ov::is_type<ov::op::v1::Reshape>(prefix) && prefix->input_value(0).get_node_shared_ptr() == block.tile)) {
+ auto relu = std::make_shared<ov::op::v0::Relu>(matmul->input_value(0));
+ matmul->input(0).replace_source_output(relu);
+ modified = true;
+ break;
+ }
+ }
+ ASSERT_TRUE(modified);
+ model->validate_nodes_and_infer_types();
+ ASSERT_FALSE(pattern.match(block.reduction));
+ ASSERT_TRUE(pattern.match(blocks.back().reduction));
+ ov::AnyMap props{{"NPUW_LLM", "YES"},
+ {"NPUW_LLM_MAX_PROMPT_LEN", "2048"},
+ {"NPUW_LLM_MIN_RESPONSE_LEN", "128"},
+ {"NPUW_LLM_GENERATE_PYRAMID", "YES"}};
+ RecordingFactory recorder;
+ ov::npuw::LLMCompiledModel compiled(model, plugin, props, recorder.make_factory());
+ EXPECT_EQ(compiled.get_property("NPUW_LLM_GENERATE_MOE_HINT").as<MoEHint>(), MoEHint::HOST_ROUTED);
+ ASSERT_EQ(recorder.count_contains("_kv"), 2u);
+ for (const auto& call : recorder.calls()) {
+ if (call.friendly_name.find("_kv") != std::string::npos) {
+ EXPECT_EQ(call.props.at("NPUW_UNFOLD_IREQS").as<std::string>(), "NO");
+ }
+ }
+}
+
+TEST(LLMMoEAutoRoutingTest, KeepsHostRoutingWithoutAnNpuDescriptor) {
+ auto plugin = std::make_shared<NullPlugin>();
+ ov::AnyMap props{{"NPUW_LLM", "YES"}, {"NPUW_LLM_MAX_PROMPT_LEN", "128"}, {"NPUW_LLM_MIN_RESPONSE_LEN", "64"}};
+ RecordingFactory recorder;
+ ov::npuw::LLMCompiledModel compiled(ov::test::npuw::build_qwen3_moe_llm_test_model(),
+ plugin,
+ props,
+ recorder.make_factory());
+ EXPECT_EQ(compiled.get_property("NPUW_LLM_GENERATE_MOE_HINT").as<MoEHint>(), MoEHint::HOST_ROUTED);
+ const auto* generate = recorder.find_contains("_kv");
+ ASSERT_NE(generate, nullptr);
+ EXPECT_EQ(generate->props.at("NPUW_UNFOLD_IREQS").as<std::string>(), "NO");
+}
+
+TEST(LLMMoEAutoRoutingTest, DetectsUnnamedTopologyAndPreparesEveryGenerateVariant) {
+ auto plugin = std::make_shared<ArchAwarePlugin>("5010", 3, (8 << 16) | 3);
+ auto core = attach_mock_core_with_npu_device(plugin);
+ auto model = ov::test::npuw::build_qwen3_moe_llm_test_model();
+ size_t renamed = 0;
+ for (const auto& op : model->get_ops()) {
+ const auto name = op->get_friendly_name();
+ if (name.find(".expert") != std::string::npos || name.find(".router") != std::string::npos)
+ op->set_friendly_name("unnamed_mlp_" + std::to_string(renamed++));
+ }
+ ASSERT_GT(renamed, 0u);
+ ov::AnyMap props{{"NPUW_LLM", "YES"},
+ {"NPUW_LLM_SHARED_HEAD", "NO"},
+ {"NPUW_LLM_MAX_PROMPT_LEN", "2048"},
+ {"NPUW_LLM_MIN_RESPONSE_LEN", "128"},
+ {"NPUW_LLM_GENERATE_PYRAMID", "YES"}};
+ RecordingFactory recorder;
+ ov::npuw::LLMCompiledModel compiled(model, plugin, props, recorder.make_factory());
+ ASSERT_EQ(recorder.count_contains("_kv"), 2u);
+ const auto* prefill = recorder.find_suffix("_prefill");
+ ASSERT_NE(prefill, nullptr);
+ EXPECT_EQ(prefill->props.at("NPUW_ONLINE_KEEP_BLOCKS_TAGGED").as<std::string>(), "expert");
+ EXPECT_EQ(compiled.get_property("NPUW_LLM_GENERATE_MOE_HINT").as<MoEHint>(), MoEHint::DEVICE_ROUTED);
+ const ov::npuw::moe::BatchedMoEPattern pattern;
+ for (const auto& call : recorder.calls()) {
+ if (call.model->get_friendly_name().find("_kv") != std::string::npos) {
+ EXPECT_EQ(call.props.at("NPUW_UNFOLD_IREQS").as<std::string>(), "YES");
+ for (const auto& op : call.model->get_ops()) {
+ EXPECT_FALSE(pattern.match(op));
+ }
+ }
+ }
+}
+
+TEST(LLMMoEAutoRoutingTest, RejectsExplicitDevicePrefillAndUnsupportedDecode) {
+ auto plugin = std::make_shared<ArchAwarePlugin>("5010", 3, (8 << 16) | 3);
+ auto core = attach_mock_core_with_npu_device(plugin);
+ ov::AnyMap props{{"NPUW_LLM", "YES"},
+ {"NPUW_LLM_MAX_PROMPT_LEN", "128"},
+ {"NPUW_LLM_MIN_RESPONSE_LEN", "64"},
+ {"NPUW_LLM_PREFILL_MOE_HINT", "DEVICE_ROUTED"}};
+ RecordingFactory recorder;
+ EXPECT_THROW(ov::npuw::LLMCompiledModel(ov::test::npuw::build_qwen3_moe_llm_test_model(),
+ plugin,
+ props,
+ recorder.make_factory()),
+ ov::Exception);
+ props["NPUW_LLM_PREFILL_MOE_HINT"] = "HOST_ROUTED";
+ props["NPUW_LLM_GENERATE_MOE_HINT"] = "DEVICE_ROUTED";
+ auto model = ov::test::npuw::build_llm_test_model();
+ model->get_parameters()[0]->set_friendly_name("legacy.expert_without_supported_topology");
+ EXPECT_THROW(ov::npuw::LLMCompiledModel(model, plugin, props, recorder.make_factory()), ov::Exception);
+}
+
class LLMCompiledModelFactoryOptionsTest : public ::testing::Test {
protected:
void SetUp() override {
diff --git a/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_graph_options_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_graph_options_test.cpp
index f972f716933..ba4b8b0c3bb 100644
--- a/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_graph_options_test.cpp
+++ b/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_graph_options_test.cpp
@@ -111,6 +111,20 @@ protected:
std::shared_ptr<ov::IPlugin> m_plugin;
};
+TEST_F(LLMCompiledModelGraphOptionsTest, SparseMoEPreservesExpertFoldingForSmallModels) {
+ RecordingFactory recorder;
+ auto props = base_props();
+ props["NPUW_LLM_GENERATE_MOE_HINT"] = "HOST_ROUTED";
+ props["NPUW_LLM_PREFILL_MOE_HINT"] = "HOST_ROUTED";
+ props["NPUW_ONLINE_KEEP_BLOCKS_TAGGED"] = "attn";
+ const auto model = ov::test::npuw::build_qwen3_moe_llm_test_model();
+ auto compiled = std::make_unique<ov::npuw::LLMCompiledModel>(model, m_plugin, props, recorder.make_factory());
+ const auto& prefill = require_call_containing(recorder, "_prefill");
+ EXPECT_EQ(prefill.props.at("NPUW_ONLINE_KEEP_BLOCKS_TAGGED").as<std::string>(), "attn,expert");
+ const auto& generate = require_call_containing(recorder, "_kv");
+ EXPECT_EQ(generate.props.at("NPUW_ONLINE_KEEP_BLOCKS_TAGGED").as<std::string>(), "attn,expert");
+}
+
TEST_F(LLMCompiledModelGraphOptionsTest, SharedHeadAddsHeadModelAndSlicesPrefillEmbeds) {
RecordingFactory recorder;
std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;