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][NPU] Add NPUW caching properties (#30639)
Alexey Smirnov22c369175193
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/config/npuw.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/config/npuw.hppindex 0c5df075448..b0ed64b7877 100644--- a/src/plugins/intel_npu/src/al/include/intel_npu/config/npuw.hpp+++ b/src/plugins/intel_npu/src/al/include/intel_npu/config/npuw.hpp@@ -10,6 +10,35 @@#include "intel_npu/npu_private_properties.hpp"#include "intel_npu/npuw_private_properties.hpp"+namespace ov {+namespace npuw {+namespace s11n {+// FIXME: likely shouldn't be here as it was initially a part of npuw::s11n+// but we need to somehow serialize AnyMap right here for several properties.+enum class AnyType : int {+ STRING = 0,+ CHARS,+ INT,+ UINT32,+ INT64,+ UINT64,+ SIZET,+ FLOAT,+ BOOL,+ CACHE_MODE,+ ELEMENT_TYPE,+ ANYMAP,+ PERFMODE+};++std::string anyToString(const ov::Any& var);+ov::Any stringToAny(const std::string& var);+std::string anyMapToString(const ov::AnyMap& var);+ov::AnyMap stringToAnyMap(const std::string& var);+} // namespace s11n+} // namespace npuw+} // namespace ov+namespace intel_npu {//@@ -28,52 +57,52 @@ void registerNPUWLLMOptions(OptionsDesc& desc);static OptionMode mode() { return OptionMode::Mode; } \};-DEFINE_OPT(NPU_USE_NPUW, bool, false, use_npuw, CompileTime);-DEFINE_OPT(NPUW_DEVICES, std::string, "NPU,CPU", npuw::devices, CompileTime);-DEFINE_OPT(NPUW_SUBMODEL_DEVICE, std::string, "", npuw::submodel_device, CompileTime);-DEFINE_OPT(NPUW_ONLINE_PIPELINE, std::string, "REG", npuw::partitioning::online::pipeline, CompileTime);-DEFINE_OPT(NPUW_ONLINE_AVOID, std::string, "", npuw::partitioning::online::avoid, CompileTime);-DEFINE_OPT(NPUW_ONLINE_ISOLATE, std::string, "", npuw::partitioning::online::isolate, CompileTime);-DEFINE_OPT(NPUW_ONLINE_NO_FOLD, std::string, "", npuw::partitioning::online::nofold, CompileTime);-DEFINE_OPT(NPUW_ONLINE_MIN_SIZE, std::size_t, 10, npuw::partitioning::online::min_size, CompileTime);-DEFINE_OPT(NPUW_ONLINE_KEEP_BLOCKS, std::size_t, 5, npuw::partitioning::online::keep_blocks, CompileTime);-DEFINE_OPT(NPUW_ONLINE_KEEP_BLOCK_SIZE, std::size_t, 10, npuw::partitioning::online::keep_block_size, CompileTime);-DEFINE_OPT(NPUW_ONLINE_DUMP_PLAN, std::string, "", npuw::partitioning::online::dump_plan, CompileTime);-DEFINE_OPT(NPUW_PLAN, std::string, "", npuw::partitioning::plan, CompileTime);-DEFINE_OPT(NPUW_FOLD, bool, false, npuw::partitioning::fold, CompileTime);-DEFINE_OPT(NPUW_CWAI, bool, false, npuw::partitioning::cwai, CompileTime);-DEFINE_OPT(NPUW_DQ, bool, false, npuw::partitioning::dyn_quant, CompileTime);-DEFINE_OPT(NPUW_DQ_FULL, bool, true, npuw::partitioning::dyn_quant_full, CompileTime);-DEFINE_OPT(NPUW_PMM, std::string, "2", npuw::partitioning::par_matmul_merge_dims, CompileTime);-DEFINE_OPT(NPUW_SLICE_OUT, bool, false, npuw::partitioning::slice_out, CompileTime);-DEFINE_OPT(NPUW_HOST_GATHER, bool, true, npuw::partitioning::host_gather, CompileTime);-DEFINE_OPT(NPUW_SPATIAL, bool, false, npuw::partitioning::spatial, CompileTime);-DEFINE_OPT(NPUW_F16IC, bool, true, npuw::partitioning::f16_interconnect, CompileTime);-DEFINE_OPT(NPUW_SPATIAL_NWAY, std::size_t, 128, npuw::partitioning::spatial_nway, CompileTime);-DEFINE_OPT(NPUW_SPATIAL_DYN, bool, true, npuw::partitioning::spatial_dyn, CompileTime);-DEFINE_OPT(NPUW_DCOFF_TYPE, std::string, "", npuw::partitioning::dcoff_type, CompileTime);-DEFINE_OPT(NPUW_DCOFF_SCALE, bool, false, npuw::partitioning::dcoff_with_scale, CompileTime);-DEFINE_OPT(NPUW_FUNCALL_FOR_ALL, bool, false, npuw::partitioning::funcall_for_all, CompileTime);-DEFINE_OPT(NPUW_PARALLEL_COMPILE, bool, false, npuw::parallel_compilation, CompileTime);-DEFINE_OPT(NPUW_WEIGHTS_BANK, std::string, "", npuw::weights_bank, CompileTime);-DEFINE_OPT(NPUW_WEIGHTS_BANK_ALLOC, std::string, "", npuw::weights_bank_alloc, CompileTime);-DEFINE_OPT(NPUW_CACHE_DIR, std::string, "", npuw::cache_dir, CompileTime);+DEFINE_OPT(NPU_USE_NPUW, bool, false, use_npuw, RunTime);+DEFINE_OPT(NPUW_DEVICES, std::string, "NPU,CPU", npuw::devices, RunTime);+DEFINE_OPT(NPUW_SUBMODEL_DEVICE, std::string, "", npuw::submodel_device, RunTime);+DEFINE_OPT(NPUW_ONLINE_PIPELINE, std::string, "REG", npuw::partitioning::online::pipeline, RunTime);+DEFINE_OPT(NPUW_ONLINE_AVOID, std::string, "", npuw::partitioning::online::avoid, RunTime);+DEFINE_OPT(NPUW_ONLINE_ISOLATE, std::string, "", npuw::partitioning::online::isolate, RunTime);+DEFINE_OPT(NPUW_ONLINE_NO_FOLD, std::string, "", npuw::partitioning::online::nofold, RunTime);+DEFINE_OPT(NPUW_ONLINE_MIN_SIZE, std::size_t, 10, npuw::partitioning::online::min_size, RunTime);+DEFINE_OPT(NPUW_ONLINE_KEEP_BLOCKS, std::size_t, 5, npuw::partitioning::online::keep_blocks, RunTime);+DEFINE_OPT(NPUW_ONLINE_KEEP_BLOCK_SIZE, std::size_t, 10, npuw::partitioning::online::keep_block_size, RunTime);+DEFINE_OPT(NPUW_ONLINE_DUMP_PLAN, std::string, "", npuw::partitioning::online::dump_plan, RunTime);+DEFINE_OPT(NPUW_PLAN, std::string, "", npuw::partitioning::plan, RunTime);+DEFINE_OPT(NPUW_FOLD, bool, false, npuw::partitioning::fold, RunTime);+DEFINE_OPT(NPUW_CWAI, bool, false, npuw::partitioning::cwai, RunTime);+DEFINE_OPT(NPUW_DQ, bool, false, npuw::partitioning::dyn_quant, RunTime);+DEFINE_OPT(NPUW_DQ_FULL, bool, true, npuw::partitioning::dyn_quant_full, RunTime);+DEFINE_OPT(NPUW_PMM, std::string, "2", npuw::partitioning::par_matmul_merge_dims, RunTime);+DEFINE_OPT(NPUW_SLICE_OUT, bool, false, npuw::partitioning::slice_out, RunTime);+DEFINE_OPT(NPUW_HOST_GATHER, bool, true, npuw::partitioning::host_gather, RunTime);+DEFINE_OPT(NPUW_SPATIAL, bool, false, npuw::partitioning::spatial, RunTime);+DEFINE_OPT(NPUW_F16IC, bool, true, npuw::partitioning::f16_interconnect, RunTime);+DEFINE_OPT(NPUW_SPATIAL_NWAY, std::size_t, 128, npuw::partitioning::spatial_nway, RunTime);+DEFINE_OPT(NPUW_SPATIAL_DYN, bool, true, npuw::partitioning::spatial_dyn, RunTime);+DEFINE_OPT(NPUW_DCOFF_TYPE, std::string, "", npuw::partitioning::dcoff_type, RunTime);+DEFINE_OPT(NPUW_DCOFF_SCALE, bool, false, npuw::partitioning::dcoff_with_scale, RunTime);+DEFINE_OPT(NPUW_FUNCALL_FOR_ALL, bool, false, npuw::partitioning::funcall_for_all, RunTime);+DEFINE_OPT(NPUW_PARALLEL_COMPILE, bool, false, npuw::parallel_compilation, RunTime);+DEFINE_OPT(NPUW_WEIGHTS_BANK, std::string, "", npuw::weights_bank, RunTime);+DEFINE_OPT(NPUW_WEIGHTS_BANK_ALLOC, std::string, "", npuw::weights_bank_alloc, RunTime);+DEFINE_OPT(NPUW_CACHE_DIR, std::string, "", npuw::cache_dir, RunTime);DEFINE_OPT(NPUW_FUNCALL_ASYNC, bool, false, npuw::funcall_async, RunTime);DEFINE_OPT(NPUW_UNFOLD_IREQS, bool, false, npuw::unfold_ireqs, RunTime);DEFINE_OPT(NPUW_ACC_CHECK, bool, false, npuw::accuracy::check, RunTime);DEFINE_OPT(NPUW_ACC_THRESH, double, 0.01, npuw::accuracy::threshold, RunTime);DEFINE_OPT(NPUW_ACC_DEVICE, std::string, "", npuw::accuracy::reference_device, RunTime);-DEFINE_OPT(NPUW_DUMP_FULL, bool, false, npuw::dump::full, CompileTime);-DEFINE_OPT(NPUW_DUMP_SUBS, std::string, "", npuw::dump::subgraphs, CompileTime);-DEFINE_OPT(NPUW_DUMP_SUBS_ON_FAIL, std::string, "", npuw::dump::subgraphs_on_fail, CompileTime);+DEFINE_OPT(NPUW_DUMP_FULL, bool, false, npuw::dump::full, RunTime);+DEFINE_OPT(NPUW_DUMP_SUBS, std::string, "", npuw::dump::subgraphs, RunTime);+DEFINE_OPT(NPUW_DUMP_SUBS_ON_FAIL, std::string, "", npuw::dump::subgraphs_on_fail, RunTime);DEFINE_OPT(NPUW_DUMP_IO, std::string, "", npuw::dump::inputs_outputs, RunTime);DEFINE_OPT(NPUW_DUMP_IO_ITERS, bool, false, npuw::dump::io_iters, RunTime);-DEFINE_OPT(NPUW_LLM, bool, false, npuw::llm::enabled, CompileTime);-DEFINE_OPT(NPUW_LLM_BATCH_DIM, uint32_t, 0, npuw::llm::batch_dim, CompileTime);-DEFINE_OPT(NPUW_LLM_SEQ_LEN_DIM, uint32_t, 2, npuw::llm::seq_len_dim, CompileTime);-DEFINE_OPT(NPUW_LLM_MAX_PROMPT_LEN, uint32_t, 1024, npuw::llm::max_prompt_len, CompileTime);-DEFINE_OPT(NPUW_LLM_MIN_RESPONSE_LEN, uint32_t, 128, npuw::llm::min_response_len, CompileTime);-DEFINE_OPT(NPUW_LLM_OPTIMIZE_V_TENSORS, bool, true, npuw::llm::optimize_v_tensors, CompileTime);+DEFINE_OPT(NPUW_LLM, bool, false, npuw::llm::enabled, RunTime);+DEFINE_OPT(NPUW_LLM_BATCH_DIM, uint32_t, 0, npuw::llm::batch_dim, RunTime);+DEFINE_OPT(NPUW_LLM_SEQ_LEN_DIM, uint32_t, 2, npuw::llm::seq_len_dim, RunTime);+DEFINE_OPT(NPUW_LLM_MAX_PROMPT_LEN, uint32_t, 1024, npuw::llm::max_prompt_len, RunTime);+DEFINE_OPT(NPUW_LLM_MIN_RESPONSE_LEN, uint32_t, 128, npuw::llm::min_response_len, RunTime);+DEFINE_OPT(NPUW_LLM_OPTIMIZE_V_TENSORS, bool, true, npuw::llm::optimize_v_tensors, RunTime);namespace npuw {namespace llm {@@ -118,11 +147,11 @@ struct NPUW_LLM_PREFILL_HINT final : OptionBase<NPUW_LLM_PREFILL_HINT, ::intel_n}static OptionMode mode() {- return OptionMode::CompileTime;+ return OptionMode::RunTime;}static bool isPublic() {- return true;+ return false;}};@@ -170,11 +199,71 @@ struct NPUW_LLM_GENERATE_HINT final : OptionBase<NPUW_LLM_GENERATE_HINT, ::intel}static OptionMode mode() {- return OptionMode::CompileTime;+ return OptionMode::RunTime;+ }++ static bool isPublic() {+ return false;+ }+};++struct NPUW_LLM_PREFILL_CONFIG final : OptionBase<NPUW_LLM_PREFILL_CONFIG, ov::AnyMap> {+ static std::string_view key() {+ return ov::intel_npu::npuw::llm::prefill_config.name();+ }++ static constexpr std::string_view getTypeName() {+ return "::intel_npu::npuw::llm::prefill_config";+ }++ static ov::AnyMap defaultValue() {+ return {};+ }++ static ov::AnyMap parse(std::string_view val) {+ return ov::npuw::s11n::stringToAnyMap(std::string(val));+ }++ static std::string toString(const ov::AnyMap& val) {+ return ov::npuw::s11n::anyMapToString(val);+ }++ static OptionMode mode() {+ return OptionMode::RunTime;+ }++ static bool isPublic() {+ return false;+ }+};++struct NPUW_LLM_GENERATE_CONFIG final : OptionBase<NPUW_LLM_GENERATE_CONFIG, ov::AnyMap> {+ static std::string_view key() {+ return ov::intel_npu::npuw::llm::generate_config.name();+ }++ static constexpr std::string_view getTypeName() {+ return "::intel_npu::npuw::llm::generate_config";+ }++ static ov::AnyMap defaultValue() {+ return {};+ }++ static ov::AnyMap parse(std::string_view val) {+ return ov::npuw::s11n::stringToAnyMap(std::string(val));+ }++ static std::string toString(const ov::AnyMap& val) {+ return ov::npuw::s11n::anyMapToString(val);+ }++ static OptionMode mode() {+ return OptionMode::RunTime;}static bool isPublic() {- return true;+ return false;}};} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/al/src/config/npuw.cpp b/src/plugins/intel_npu/src/al/src/config/npuw.cppindex 3834beeead3..76a28acc801 100644--- a/src/plugins/intel_npu/src/al/src/config/npuw.cpp+++ b/src/plugins/intel_npu/src/al/src/config/npuw.cpp@@ -66,3 +66,167 @@ void intel_npu::registerNPUWLLMOptions(OptionsDesc& desc) {desc.add<NPUW_LLM_PREFILL_HINT>();desc.add<NPUW_LLM_GENERATE_HINT>();}++std::string ov::npuw::s11n::anyToString(const ov::Any& var) {+#define HNDL(anyt, t) \+ auto type = static_cast<int>(AnyType::anyt); \+ stream.write(reinterpret_cast<const char*>(&type), sizeof type); \+ auto var_as = var.as<t>(); \+ stream.write(reinterpret_cast<const char*>(&var_as), sizeof var_as);++ std::stringstream stream;+ // FIXME: figure out a proper way to serialize Any (for config)+ if (var.is<std::string>()) {+ auto type = static_cast<int>(AnyType::STRING);+ stream.write(reinterpret_cast<const char*>(&type), sizeof type);+ auto str = var.as<std::string>();+ auto var_size = str.size();+ stream.write(reinterpret_cast<const char*>(&var_size), sizeof var_size);+ stream.write(&str[0], str.size());+ } else if (var.is<const char*>()) {+ // FIXME: handle properly+ auto type = static_cast<int>(AnyType::CHARS);+ stream.write(reinterpret_cast<const char*>(&type), sizeof type);+ auto str = std::string(var.as<const char*>());+ auto var_size = str.size();+ stream.write(reinterpret_cast<const char*>(&var_size), sizeof var_size);+ stream.write(&str[0], str.size());+ } else if (var.is<std::size_t>()) {+ HNDL(SIZET, std::size_t)+ } else if (var.is<int>()) {+ HNDL(INT, int)+ } else if (var.is<int64_t>()) {+ HNDL(INT64, int64_t)+ } else if (var.is<uint32_t>()) {+ HNDL(UINT32, uint32_t)+ } else if (var.is<uint64_t>()) {+ HNDL(UINT64, uint64_t)+ } else if (var.is<float>()) {+ HNDL(FLOAT, float)+ } else if (var.is<bool>()) {+ HNDL(BOOL, bool)+ } else if (var.is<ov::CacheMode>()) {+ HNDL(CACHE_MODE, ov::CacheMode)+ } else if (var.is<ov::element::Type>()) {+ HNDL(ELEMENT_TYPE, ov::element::Type)+ } else if (var.is<ov::AnyMap>()) {+ auto any_map = var.as<ov::AnyMap>();+ auto str = ov::npuw::s11n::anyMapToString(any_map);+ auto type = static_cast<int>(AnyType::ANYMAP);+ stream.write(reinterpret_cast<const char*>(&type), sizeof type);+ auto var_size = str.size();+ stream.write(reinterpret_cast<const char*>(&var_size), sizeof var_size);+ stream.write(&str[0], str.size());+ } else if (var.is<ov::hint::PerformanceMode>()) {+ HNDL(PERFMODE, ov::hint::PerformanceMode)+ } else {+ OPENVINO_THROW("Unsupported type of ov::Any to convert to string!");+ }+#undef HNDL+ return stream.str();+}++ov::Any ov::npuw::s11n::stringToAny(const std::string& var) {+ std::stringstream stream(var);+ int type_int;+ stream.read(reinterpret_cast<char*>(&type_int), sizeof type_int);+ AnyType type = static_cast<AnyType>(type_int);++#define HNDL(t) \+ t val; \+ stream.read(reinterpret_cast<char*>(&val), sizeof val); \+ return ov::Any(val);++ if (type == AnyType::STRING) {+ std::string val;+ std::size_t size = 0;+ stream.read(reinterpret_cast<char*>(&size), sizeof size);+ val.resize(size);+ stream.read(&val[0], size);+ return ov::Any(val);+ } else if (type == AnyType::CHARS) {+ // FIXME: handle properly+ std::string val;+ std::size_t size = 0;+ stream.read(reinterpret_cast<char*>(&size), sizeof size);+ val.resize(size);+ stream.read(&val[0], size);+ return ov::Any(val);+ } else if (type == AnyType::SIZET) {+ HNDL(std::size_t)+ } else if (type == AnyType::INT) {+ HNDL(int)+ } else if (type == AnyType::INT64) {+ HNDL(int64_t)+ } else if (type == AnyType::UINT32) {+ HNDL(uint32_t)+ } else if (type == AnyType::UINT64) {+ HNDL(uint64_t)+ } else if (type == AnyType::FLOAT) {+ HNDL(float)+ } else if (type == AnyType::BOOL) {+ HNDL(bool)+ } else if (type == AnyType::CACHE_MODE) {+ HNDL(ov::CacheMode)+ } else if (type == AnyType::ELEMENT_TYPE) {+ HNDL(ov::element::Type)+ } else if (type == AnyType::ANYMAP) {+ std::string val;+ std::size_t size = 0;+ stream.read(reinterpret_cast<char*>(&size), sizeof size);+ val.resize(size);+ stream.read(&val[0], size);+ return ov::Any(ov::npuw::s11n::stringToAnyMap(val));+ } else if (type == AnyType::PERFMODE) {+ HNDL(ov::hint::PerformanceMode)+ } else {+ OPENVINO_THROW("Unsupported type of ov::Any to convert from string!");+ }+#undef HNDL+ return {};+}++std::string ov::npuw::s11n::anyMapToString(const ov::AnyMap& var) {+ std::stringstream stream;+ auto map_size = var.size();+ stream.write(reinterpret_cast<const char*>(&map_size), sizeof map_size);+ for (const auto& el : var) {+ // key+ auto str = el.first;+ auto var_size = str.size();+ stream.write(reinterpret_cast<const char*>(&var_size), sizeof var_size);+ stream.write(&str[0], str.size());+ // value+ auto any = el.second;+ auto strv = ov::npuw::s11n::anyToString(any);+ auto varv_size = strv.size();+ stream.write(reinterpret_cast<const char*>(&varv_size), sizeof varv_size);+ stream.write(&strv[0], strv.size());+ }+ return stream.str();+}++ov::AnyMap ov::npuw::s11n::stringToAnyMap(const std::string& var) {+ std::stringstream stream(var);+ ov::AnyMap res;+ std::size_t size = 0;+ stream.read(reinterpret_cast<char*>(&size), sizeof size);+ for (std::size_t i = 0; i < size; ++i) {+ // key+ std::size_t ksize = 0;+ stream.read(reinterpret_cast<char*>(&ksize), sizeof ksize);+ std::string kval;+ kval.resize(ksize);+ stream.read(&kval[0], ksize);+ // value+ std::size_t vsize = 0;+ stream.read(reinterpret_cast<char*>(&vsize), sizeof vsize);+ std::string vval;+ vval.resize(vsize);+ stream.read(&vval[0], vsize);++ auto any_val = ov::npuw::s11n::stringToAny(vval);+ res[kval] = any_val;+ }+ return res;+}diff --git a/src/plugins/intel_npu/src/common/src/filtered_config.cpp b/src/plugins/intel_npu/src/common/src/filtered_config.cppindex 285e72f111d..8ab2b04484a 100644--- a/src/plugins/intel_npu/src/common/src/filtered_config.cpp+++ b/src/plugins/intel_npu/src/common/src/filtered_config.cpp@@ -40,6 +40,11 @@ void FilteredConfig::update(const ConfigMap& options, OptionMode mode) {}bool FilteredConfig::isAvailable(std::string key) const {+ // NPUW properties are requested by OV Core during caching and have no effect on the NPU plugin. But we still need+ // to enable those for OV Core to query.+ if (key.find("NPUW") != key.npos) {+ return true; // always available+ }auto it = _enabled.find(key);if (it != _enabled.end() && hasOpt(key)) {return it->second;diff --git a/src/plugins/intel_npu/src/plugin/include/properties.hpp b/src/plugins/intel_npu/src/plugin/include/properties.hppindex 71be2ba08b7..4b1acdd032b 100644--- a/src/plugins/intel_npu/src/plugin/include/properties.hpp+++ b/src/plugins/intel_npu/src/plugin/include/properties.hpp@@ -5,6 +5,7 @@#pragma once#include "intel_npu/common/filtered_config.hpp"+#include "intel_npu/npuw_private_properties.hpp"#include "metrics.hpp"namespace intel_npu {@@ -65,16 +66,57 @@ private:void registerPluginProperties();void registerCompiledModelProperties();- const std::vector<ov::PropertyName> _cachingProperties = {ov::device::architecture.name(),- ov::intel_npu::compilation_mode_params.name(),- ov::intel_npu::compiler_dynamic_quantization.name(),- ov::intel_npu::tiles.name(),- ov::intel_npu::dma_engines.name(),- ov::intel_npu::compilation_mode.name(),- ov::intel_npu::driver_version.name(),- ov::intel_npu::compiler_type.name(),- ov::intel_npu::batch_mode.name(),- ov::hint::execution_mode.name()};+ const std::vector<ov::PropertyName> _cachingProperties = {+ ov::device::architecture.name(),+ ov::intel_npu::compilation_mode_params.name(),+ ov::intel_npu::compiler_dynamic_quantization.name(),+ ov::intel_npu::tiles.name(),+ ov::intel_npu::dma_engines.name(),+ ov::intel_npu::compilation_mode.name(),+ ov::intel_npu::driver_version.name(),+ ov::intel_npu::compiler_type.name(),+ ov::intel_npu::batch_mode.name(),+ ov::hint::execution_mode.name(),+ // NPUW caching properties+ ov::cache_mode.name(),+ ov::intel_npu::use_npuw.name(),+ ov::intel_npu::npuw::devices.name(),+ ov::intel_npu::npuw::submodel_device.name(),+ ov::intel_npu::npuw::weights_bank.name(),+ ov::intel_npu::npuw::weights_bank_alloc.name(),+ ov::intel_npu::npuw::partitioning::online::pipeline.name(),+ ov::intel_npu::npuw::partitioning::online::avoid.name(),+ ov::intel_npu::npuw::partitioning::online::isolate.name(),+ ov::intel_npu::npuw::partitioning::online::nofold.name(),+ ov::intel_npu::npuw::partitioning::online::min_size.name(),+ ov::intel_npu::npuw::partitioning::online::keep_blocks.name(),+ ov::intel_npu::npuw::partitioning::online::keep_block_size.name(),+ ov::intel_npu::npuw::partitioning::fold.name(),+ ov::intel_npu::npuw::partitioning::cwai.name(),+ ov::intel_npu::npuw::partitioning::dyn_quant.name(),+ ov::intel_npu::npuw::partitioning::dyn_quant_full.name(),+ ov::intel_npu::npuw::partitioning::par_matmul_merge_dims.name(),+ ov::intel_npu::npuw::partitioning::slice_out.name(),+ ov::intel_npu::npuw::partitioning::spatial.name(),+ ov::intel_npu::npuw::partitioning::spatial_nway.name(),+ ov::intel_npu::npuw::partitioning::spatial_dyn.name(),+ ov::intel_npu::npuw::partitioning::f16_interconnect.name(),+ ov::intel_npu::npuw::partitioning::host_gather.name(),+ ov::intel_npu::npuw::partitioning::dcoff_type.name(),+ ov::intel_npu::npuw::partitioning::dcoff_with_scale.name(),+ ov::intel_npu::npuw::partitioning::funcall_for_all.name(),+ ov::intel_npu::npuw::funcall_async.name(),+ ov::intel_npu::npuw::unfold_ireqs.name(),+ ov::intel_npu::npuw::llm::enabled.name(),+ ov::intel_npu::npuw::llm::batch_dim.name(),+ ov::intel_npu::npuw::llm::seq_len_dim.name(),+ ov::intel_npu::npuw::llm::max_prompt_len.name(),+ ov::intel_npu::npuw::llm::min_response_len.name(),+ ov::intel_npu::npuw::llm::optimize_v_tensors.name(),+ ov::intel_npu::npuw::llm::prefill_hint.name(),+ ov::intel_npu::npuw::llm::prefill_config.name(),+ ov::intel_npu::npuw::llm::generate_hint.name(),+ ov::intel_npu::npuw::llm::generate_config.name()};const std::vector<ov::PropertyName> _internalSupportedProperties = {ov::internal::caching_properties.name(),ov::internal::caching_with_mmap.name()};diff --git a/src/plugins/intel_npu/src/plugin/npuw/serialization.cpp b/src/plugins/intel_npu/src/plugin/npuw/serialization.cppindex 693685b4fc1..d1b4a6d2090 100644--- a/src/plugins/intel_npu/src/plugin/npuw/serialization.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/serialization.cpp@@ -5,6 +5,7 @@#include "serialization.hpp"#include "intel_npu/config/config.hpp"+#include "intel_npu/config/npuw.hpp"#include "lazy_tensor.hpp"#include "logging.hpp"#include "openvino/core/rt_info/weightless_caching_attributes.hpp"@@ -124,67 +125,9 @@ void ov::npuw::s11n::write(std::ostream& stream, const ov::Output<const ov::Nodewrite(stream, var.get_names());}-enum class AnyType : int {- STRING = 0,- CHARS,- INT,- UINT32,- INT64,- UINT64,- SIZET,- FLOAT,- BOOL,- CACHE_MODE,- ELEMENT_TYPE,- ANYMAP,- PERFMODE-};-void ov::npuw::s11n::write_any(std::ostream& stream, const ov::Any& var) {- // FIXME: figure out a proper way to serialize Any (for config)- if (var.is<std::string>()) {- write(stream, static_cast<int>(AnyType::STRING));- write(stream, var.as<std::string>());- } else if (var.is<const char*>()) {- // FIXME: handle properly- write(stream, static_cast<int>(AnyType::CHARS));- write(stream, std::string(var.as<const char*>()));- } else if (var.is<std::size_t>()) {- write(stream, static_cast<int>(AnyType::SIZET));- write(stream, var.as<std::size_t>());- } else if (var.is<int>()) {- write(stream, static_cast<int>(AnyType::INT));- write(stream, var.as<int>());- } else if (var.is<int64_t>()) {- write(stream, static_cast<int>(AnyType::INT64));- write(stream, var.as<int64_t>());- } else if (var.is<uint32_t>()) {- write(stream, static_cast<int>(AnyType::UINT32));- write(stream, var.as<uint32_t>());- } else if (var.is<uint64_t>()) {- write(stream, static_cast<int>(AnyType::UINT64));- write(stream, var.as<uint64_t>());- } else if (var.is<float>()) {- write(stream, static_cast<int>(AnyType::FLOAT));- write(stream, var.as<float>());- } else if (var.is<bool>()) {- write(stream, static_cast<int>(AnyType::BOOL));- write(stream, var.as<bool>());- } else if (var.is<ov::CacheMode>()) {- write(stream, static_cast<int>(AnyType::CACHE_MODE));- write(stream, var.as<ov::CacheMode>());- } else if (var.is<ov::element::Type>()) {- write(stream, static_cast<int>(AnyType::ELEMENT_TYPE));- write(stream, var.as<ov::element::Type>());- } else if (var.is<ov::AnyMap>()) {- write(stream, static_cast<int>(AnyType::ANYMAP));- write(stream, var.as<ov::AnyMap>());- } else if (var.is<ov::hint::PerformanceMode>()) {- write(stream, static_cast<int>(AnyType::PERFMODE));- write(stream, var.as<ov::hint::PerformanceMode>());- } else {- NPUW_ASSERT(false && "Unsupported type");- }+ auto str = ov::npuw::s11n::anyToString(var);+ write(stream, str);}void ov::npuw::s11n::write(std::ostream& stream, const ov::npuw::weights::LazyTensor& var) {@@ -204,11 +147,8 @@ void ov::npuw::s11n::write(std::ostream& stream, const ov::hint::PerformanceMode}void ov::npuw::s11n::write(std::ostream& stream, const ov::AnyMap& var) {- write(stream, var.size());- for (const auto& el : var) {- write(stream, el.first);- write_any(stream, el.second);- }+ auto str = ov::npuw::s11n::anyMapToString(var);+ write(stream, str);}void ov::npuw::s11n::read(std::istream& stream, std::streampos& var) {@@ -311,66 +251,9 @@ void ov::npuw::s11n::read(std::istream& stream, std::shared_ptr<ov::Node>& var)}void ov::npuw::s11n::read_any(std::istream& stream, ov::Any& var) {- // FIXME: ugly, but cannot use .read(stream) here due to its usage of operator>>()- int type_int;- read(stream, type_int);- AnyType type = static_cast<AnyType>(type_int);- if (type == AnyType::STRING) {- std::string val;- read(stream, val);- var = std::move(val);- } else if (type == AnyType::CHARS) {- // FIXME: handle properly- std::string val;- read(stream, val);- var = std::move(val);- } else if (type == AnyType::SIZET) {- std::size_t val;- read(stream, val);- var = val;- } else if (type == AnyType::INT) {- int val;- read(stream, val);- var = val;- } else if (type == AnyType::INT64) {- int64_t val;- read(stream, val);- var = val;- } else if (type == AnyType::UINT32) {- uint32_t val;- read(stream, val);- var = val;- } else if (type == AnyType::UINT64) {- uint64_t val;- read(stream, val);- var = val;- } else if (type == AnyType::FLOAT) {- float val;- read(stream, val);- var = val;- } else if (type == AnyType::BOOL) {- bool val;- read(stream, val);- var = val;- } else if (type == AnyType::CACHE_MODE) {- ov::CacheMode val;- read(stream, val);- var = val;- } else if (type == AnyType::ELEMENT_TYPE) {- ov::element::Type val;- read(stream, val);- var = val;- } else if (type == AnyType::ANYMAP) {- ov::AnyMap val;- read(stream, val);- var = val;- } else if (type == AnyType::PERFMODE) {- ov::hint::PerformanceMode val;- read(stream, val);- var = val;- } else {- NPUW_ASSERT(false && "Unsupported type");- }+ std::string str;+ read(stream, str);+ var = ov::npuw::s11n::stringToAny(str);}void ov::npuw::s11n::read(std::istream& stream, ov::npuw::weights::LazyTensor& var) {@@ -390,15 +273,9 @@ void ov::npuw::s11n::read(std::istream& stream, ov::hint::PerformanceMode& var)}void ov::npuw::s11n::read(std::istream& stream, ov::AnyMap& var) {- std::size_t var_size = 0;- read(stream, var_size);- for (std::size_t i = 0; i < var_size; ++i) {- std::string k;- read(stream, k);- ov::Any v;- read_any(stream, v);- var[k] = v;- }+ std::string str;+ read(stream, str);+ var = ov::npuw::s11n::stringToAnyMap(str);}// Weightlessdiff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cppindex e909a82b984..b91ec35bb3b 100644--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp@@ -228,6 +228,48 @@ void Plugin::init_options() {// filter out unsupported optionsfilter_config_by_compiler_support(_globalConfig);++ // NPUW properties are requested by OV Core during caching and have no effect on the NPU plugin. But we still need to enable those for OV Core to query.+ // Note: do this last to not filter them out.+ // register npuw caching properties+ REGISTER_OPTION(NPU_USE_NPUW);+ REGISTER_OPTION(NPUW_DEVICES);+ REGISTER_OPTION(NPUW_SUBMODEL_DEVICE);+ REGISTER_OPTION(NPUW_WEIGHTS_BANK);+ REGISTER_OPTION(NPUW_WEIGHTS_BANK_ALLOC);+ REGISTER_OPTION(NPUW_ONLINE_PIPELINE);+ REGISTER_OPTION(NPUW_ONLINE_AVOID);+ REGISTER_OPTION(NPUW_ONLINE_ISOLATE);+ REGISTER_OPTION(NPUW_ONLINE_NO_FOLD);+ REGISTER_OPTION(NPUW_ONLINE_MIN_SIZE);+ REGISTER_OPTION(NPUW_ONLINE_KEEP_BLOCKS);+ REGISTER_OPTION(NPUW_ONLINE_KEEP_BLOCK_SIZE);+ REGISTER_OPTION(NPUW_FOLD);+ REGISTER_OPTION(NPUW_CWAI);+ REGISTER_OPTION(NPUW_DQ);+ REGISTER_OPTION(NPUW_DQ_FULL);+ REGISTER_OPTION(NPUW_PMM);+ REGISTER_OPTION(NPUW_SLICE_OUT);+ REGISTER_OPTION(NPUW_SPATIAL);+ REGISTER_OPTION(NPUW_SPATIAL_NWAY);+ REGISTER_OPTION(NPUW_SPATIAL_DYN);+ REGISTER_OPTION(NPUW_F16IC);+ REGISTER_OPTION(NPUW_HOST_GATHER);+ REGISTER_OPTION(NPUW_DCOFF_TYPE);+ REGISTER_OPTION(NPUW_DCOFF_SCALE);+ REGISTER_OPTION(NPUW_FUNCALL_FOR_ALL);+ REGISTER_OPTION(NPUW_FUNCALL_ASYNC);+ REGISTER_OPTION(NPUW_UNFOLD_IREQS);+ REGISTER_OPTION(NPUW_LLM);+ REGISTER_OPTION(NPUW_LLM_BATCH_DIM);+ REGISTER_OPTION(NPUW_LLM_SEQ_LEN_DIM);+ REGISTER_OPTION(NPUW_LLM_MAX_PROMPT_LEN);+ REGISTER_OPTION(NPUW_LLM_MIN_RESPONSE_LEN);+ REGISTER_OPTION(NPUW_LLM_OPTIMIZE_V_TENSORS);+ REGISTER_OPTION(NPUW_LLM_PREFILL_HINT);+ REGISTER_OPTION(NPUW_LLM_PREFILL_CONFIG);+ REGISTER_OPTION(NPUW_LLM_GENERATE_HINT);+ REGISTER_OPTION(NPUW_LLM_GENERATE_CONFIG);}void Plugin::filter_config_by_compiler_support(FilteredConfig& cfg) const {diff --git a/src/plugins/intel_npu/src/plugin/src/properties.cpp b/src/plugins/intel_npu/src/plugin/src/properties.cppindex 5da92d7fb59..978abba4f33 100644--- a/src/plugins/intel_npu/src/plugin/src/properties.cpp+++ b/src/plugins/intel_npu/src/plugin/src/properties.cpp@@ -7,6 +7,7 @@#include "compiler_adapter_factory.hpp"#include "intel_npu/common/device_helpers.hpp"+#include "intel_npu/config/npuw.hpp"#include "intel_npu/config/options.hpp"namespace intel_npu {@@ -404,6 +405,48 @@ void Properties::registerPluginProperties() {}());TRY_REGISTER_SIMPLE_PROPERTY(ov::hint::enable_cpu_pinning, ENABLE_CPU_PINNING);+ // NPUW properties are requested by OV Core during caching and have no effect on the NPU plugin. But we still need+ // to enable those for OV Core to query.+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::use_npuw, NPU_USE_NPUW);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::devices, NPUW_DEVICES);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::submodel_device, NPUW_SUBMODEL_DEVICE);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::weights_bank, NPUW_WEIGHTS_BANK);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::weights_bank_alloc, NPUW_WEIGHTS_BANK_ALLOC);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::online::pipeline, NPUW_ONLINE_PIPELINE);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::online::avoid, NPUW_ONLINE_AVOID);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::online::isolate, NPUW_ONLINE_ISOLATE);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::online::nofold, NPUW_ONLINE_NO_FOLD);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::online::min_size, NPUW_ONLINE_MIN_SIZE);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::online::keep_blocks, NPUW_ONLINE_KEEP_BLOCKS);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::online::keep_block_size,+ NPUW_ONLINE_KEEP_BLOCK_SIZE);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::fold, NPUW_FOLD);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::cwai, NPUW_CWAI);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::dyn_quant, NPUW_DQ);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::dyn_quant_full, NPUW_DQ_FULL);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::par_matmul_merge_dims, NPUW_PMM);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::slice_out, NPUW_SLICE_OUT);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::spatial, NPUW_SPATIAL);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::spatial_nway, NPUW_SPATIAL_NWAY);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::spatial_dyn, NPUW_SPATIAL_DYN);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::f16_interconnect, NPUW_F16IC);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::host_gather, NPUW_HOST_GATHER);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::dcoff_type, NPUW_DCOFF_TYPE);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::dcoff_with_scale, NPUW_DCOFF_SCALE);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::partitioning::funcall_for_all, NPUW_FUNCALL_FOR_ALL);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::funcall_async, NPUW_FUNCALL_ASYNC);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::unfold_ireqs, NPUW_UNFOLD_IREQS);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::llm::enabled, NPUW_LLM);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::llm::batch_dim, NPUW_LLM_BATCH_DIM);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::llm::seq_len_dim, NPUW_LLM_SEQ_LEN_DIM);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::llm::max_prompt_len, NPUW_LLM_MAX_PROMPT_LEN);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::llm::min_response_len, NPUW_LLM_MIN_RESPONSE_LEN);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::llm::optimize_v_tensors, NPUW_LLM_OPTIMIZE_V_TENSORS);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::llm::prefill_hint, NPUW_LLM_PREFILL_HINT);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::llm::prefill_config, NPUW_LLM_PREFILL_CONFIG);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::llm::generate_hint, NPUW_LLM_GENERATE_HINT);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::llm::generate_config, NPUW_LLM_GENERATE_CONFIG);+// 2. Metrics (static device and enviroment properties)// ========// REGISTER_SIMPLE_METRIC format: (property, public true/false, return value)@@ -480,6 +523,13 @@ void Properties::registerPluginProperties() {caching_props.emplace_back(prop);}}+ // NPUW properties are requested by OV Core during caching and have no effect on the NPU plugin. But we+ // still need to enable those for OV Core to query. add all NPUW properties+ for (auto prop : _cachingProperties) {+ if (prop.find("NPUW") != prop.npos) {+ caching_props.emplace_back(prop);+ }+ }return caching_props;});}