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] Architecture-aware NPU tile configuration (#35601)
Eugene Smirnov7dcd68cc424d
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 2166db0c621..81384ff7e46 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@@ -208,7 +208,6 @@ std::optional<NPUDesc> extract_npu_descriptor(const std::shared_ptr<const ov::IPif (all_devices.empty()) {return std::nullopt;}-NPUDesc desc;desc.arch = plugin->get_property(ov::device::architecture.name(), ov::AnyMap{}).as<std::string>();desc.max_tiles = plugin->get_property(ov::intel_npu::max_tiles.name(), ov::AnyMap{}).as<int64_t>();@@ -315,14 +314,52 @@ ov::AnyMap get_default_common_config(const std::optional<NPUDesc>& npudesc) {} else {config.emplace("NPUW_FUNCALL_FOR_ALL", "YES");}+ auto set_max_tiles_based_on_arch = [&config, &npudesc]() {+ if (!npudesc.has_value()) {+ return;+ }+ LOG_DEBUG("NPU architecture detected: " << npudesc->arch << ", max tiles: " << npudesc->max_tiles+ << ", compiler DQ support: " << (npudesc->compiler_dq ? "YES" : "NO"));++ // Platform parameter has a higher priority than deviceID+ std::string npu_platform;+ if (npudesc->arch != ov::intel_npu::Platform::AUTO_DETECT) {+ npu_platform = ov::intel_npu::Platform::standardize(npudesc->arch);+ } else {+ npu_platform = npudesc->arch;+ }++ bool set_npu_tiles = false;+ std::string arch_added_compilation_param;+ if (npu_platform == ov::intel_npu::Platform::NPU3720) {+ // Keep baseline settings.+ } else if (npu_platform == ov::intel_npu::Platform::NPU4000) {+ set_npu_tiles = true;+ arch_added_compilation_param = "optimization-level=3";+ } else if (npu_platform == ov::intel_npu::Platform::NPU5010 ||+ npu_platform == ov::intel_npu::Platform::NPU5020) {+ set_npu_tiles = true;+ } else if (npu_platform == ov::intel_npu::Platform::AUTO_DETECT) {+ arch_added_compilation_param = "performance-hint-override=latency";+ } else {+ LOG_WARN("Unknown NPU platform: " << npu_platform << ". Default config will be used.");+ }++ if (set_npu_tiles) {+ config["NPU_TILES"] = npudesc->max_tiles;+ }++ if (!arch_added_compilation_param.empty()) {+ config["NPU_COMPILATION_MODE_PARAMS"] =+ config["NPU_COMPILATION_MODE_PARAMS"].as<std::string>() + " " + arch_added_compilation_param;+ }+ };+ set_max_tiles_based_on_arch();return config;}ov::AnyMap get_default_prefill_config(const std::shared_ptr<ov::Model>& model, const std::optional<NPUDesc>& npudesc) {auto config = get_default_common_config(npudesc);- if (npudesc.has_value() && npudesc->arch == "4000" && npudesc->max_tiles != -1) {- config.emplace("NPU_TILES", npudesc->max_tiles);- }// Specify NPUW DQ if Compiler DQ is not enabledif (!npudesc.has_value() || !npudesc->compiler_dq) {if (is_cw_compressed(model)) {@@ -945,6 +982,11 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& mLOG_DEBUG("Converting KV-cache in prefill model to" << kv_kache_storage_type);ov::npuw::ConvertKVCacheToPrecision(kv_kache_storage_type).run_on_model(prefill_model);+ std::optional<std::string> user_compilation_mode_params = std::nullopt;+ if (const auto it = other_props.find("NPU_COMPILATION_MODE_PARAMS"); it != other_props.end()) {+ user_compilation_mode_params = it->second.as<std::string>();+ }+auto prefill_config =prefill_config_opt.value_or(get_default_prefill_config(prefill_model, npudesc)).as<ov::AnyMap>();@@ -956,6 +998,14 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& mauto generate_config =generate_config_opt.value_or(get_default_generate_config(npudesc, generate_hint)).as<ov::AnyMap>();+ const std::optional<std::string> default_compilation_mode_params =+ [&prefill_config]() -> std::optional<std::string> {+ if (const auto it = prefill_config.find("NPU_COMPILATION_MODE_PARAMS"); it != prefill_config.end()) {+ return it->second.as<std::string>();+ }+ return std::nullopt;+ }();+auto prefill_config_addition_value =prefill_config_addition.has_value() ? prefill_config_addition.value().as<ov::AnyMap>() : ov::AnyMap{};auto generate_config_addition_value =@@ -966,6 +1016,13 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& mmerge_config_with(prefill_config, prefill_config_addition_value);merge_config_with(generate_config, generate_config_addition_value);+ if (user_compilation_mode_params.has_value() && default_compilation_mode_params.has_value() &&+ user_compilation_mode_params.value() != default_compilation_mode_params.value()) {+ LOG_WARN("User-provided NPU_COMPILATION_MODE_PARAMS overrides arch-aware setting \""+ << default_compilation_mode_params.value() << "\". User value: \""+ << user_compilation_mode_params.value() << "\".");+ }+// Generate a random weights bank name unique to this LLMCompiledModel objectauto weights_bank_name = ov::npuw::util::generate_random_string();LOG_VERB("Generated a unique weights bank name: " << weights_bank_name);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.cppindex 2811e77b94e..c15b6c8f211 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@@ -13,6 +13,7 @@#include <vector>#include "llm_test_helpers.hpp"+#include "openvino/runtime/intel_npu/properties.hpp"#include "whisper/prepare_whisper_model.hpp"#include "openvino/pass/stateful_to_stateless.hpp"#include "unit_test_utils/mocks/openvino/runtime/mock_icore.hpp"@@ -22,6 +23,46 @@ using ov::test::npuw::CompileCall;using ov::test::npuw::NullPlugin;using ov::test::npuw::RecordingFactory;+class ArchAwarePlugin final : public NullPlugin {+public:+ ArchAwarePlugin(std::string arch, int64_t max_tiles) : m_arch(std::move(arch)), m_max_tiles(max_tiles) {}++ ov::Any get_property(const std::string& name, const ov::AnyMap&) const override {+ if (name == ov::device::architecture.name()) {+ return m_arch;+ }+ if (name == ov::intel_npu::max_tiles.name()) {+ return m_max_tiles;+ }+ if (name == ov::intel_npu::compiler_version.name()) {+ return static_cast<int64_t>(0);+ }+ if (name == ov::supported_properties.name()) {+ return std::vector<ov::PropertyName>{};+ }+ return {};+ }++private:+ std::string m_arch;+ int64_t m_max_tiles;+};++std::shared_ptr<ov::MockICore> attach_mock_core_with_npu_device(const std::shared_ptr<ov::IPlugin>& plugin,+ std::vector<std::string> device_list = std::vector<std::string>{"0"}) {+ auto core = std::make_shared<testing::NiceMock<ov::MockICore>>();+ plugin->set_core(core);++ ON_CALL(*core,+ get_property(testing::StrEq("NPU"),+ testing::StrEq(ov::available_devices.name()),+ testing::An<const ov::AnyMap&>()))+ .WillByDefault([device_list](const std::string&, const std::string&, const ov::AnyMap&) -> ov::Any {+ return ov::Any(device_list);+ });+ return core;+}+class LLMCompiledModelFactoryOptionsTest : public ::testing::Test {protected:void SetUp() override {@@ -84,6 +125,12 @@ protected:return it->second.as<std::string>();}+ static int64_t prop_i64(const ov::AnyMap& props, const std::string& key) {+ const auto it = props.find(key);+ OPENVINO_ASSERT(it != props.end(), "Missing property: ", key);+ return it->second.as<int64_t>();+ }+static void expect_prop(const ov::AnyMap& props, const std::string& key, const std::string& expected) {EXPECT_EQ(prop_string(props, key), expected);}@@ -353,6 +400,198 @@ TEST_F(LLMCompiledModelFactoryOptionsTest, CommonRuntimeAndDebugOptionsForwardTo}}+TEST_F(LLMCompiledModelFactoryOptionsTest, ArchIn5000SeriesSetsNpuTilesInDefaultStageConfigs) {+ m_plugin = std::make_shared<ArchAwarePlugin>("5010", 3);+ const auto core = attach_mock_core_with_npu_device(m_plugin);++ RecordingFactory recorder;+ std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;++ ASSERT_NO_THROW(compiled = create_compiled_model(build_llm_model(), {{"NPUW_LLM_SHARED_HEAD", "YES"}}, recorder));+ ASSERT_NE(compiled, nullptr);++ const auto& prefill = require_call(recorder, "_prefill");+ const auto& generate = require_call_containing(recorder, "_kv");+ const auto& head = require_call(recorder, "_lm_head");++ for (const auto* call : {&prefill, &generate, &head}) {+ EXPECT_EQ(prop_i64(call->props, "NPU_TILES"), 3);+ expect_prop(call->props,+ "NPU_COMPILATION_MODE_PARAMS",+ "compute-layers-with-higher-precision=Sqrt,Power,ReduceMean,Add_RMSNorm");+ }+}++struct UserStageConfigParam {+ std::string arch;+ int64_t max_tiles; // reported by the plugin (arch default)+ int64_t user_tiles; // NPU_TILES value explicitly provided by the user+ // Note: NPU_COMPILATION_MODE_PARAMS is a space-separated token string.+ // Supplying it here performs a *full replace* of the arch-computed value+ // (which may include tokens like optimization-level=3 or performance-hint-override=latency).+ // The production code emits a LOG_WARN when the user value differs from the arch-computed one+ // so the user is informed that arch-specific tokens will be lost unless explicitly repeated.+ // A proper additive mechanism (analogous to ++NPUW_LLM_PREFILL_CONFIG) does not yet exist+ // for this property.+ std::string user_compile_params; // NPU_COMPILATION_MODE_PARAMS override; empty = not provided+};++class StageConfigUserOverrideTest : public LLMCompiledModelFactoryOptionsTest,+ public ::testing::WithParamInterface<UserStageConfigParam> {};++// User-provided NPU_TILES (and optionally NPU_COMPILATION_MODE_PARAMS) must take priority+// over the arch-computed defaults from set_max_tiles_based_on_arch, regardless of the NPU platform.+TEST_P(StageConfigUserOverrideTest, UserSettingsOverrideArchDefaults) {+ const auto& param = GetParam();+ m_plugin = std::make_shared<ArchAwarePlugin>(param.arch, param.max_tiles);+ const auto core = attach_mock_core_with_npu_device(m_plugin);++ RecordingFactory recorder;+ std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;++ ov::AnyMap extra_props = {{"NPUW_LLM_SHARED_HEAD", "YES"}, {"NPU_TILES", param.user_tiles}};+ if (!param.user_compile_params.empty()) {+ extra_props["NPU_COMPILATION_MODE_PARAMS"] = param.user_compile_params;+ }++ ASSERT_NO_THROW(compiled = create_compiled_model(build_llm_model(), extra_props, recorder));+ ASSERT_NE(compiled, nullptr);++ const auto& prefill = require_call(recorder, "_prefill");+ const auto& generate = require_call_containing(recorder, "_kv");+ const auto& head = require_call(recorder, "_lm_head");++ for (const auto* call : {&prefill, &generate, &head}) {+ EXPECT_EQ(call->props.count("NPU_TILES"), 1u) << "NPU_TILES must appear exactly once in compiled stage config";+ EXPECT_EQ(prop_i64(call->props, "NPU_TILES"), param.user_tiles);++ if (!param.user_compile_params.empty()) {+ EXPECT_EQ(call->props.count("NPU_COMPILATION_MODE_PARAMS"), 1u)+ << "NPU_COMPILATION_MODE_PARAMS must appear exactly once in compiled stage config";+ // Full replace: the user value entirely replaces the arch-computed string.+ expect_prop(call->props, "NPU_COMPILATION_MODE_PARAMS", param.user_compile_params);+ }+ }+}++INSTANTIATE_TEST_SUITE_P(+ AllArchVariants,+ StageConfigUserOverrideTest,+ ::testing::Values(+ // NPU 2700: arch default sets no tiles; user overrides NPU_TILES with 1 and 2+ UserStageConfigParam{"2700", 2, 1, ""},+ UserStageConfigParam{"2700", 2, 2, ""},+ // NPU 4000: arch default is max_tiles=4 + optimization-level=3; user fully replaces compile params+ UserStageConfigParam{"4000", 4, 1, ""},+ UserStageConfigParam{"4000", 4, 2, "compute-layers-with-higher-precision=Sqrt,Power"},+ // NPU 5010: arch default is max_tiles=3; user overrides NPU_TILES and compile params+ UserStageConfigParam{"5010", 3, 1, ""},+ UserStageConfigParam{"5010", 3, 2, "compute-layers-with-higher-precision=Sqrt,Power"},+ // NPU 5020: arch default is max_tiles=3; user overrides NPU_TILES and compile params+ UserStageConfigParam{"5020", 3, 1, ""},+ UserStageConfigParam{"5020", 3, 2, "compute-layers-with-higher-precision=Sqrt,Power"},+ // AUTO_DETECT: arch default appends performance-hint-override=latency; user fully replaces+ UserStageConfigParam{"AUTO_DETECT", 4, 1, ""},+ UserStageConfigParam{"AUTO_DETECT", 4, 2, "compute-layers-with-higher-precision=Sqrt,Power"}),+ [](const ::testing::TestParamInfo<UserStageConfigParam>& info) {+ std::string name = info.param.arch;+ std::replace(name.begin(), name.end(), '_', 'x');+ name += "_tiles" + std::to_string(info.param.user_tiles);+ if (!info.param.user_compile_params.empty()) {+ name += "_with_compile_params";+ }+ return name;+ });++TEST_F(LLMCompiledModelFactoryOptionsTest, Arch2700SkipsNpuTilesInDefaultStageConfigs) {+ m_plugin = std::make_shared<ArchAwarePlugin>("2700", 2);+ const auto core = attach_mock_core_with_npu_device(m_plugin);++ RecordingFactory recorder;+ std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;++ ASSERT_NO_THROW(compiled = create_compiled_model(build_llm_model(), {{"NPUW_LLM_SHARED_HEAD", "YES"}}, recorder));+ ASSERT_NE(compiled, nullptr);++ const auto& prefill = require_call(recorder, "_prefill");+ const auto& generate = require_call_containing(recorder, "_kv");+ const auto& head = require_call(recorder, "_lm_head");++ for (const auto* call : {&prefill, &generate, &head}) {+ expect_missing_prop(call->props, "NPU_TILES");+ expect_prop(call->props,+ "NPU_COMPILATION_MODE_PARAMS",+ "compute-layers-with-higher-precision=Sqrt,Power,ReduceMean,Add_RMSNorm");+ }+}+// avtual config for one of platform with embargo details.+TEST_F(LLMCompiledModelFactoryOptionsTest, ArchAutoDetectSkipsNpuTilesInDefaultStageConfigs) {+ m_plugin = std::make_shared<ArchAwarePlugin>("AUTO_DETECT", 4);+ const auto core = attach_mock_core_with_npu_device(m_plugin);++ RecordingFactory recorder;+ std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;++ ASSERT_NO_THROW(compiled = create_compiled_model(build_llm_model(), {{"NPUW_LLM_SHARED_HEAD", "YES"}}, recorder));+ ASSERT_NE(compiled, nullptr);++ const auto& prefill = require_call(recorder, "_prefill");+ const auto& generate = require_call_containing(recorder, "_kv");+ const auto& head = require_call(recorder, "_lm_head");++ for (const auto* call : {&prefill, &generate, &head}) {+ expect_missing_prop(call->props, "NPU_TILES");+ expect_prop(call->props,+ "NPU_COMPILATION_MODE_PARAMS",+ "compute-layers-with-higher-precision=Sqrt,Power,ReduceMean,Add_RMSNorm performance-hint-override=latency");+ }+}++TEST_F(LLMCompiledModelFactoryOptionsTest, Arch4000AddsOptimizationLevelAndSetsNpuTiles) {+ m_plugin = std::make_shared<ArchAwarePlugin>("4000", 4);+ const auto core = attach_mock_core_with_npu_device(m_plugin);++ RecordingFactory recorder;+ std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;++ ASSERT_NO_THROW(compiled = create_compiled_model(build_llm_model(), {{"NPUW_LLM_SHARED_HEAD", "YES"}}, recorder));+ ASSERT_NE(compiled, nullptr);++ const auto& prefill = require_call(recorder, "_prefill");+ const auto& generate = require_call_containing(recorder, "_kv");+ const auto& head = require_call(recorder, "_lm_head");++ for (const auto* call : {&prefill, &generate, &head}) {+ EXPECT_EQ(prop_i64(call->props, "NPU_TILES"), 4);+ expect_prop(call->props,+ "NPU_COMPILATION_MODE_PARAMS",+ "compute-layers-with-higher-precision=Sqrt,Power,ReduceMean,Add_RMSNorm optimization-level=3");+ }+}++TEST_F(LLMCompiledModelFactoryOptionsTest, ArchAtLeast6000UsesDefaultConfig) {+ m_plugin = std::make_shared<ArchAwarePlugin>("7000", 8);+ const auto core = attach_mock_core_with_npu_device(m_plugin);++ RecordingFactory recorder;+ std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;++ ASSERT_NO_THROW(compiled = create_compiled_model(build_llm_model(), {{"NPUW_LLM_SHARED_HEAD", "YES"}}, recorder));+ ASSERT_NE(compiled, nullptr);++ const auto& prefill = require_call(recorder, "_prefill");+ const auto& generate = require_call_containing(recorder, "_kv");+ const auto& head = require_call(recorder, "_lm_head");++ for (const auto* call : {&prefill, &generate, &head}) {+ expect_missing_prop(call->props, "NPU_TILES");+ expect_prop(call->props,+ "NPU_COMPILATION_MODE_PARAMS",+ "compute-layers-with-higher-precision=Sqrt,Power,ReduceMean,Add_RMSNorm");+ }+}++TEST_F(LLMCompiledModelFactoryOptionsTest, FastCompileGenerateHintKeepsCurrentGenerateDefaults) {RecordingFactory recorder;std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;diff --git a/src/plugins/intel_npu/tests/unit/npuw/llm_test_helpers.hpp b/src/plugins/intel_npu/tests/unit/npuw/llm_test_helpers.hppindex 2c265682f42..36ba8bd61ce 100644--- a/src/plugins/intel_npu/tests/unit/npuw/llm_test_helpers.hpp+++ b/src/plugins/intel_npu/tests/unit/npuw/llm_test_helpers.hpp@@ -144,6 +144,7 @@ inline std::shared_ptr<ov::Model> build_moe_llm_test_model() {return mb.build_llm(cfg);}+class NullPlugin : public ov::IPlugin {public:std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>&,