Skip to content

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

[NPUW] Fix import issue for non NPUW_LLM models (#34794)

Anastasiya(Asya) Pronina5be054d5f7d6
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 d009c0da7a5..ff5910c5260 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
@@ -59,6 +59,33 @@ std::map<std::string, std::string> any_copy(const ov::AnyMap& params) {
}
return result;
}
+
+bool can_use_weightless_flow(const ::intel_npu::Config& config) {
+ return config.get<::intel_npu::NPUW_FOLD>() || config.get<::intel_npu::NPUW_CWAI>();
+}
+
+bool should_use_weightless_flow(const ov::AnyMap& non_npuw_props,
+ const ::intel_npu::Config& config,
+ const std::unordered_map<const void*, std::size_t>& const_to_offset) {
+ if (!can_use_weightless_flow(config)) {
+ return false;
+ }
+
+ bool is_weightless = true;
+ if (auto it = non_npuw_props.find(ov::enable_weightless.name()); it != non_npuw_props.end()) {
+ is_weightless = it->second.as<bool>();
+ } else if (auto it = non_npuw_props.find(ov::cache_mode.name());
+ it != non_npuw_props.end() && it->second.as<ov::CacheMode>() == ov::CacheMode::OPTIMIZE_SPEED) {
+ is_weightless = false;
+ }
+
+ // Weightless serialization is only valid when WAI metadata was generated.
+ if (is_weightless && const_to_offset.empty()) {
+ is_weightless = false;
+ }
+
+ return is_weightless;
+}
} // anonymous namespace
namespace ov {
@@ -1020,15 +1047,9 @@ void ov::npuw::CompiledModel::export_model(std::ostream& stream) const {
}
// Identify either full flow or weightless
- bool is_weightless = true;
- if (auto it = m_non_npuw_props.find(ov::enable_weightless.name()); it != m_non_npuw_props.end()) {
- if (!it->second.as<bool>()) {
- is_weightless = false;
- }
- } else if (auto it = m_non_npuw_props.find(ov::cache_mode.name());
- it != m_non_npuw_props.end() && it->second.as<CacheMode>() == CacheMode::OPTIMIZE_SPEED) {
+ bool is_weightless = should_use_weightless_flow(m_non_npuw_props, m_cfg, m_const_to_offset);
+ if (!is_weightless) {
LOG_INFO("Serialization will be done via flow with weights.");
- is_weightless = false;
}
// Write header regardless of encryption requirement - to identify NPUW serializated blobs
@@ -1228,15 +1249,7 @@ void ov::npuw::CompiledModel::serialize(std::ostream& stream, const ov::npuw::s1
}
// Write flow identifier
- bool is_weightless = true;
- if (auto it = m_non_npuw_props.find(ov::enable_weightless.name()); it != m_non_npuw_props.end()) {
- if (!it->second.as<bool>()) {
- is_weightless = false;
- }
- } else if (m_non_npuw_props.count(ov::cache_mode.name()) &&
- m_non_npuw_props.at(ov::cache_mode.name()).as<CacheMode>() == CacheMode::OPTIMIZE_SPEED) {
- is_weightless = false;
- }
+ bool is_weightless = should_use_weightless_flow(m_non_npuw_props, m_cfg, m_const_to_offset);
write(model_stream, is_weightless);
// Write bf16 consts cache
diff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/models/model_builder.cpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/models/model_builder.cpp
index 088fd3e2893..ccd9ab15b68 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/models/model_builder.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/models/model_builder.cpp
@@ -14,11 +14,27 @@
#include "openvino/op/util/variable.hpp"
#include "openvino/openvino.hpp"
#include "openvino/opsets/opset11.hpp"
+#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
namespace ov {
namespace test {
namespace npuw {
+namespace {
+void annotate_constants_with_weightless_cache(const std::shared_ptr<ov::Model>& model) {
+ std::size_t offset = 0;
+ for (const auto& node : model->get_ordered_ops()) {
+ if (!ov::op::util::is_constant(node)) {
+ continue;
+ }
+ const auto& c = std::static_pointer_cast<ov::op::v0::Constant>(node);
+ c->get_rt_info()[ov::WeightlessCacheAttribute::get_type_info_static()] =
+ ov::WeightlessCacheAttribute(c->get_byte_size(), offset, c->get_element_type());
+ offset += c->get_byte_size();
+ }
+}
+} // namespace
+
// Named constants for magic values used throughout model construction.
constexpr float kRoPEBaseFrequency = 10000.0f;
constexpr float kAttentionMaskPadding = -10000.0f;
@@ -1030,6 +1046,16 @@ std::shared_ptr<ov::Model> ModelBuilder::get_model_with_repeated_blocks() {
return get_model_with_repeated_blocks(10);
}
+std::shared_ptr<ov::Model> ModelBuilder::get_model_with_repeated_blocks_with_weightless_cache(std::size_t repetitions) {
+ auto model = get_model_with_repeated_blocks(repetitions);
+ annotate_constants_with_weightless_cache(model);
+ return model;
+}
+
+std::shared_ptr<ov::Model> ModelBuilder::get_model_with_repeated_blocks_with_weightless_cache() {
+ return get_model_with_repeated_blocks_with_weightless_cache(10);
+}
+
std::shared_ptr<ov::Model> ModelBuilder::get_model_with_repeated_blocks_and_results(
std::size_t repetitions,
const std::vector<std::size_t>& block_indices) {
diff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/models/model_builder.hpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/models/model_builder.hpp
index 75562611324..fea8c31777e 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/models/model_builder.hpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/test_engine/models/model_builder.hpp
@@ -435,6 +435,8 @@ public:
std::shared_ptr<ov::Model> get_model_without_repeated_blocks();
std::shared_ptr<ov::Model> get_model_with_repeated_blocks(std::size_t repetitions);
std::shared_ptr<ov::Model> get_model_with_repeated_blocks();
+ std::shared_ptr<ov::Model> get_model_with_repeated_blocks_with_weightless_cache(std::size_t repetitions);
+ std::shared_ptr<ov::Model> get_model_with_repeated_blocks_with_weightless_cache();
std::shared_ptr<ov::Model> get_model_with_repeated_blocks_and_results(
std::size_t repetitions,
const std::vector<std::size_t>& block_indices);
diff --git a/src/plugins/intel_npu/tests/unit/npuw/import_non_llm_blob.cpp b/src/plugins/intel_npu/tests/unit/npuw/import_non_llm_blob.cpp
new file mode 100644
index 00000000000..e0bbd93a9cb
--- /dev/null
+++ b/src/plugins/intel_npu/tests/unit/npuw/import_non_llm_blob.cpp
@@ -0,0 +1,116 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "compiled_model.hpp"
+#include "intel_npu/config/config.hpp"
+#include "intel_npu/config/npuw.hpp"
+#include "model_builder.hpp"
+#include "openvino/openvino.hpp"
+
+using ov::test::npuw::ModelBuilder;
+
+class ImportNonLLMBlobTestNPUW : public ::testing::TestWithParam<ov::AnyMap> {
+public:
+ void SetUp() override {
+ ModelBuilder mb;
+ m_ov_model = mb.get_model_with_repeated_blocks_with_weightless_cache();
+ m_props = {{"NPU_USE_NPUW", "YES"}, {"NPUW_DEVICES", "CPU"}};
+ }
+
+protected:
+ ModelBuilder model_builder;
+ std::shared_ptr<ov::Model> m_ov_model;
+ ov::AnyMap m_props;
+ ov::Core m_core;
+};
+
+TEST_P(ImportNonLLMBlobTestNPUW, CacheModeOptimizeSpeed) {
+ ov::AnyMap wai_props = GetParam();
+ m_props.insert(wai_props.begin(), wai_props.end());
+ m_props["CACHE_MODE"] = "OPTIMIZE_SPEED";
+
+ auto compiled = m_core.compile_model(m_ov_model, "NPU", m_props);
+
+ std::stringstream blob;
+ compiled.export_model(blob);
+
+ EXPECT_NO_THROW({
+ auto imported = m_core.import_model(blob, "NPU", m_props);
+ imported.create_infer_request();
+ });
+}
+
+TEST_P(ImportNonLLMBlobTestNPUW, CacheModeOptimizeSizeWithModelPtr) {
+ ov::AnyMap wai_props = GetParam();
+ m_props.insert(wai_props.begin(), wai_props.end());
+ m_props["CACHE_MODE"] = "OPTIMIZE_SIZE";
+
+ auto compiled = m_core.compile_model(m_ov_model, "NPU", m_props);
+
+ std::stringstream blob;
+ compiled.export_model(blob);
+
+ EXPECT_NO_THROW({
+ auto import_props = m_props;
+ import_props[ov::hint::model.name()] = std::static_pointer_cast<const ov::Model>(m_ov_model);
+ auto imported = m_core.import_model(blob, "NPU", import_props);
+ imported.create_infer_request();
+ });
+}
+
+using ImportNonLLMNonWAIBlobTestNPUW = ImportNonLLMBlobTestNPUW;
+TEST_P(ImportNonLLMNonWAIBlobTestNPUW, CacheModeOptimizeSizeNoModelPtr) {
+ ov::AnyMap wai_props = GetParam();
+ m_props.insert(wai_props.begin(), wai_props.end());
+ m_props["CACHE_MODE"] = "OPTIMIZE_SIZE";
+
+ auto compiled = m_core.compile_model(m_ov_model, "NPU", m_props);
+
+ std::stringstream blob;
+ compiled.export_model(blob);
+
+ EXPECT_NO_THROW({
+ auto imported = m_core.import_model(blob, "NPU", m_props);
+ imported.create_infer_request();
+ });
+}
+
+using ImportNonLLMWAIBlobTestNPUW = ImportNonLLMBlobTestNPUW;
+TEST_P(ImportNonLLMWAIBlobTestNPUW, CacheModeOptimizeSizeNoModelPtr) {
+ ov::AnyMap wai_props = GetParam();
+ m_props.insert(wai_props.begin(), wai_props.end());
+ m_props["CACHE_MODE"] = "OPTIMIZE_SIZE";
+
+ auto compiled = m_core.compile_model(m_ov_model, "NPU", m_props);
+
+ std::stringstream blob;
+ compiled.export_model(blob);
+ try {
+ auto imported = m_core.import_model(blob, "NPU", m_props);
+ FAIL() << "Expected import to throw when WAI weightless blob is imported without MODEL_PTR/WEIGHTS_PATH";
+ } catch (const ov::Exception& ex) {
+ const std::string what = ex.what();
+ const bool has_expected_text =
+ what.find("Blob is weightless") != std::string::npos &&
+ what.find("WEIGHTS_PATH") != std::string::npos &&
+ what.find("MODEL_PTR") != std::string::npos;
+ EXPECT_TRUE(has_expected_text) << "Unexpected exception message: " << what;
+ }
+}
+
+INSTANTIATE_TEST_SUITE_P(Only_NPU_USE_NPUW, ImportNonLLMBlobTestNPUW,
+ testing::Values(ov::AnyMap{}));
+INSTANTIATE_TEST_SUITE_P(NPUW_FOLD, ImportNonLLMBlobTestNPUW,
+ testing::Values(ov::AnyMap{{"NPUW_FOLD", "YES"}}));
+INSTANTIATE_TEST_SUITE_P(NPUW_CWAI, ImportNonLLMBlobTestNPUW,
+ testing::Values(ov::AnyMap{{"NPUW_CWAI", "YES"}}));
+
+INSTANTIATE_TEST_SUITE_P(NPUW_NON_WAI, ImportNonLLMNonWAIBlobTestNPUW,
+ testing::Values(ov::AnyMap{}, ov::AnyMap{{"NPUW_FUNCALL_FOR_ALL", "YES"}}));
+INSTANTIATE_TEST_SUITE_P(NPUW_WAI, ImportNonLLMWAIBlobTestNPUW,
+ testing::Values(ov::AnyMap{{"NPUW_FOLD", "YES"}}, ov::AnyMap{{"NPUW_CWAI", "YES"}}));