Skip to content

Commit 7d17605

Browse files
committed
Split linkage dependency between LLMCompiledModel and INPUWCompiledModelFactory
1 parent 9ecc9ba commit 7d17605

File tree

5 files changed

+73
-46
lines changed

5 files changed

+73
-46
lines changed

src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,21 +1818,6 @@ void ov::npuw::LLMCompiledModel::compile_generate_model_variants(
18181818
m_kvcache_compiled = m_generate_compiled_variants.back();
18191819
}
18201820

1821-
std::shared_ptr<ov::npuw::ICompiledModel> ov::npuw::DefaultNPUWCompiledModelFactory::create(
1822-
const std::shared_ptr<ov::Model>& model,
1823-
const std::shared_ptr<const ov::IPlugin>& plugin,
1824-
const ov::AnyMap& properties) {
1825-
return std::make_shared<ov::npuw::CompiledModel>(model, plugin, properties);
1826-
}
1827-
1828-
std::shared_ptr<ov::npuw::ICompiledModel> ov::npuw::DefaultNPUWCompiledModelFactory::deserialize(
1829-
std::istream& stream,
1830-
const std::shared_ptr<const ov::IPlugin>& plugin,
1831-
const ov::AnyMap& properties,
1832-
const ov::npuw::s11n::CompiledContext& enc_ctx) {
1833-
return ov::npuw::CompiledModel::deserialize(stream, plugin, properties, enc_ctx);
1834-
}
1835-
18361821
ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& model,
18371822
const std::shared_ptr<const ov::IPlugin>& plugin,
18381823
const ov::AnyMap& properties,
@@ -1859,10 +1844,9 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
18591844
// Solely used for serialization at the moment
18601845
m_non_llm_props = other_props;
18611846

1862-
std::shared_ptr<ov::npuw::INPUWCompiledModelFactory> factory = std::make_shared<DefaultNPUWCompiledModelFactory>();
1863-
if (npuw_cm_factory) {
1864-
LOG_DEBUG("Using provided custom NPUW CompiledModel factory");
1865-
factory = npuw_cm_factory;
1847+
std::shared_ptr<ov::npuw::INPUWCompiledModelFactory> factory = npuw_cm_factory;
1848+
if (!factory) {
1849+
factory = make_default_npuw_factory();
18661850
}
18671851
OPENVINO_ASSERT(factory, "Factory is nullptr!");
18681852

@@ -2548,10 +2532,9 @@ std::shared_ptr<ov::npuw::LLMCompiledModel> ov::npuw::LLMCompiledModel::import_m
25482532
}
25492533
};
25502534

2551-
std::shared_ptr<INPUWCompiledModelFactory> factory = std::make_shared<DefaultNPUWCompiledModelFactory>();
2552-
if (npuw_cm_factory) {
2553-
LOG_DEBUG("Using provided custom NPUW CompiledModel factory");
2554-
factory = npuw_cm_factory;
2535+
std::shared_ptr<INPUWCompiledModelFactory> factory = npuw_cm_factory;
2536+
if (!factory) {
2537+
factory = make_default_npuw_factory();
25552538
}
25562539
OPENVINO_ASSERT(factory, "Factory is nullptr!");
25572540

src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.hpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <memory>
88

99
#include "compiled_model.hpp"
10+
#include "npuw_compiled_model_factory.hpp"
1011
#include "openvino/openvino.hpp"
1112

1213
namespace {
@@ -18,29 +19,6 @@ struct KVAxesPosition {
1819

1920
namespace ov {
2021
namespace npuw {
21-
class INPUWCompiledModelFactory {
22-
public:
23-
virtual std::shared_ptr<ov::npuw::ICompiledModel> create(const std::shared_ptr<ov::Model>& model,
24-
const std::shared_ptr<const ov::IPlugin>& plugin,
25-
const ov::AnyMap& properties) = 0;
26-
virtual std::shared_ptr<ov::npuw::ICompiledModel> deserialize(std::istream& stream,
27-
const std::shared_ptr<const ov::IPlugin>& plugin,
28-
const ov::AnyMap& properties,
29-
const ov::npuw::s11n::CompiledContext& enc_ctx) = 0;
30-
};
31-
32-
class DefaultNPUWCompiledModelFactory : public INPUWCompiledModelFactory {
33-
public:
34-
std::shared_ptr<ov::npuw::ICompiledModel> create(const std::shared_ptr<ov::Model>& model,
35-
const std::shared_ptr<const ov::IPlugin>& plugin,
36-
const ov::AnyMap& properties) override;
37-
38-
std::shared_ptr<ov::npuw::ICompiledModel> deserialize(std::istream& stream,
39-
const std::shared_ptr<const ov::IPlugin>& plugin,
40-
const ov::AnyMap& properties,
41-
const ov::npuw::s11n::CompiledContext& enc_ctx) override;
42-
};
43-
4422
class LLMInferRequest;
4523
class WhisperInferRequest;
4624
struct PrefixCacheRestorationContext;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (C) 2018-2026 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include "npuw_compiled_model_factory.hpp"
6+
7+
std::shared_ptr<ov::npuw::ICompiledModel> ov::npuw::DefaultNPUWCompiledModelFactory::create(
8+
const std::shared_ptr<ov::Model>& model,
9+
const std::shared_ptr<const ov::IPlugin>& plugin,
10+
const ov::AnyMap& properties) {
11+
return std::make_shared<ov::npuw::CompiledModel>(model, plugin, properties);
12+
}
13+
14+
std::shared_ptr<ov::npuw::ICompiledModel> ov::npuw::DefaultNPUWCompiledModelFactory::deserialize(
15+
std::istream& stream,
16+
const std::shared_ptr<const ov::IPlugin>& plugin,
17+
const ov::AnyMap& properties,
18+
const ov::npuw::s11n::CompiledContext& enc_ctx) {
19+
return ov::npuw::CompiledModel::deserialize(stream, plugin, properties, enc_ctx);
20+
}
21+
22+
std::shared_ptr<ov::npuw::INPUWCompiledModelFactory> ov::npuw::make_default_npuw_factory() {
23+
return std::make_shared<DefaultNPUWCompiledModelFactory>();
24+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (C) 2018-2026 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#pragma once
6+
7+
#include "compiled_model.hpp"
8+
9+
namespace ov {
10+
namespace npuw {
11+
class INPUWCompiledModelFactory {
12+
public:
13+
virtual ~INPUWCompiledModelFactory() = default;
14+
15+
virtual std::shared_ptr<ov::npuw::ICompiledModel> create(const std::shared_ptr<ov::Model>& model,
16+
const std::shared_ptr<const ov::IPlugin>& plugin,
17+
const ov::AnyMap& properties) = 0;
18+
virtual std::shared_ptr<ov::npuw::ICompiledModel> deserialize(std::istream& stream,
19+
const std::shared_ptr<const ov::IPlugin>& plugin,
20+
const ov::AnyMap& properties,
21+
const ov::npuw::s11n::CompiledContext& enc_ctx) = 0;
22+
};
23+
24+
class DefaultNPUWCompiledModelFactory : public INPUWCompiledModelFactory {
25+
public:
26+
std::shared_ptr<ov::npuw::ICompiledModel> create(const std::shared_ptr<ov::Model>& model,
27+
const std::shared_ptr<const ov::IPlugin>& plugin,
28+
const ov::AnyMap& properties) override;
29+
30+
std::shared_ptr<ov::npuw::ICompiledModel> deserialize(std::istream& stream,
31+
const std::shared_ptr<const ov::IPlugin>& plugin,
32+
const ov::AnyMap& properties,
33+
const ov::npuw::s11n::CompiledContext& enc_ctx) override;
34+
};
35+
36+
// Factory function to create the default NPUW compiled model factory.
37+
// Defined in npuw_compiled_model_factory.cpp to isolate the dependency on CompiledModel.
38+
std::shared_ptr<INPUWCompiledModelFactory> make_default_npuw_factory();
39+
40+
} // namespace npuw
41+
} // namespace ov

src/plugins/intel_npu/tests/unit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ ov_add_test_target(
5454
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/moe/moe_resources.cpp # needed for LLMCompiledModel
5555
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/moe/moe_infer_utils.cpp # needed for LLMCompiledModel
5656
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/moe/moe_executor.cpp # needed for LLMCompiledModel
57+
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp # needed for LLMCompiledModel
5758
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/weights_bank.cpp # needed for LLMCompiledModel
5859
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/spatial.cpp # needed for LLMCompiledModel
5960
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp # needed for LLMCompiledModel

0 commit comments

Comments
 (0)