Skip to content

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

[NPU] Change model priority at runtime without re-creating the pipeline (#35039)

Bogdan Pereanuc2e6481207b1
diff --git a/src/plugins/intel_npu/README.md b/src/plugins/intel_npu/README.md
index 7e98c1a8048..0fc9ecc9093 100644
--- a/src/plugins/intel_npu/README.md
+++ b/src/plugins/intel_npu/README.md
@@ -195,6 +195,7 @@ The following properties are supported (may differ based on current system confi
| `ov::range_for_async_infer_requests`/</br>`RANGE_FOR_ASYNC_INFER_REQUESTS` | RO | Returns a tuple (bottom, top, step). </br> Not used by the NPU plugin. | `N/A` | `N/A` |
| `ov::range_for_streams`/</br>`RANGE_FOR_STREAMS` | RO | Returns a tuple (bottom, top).</br> Not used by the NPU plugin. | `N/A`| `N/A` |
| `ov::enable_profiling`/</br>`PERF_COUNT` | RW | Enables or disables performance counters. | `YES`/ `NO` | `NO` |
+| `ov::workload_type`/</br>`WORKLOAD_TYPE` | RW | Selects the NPU workload profile for model execution. | `DEFAULT`/ `EFFICIENT`| `DEFAULT` |
| `ov::hint::performance_mode`/</br>`PERFORMANCE_HINT` | RW | Sets the performance profile used to determine default values of Tiles/DMAs/NIREQs.</br>Default values for each profile are documented below. | `THROUGHPUT`/</br>`LATENCY`/</br>`UNDEFINED` | `UNDEFINED` |
| `ov::hint::num_requests`/</br>`PERFORMANCE_HINT_NUM_REQUESTS` | RW | Sets the number of outstanding inference requests. | `[0-]` | `1` |
| `ov::hint::model_priority`/</br>`MODEL_PRIORITY` | RW | Assigns a priority for the model execution. | `LOW`/</br>`MEDIUM`/</br>`HIGH` | `MEDIUM` |
diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp
index 0039a76a433..4c551a40e93 100644
--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp
+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp
@@ -50,6 +50,7 @@ public:
virtual CommandQueueDesc get_command_queue_desc() const;
virtual void set_workload_type(const ov::WorkloadType workloadType);
+ virtual void set_model_priority(const ov::hint::Priority modelPriority);
std::mutex& get_mutex() {
return _initialize_mutex;
diff --git a/src/plugins/intel_npu/src/common/src/igraph.cpp b/src/plugins/intel_npu/src/common/src/igraph.cpp
index c916efe89f9..248410d5089 100644
--- a/src/plugins/intel_npu/src/common/src/igraph.cpp
+++ b/src/plugins/intel_npu/src/common/src/igraph.cpp
@@ -58,6 +58,10 @@ void IGraph::set_workload_type(const ov::WorkloadType) {
OPENVINO_THROW("set_workload_type not implemented");
}
+void IGraph::set_model_priority(const ov::hint::Priority) {
+ OPENVINO_THROW("set_model_priority not implemented");
+}
+
void IGraph::set_last_submitted_event(const std::shared_ptr<Event>&, size_t) {
OPENVINO_THROW("set_last_submitted_event not implemented");
}
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp
index acaad6a9496..954f6a5f588 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp
@@ -129,6 +129,7 @@ public:
CommandQueueDesc get_command_queue_desc() const override;
void set_workload_type(const ov::WorkloadType workloadType) override;
+ void set_model_priority(const ov::hint::Priority modelPriority) override;
void set_batch_size(std::size_t batch) override;
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp
index c65976e33d1..272fab4c624 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp
@@ -44,6 +44,7 @@ public:
CommandQueueDesc get_command_queue_desc() const override;
void set_workload_type(const ov::WorkloadType workloadType) override;
+ void set_model_priority(const ov::hint::Priority modelPriority) override;
void set_last_submitted_event(const std::shared_ptr<Event>& event, size_t indexOfCommandList) override;
const std::shared_ptr<Event>& get_last_submitted_event(size_t indexOfCommandList) const override;
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp
index 9bb18370cfa..96252fd29da 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp
@@ -512,6 +512,23 @@ void DynamicGraph::set_workload_type(const ov::WorkloadType workloadType) {
_commandQueueDesc.key = static_cast<uint64_t>(queueKeyHash);
}
+void DynamicGraph::set_model_priority(const ov::hint::Priority modelPriority) {
+ if (_zeroInitStruct == nullptr) {
+ return;
+ }
+
+ std::lock_guard<std::mutex> lock(_commandQueueDescMutex);
+ auto zeModelPriority = zeroUtils::toZeQueuePriority(modelPriority);
+ if (_commandQueueDesc.priority == zeModelPriority) {
+ return;
+ }
+ _commandQueueDesc.priority = zeModelPriority;
+
+ const ZeroCmdQueueKey key{_zeroInitStruct->getContext(), _zeroInitStruct->getDevice(), _commandQueueDesc};
+ const auto queueKeyHash = ZeroCmdQueueKeyHash{}(key);
+ _commandQueueDesc.key = static_cast<uint64_t>(queueKeyHash);
+}
+
void DynamicGraph::set_argument_value(uint32_t argi, const void* argv) const {
if (_impl == nullptr) {
_logger.warning("Graph handle is null, dynamic pipeline to handle set_argument_value");
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
index abe10558a74..04503cb76e2 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
@@ -72,6 +72,23 @@ void Graph::set_workload_type(const ov::WorkloadType workloadType) {
_commandQueueDesc.key = static_cast<uint64_t>(queueKeyHash);
}
+void Graph::set_model_priority(const ov::hint::Priority modelPriority) {
+ if (_zeroInitStruct == nullptr) {
+ return;
+ }
+
+ std::lock_guard<std::mutex> lock(_commandQueueDescMutex);
+ auto zeModelPriority = zeroUtils::toZeQueuePriority(modelPriority);
+ if (_commandQueueDesc.priority == zeModelPriority) {
+ return;
+ }
+ _commandQueueDesc.priority = zeModelPriority;
+
+ const ZeroCmdQueueKey key{_zeroInitStruct->getContext(), _zeroInitStruct->getDevice(), _commandQueueDesc};
+ const auto queueKeyHash = ZeroCmdQueueKeyHash{}(key);
+ _commandQueueDesc.key = static_cast<uint64_t>(queueKeyHash);
+}
+
ze_graph_handle_t Graph::get_handle() const {
return _graphDesc._handle;
}
diff --git a/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp b/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
index 065c920b7eb..8ff6b6147de 100644
--- a/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
@@ -163,6 +163,13 @@ void CompiledModel::set_property(const ov::AnyMap& properties) {
_graph->set_workload_type(workloadType);
}
}
+
+ if (properties.count(std::string(MODEL_PRIORITY::key())) != 0) {
+ if (_graph != nullptr) {
+ const auto modelPriority = properties.at(ov::hint::model_priority.name()).as<ov::hint::Priority>();
+ _graph->set_model_priority(modelPriority);
+ }
+ }
}
ov::Any CompiledModel::get_property(const std::string& name) const {
diff --git a/src/plugins/intel_npu/src/plugin/src/properties.cpp b/src/plugins/intel_npu/src/plugin/src/properties.cpp
index a9d3590cca5..cf7f0e34386 100644
--- a/src/plugins/intel_npu/src/plugin/src/properties.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/properties.cpp
@@ -720,7 +720,6 @@ void Properties::registerCompiledModelProperties() {
TRY_REGISTER_SIMPLE_PROPERTY(ov::hint::enable_cpu_pinning, ENABLE_CPU_PINNING);
TRY_REGISTER_SIMPLE_PROPERTY(ov::log::level, LOG_LEVEL);
TRY_REGISTER_SIMPLE_PROPERTY(ov::loaded_from_cache, LOADED_FROM_CACHE);
- TRY_REGISTER_SIMPLE_PROPERTY(ov::hint::model_priority, MODEL_PRIORITY);
TRY_REGISTER_SIMPLE_PROPERTY(ov::hint::performance_mode, PERFORMANCE_HINT);
TRY_REGISTER_SIMPLE_PROPERTY(ov::hint::execution_mode, EXECUTION_MODE_HINT);
TRY_REGISTER_SIMPLE_PROPERTY(ov::hint::num_requests, PERFORMANCE_HINT_NUM_REQUESTS);
@@ -762,6 +761,14 @@ void Properties::registerCompiledModelProperties() {
TRY_REGISTER_VARPUB_PROPERTY(ov::intel_npu::batch_mode, BATCH_MODE, false);
TRY_REGISTER_VARPUB_PROPERTY(ov::intel_npu::shared_common_queue, SHARED_COMMON_QUEUE, false);
+ TRY_REGISTER_CUSTOM_PROPERTY(ov::hint::model_priority,
+ MODEL_PRIORITY,
+ true,
+ ov::PropertyMutability::RW,
+ [](const Config& config) {
+ return config.get<MODEL_PRIORITY>();
+ });
+
TRY_REGISTER_CUSTOM_PROPERTY(ov::workload_type,
WORKLOAD_TYPE,
true,
diff --git a/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.cpp b/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.cpp
index e1987dd8043..2de8235f006 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/compiled_model/property.cpp
@@ -17,7 +17,6 @@ std::vector<std::pair<std::string, ov::Any>> exe_network_supported_properties =
{ov::hint::num_requests.name(), ov::Any(8)},
{ov::hint::enable_cpu_pinning.name(), ov::Any(true)},
{ov::hint::performance_mode.name(), ov::Any(ov::hint::PerformanceMode::THROUGHPUT)},
- {ov::hint::model_priority.name(), ov::Any(ov::hint::Priority::MEDIUM)},
{ov::optimal_number_of_infer_requests.name(), ov::Any(2)},
};
diff --git a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/compile_and_infer.hpp b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/compile_and_infer.hpp
index cf330226e3f..b590fe2258e 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/compile_and_infer.hpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/compile_and_infer.hpp
@@ -265,6 +265,26 @@ TEST_P(OVCompileAndInferRequest, CompiledModelWorkloadTypeUpdateAfterCompilation
ASSERT_TRUE(is_called);
}
+TEST_P(OVCompileAndInferRequest, CompiledModelModelPriorityUpdateAfterCompilation) {
+ configuration[hint::model_priority.name()] = hint::Priority::MEDIUM;
+ OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration));
+ ASSERT_EQ(execNet.get_property(hint::model_priority.name()).as<hint::Priority>(), hint::Priority::MEDIUM);
+
+ ov::AnyMap modelConfiguration;
+ ov::InferRequest req;
+
+ modelConfiguration[hint::model_priority.name()] = hint::Priority::HIGH;
+ OV_ASSERT_NO_THROW(execNet.set_property(modelConfiguration));
+ ASSERT_EQ(execNet.get_property(hint::model_priority.name()).as<hint::Priority>(), hint::Priority::HIGH);
+ OV_ASSERT_NO_THROW(req = execNet.create_infer_request());
+ OV_ASSERT_NO_THROW(req.infer());
+
+ modelConfiguration[hint::model_priority.name()] = hint::Priority::LOW;
+ OV_ASSERT_NO_THROW(execNet.set_property(modelConfiguration));
+ ASSERT_EQ(execNet.get_property(hint::model_priority.name()).as<hint::Priority>(), hint::Priority::LOW);
+ OV_ASSERT_NO_THROW(req.infer());
+}
+
using OVCompileAndInferRequestMultiThreading = OVCompileAndInferRequest;
TEST_P(OVCompileAndInferRequestMultiThreading, CreateInferRequestsAndRunOnDifferentThreads) {
@@ -303,7 +323,7 @@ TEST_P(OVCompileAndInferRequestMultiThreading, CreateInferRequestsAndRunOnDiffer
}
}
-TEST_P(OVCompileAndInferRequestMultiThreading, CreateInferRequestsAndRunOnDifferentThreadsWithWorkloadType) {
+TEST_P(OVCompileAndInferRequestMultiThreading, CreateInferRequestsAndRunOnDifferentThreadsWithWorkloadTypeAndPriority) {
if (!isCommandQueueExtSupported()) {
GTEST_SKIP() << "Workload type update is not supported with current driver.\n";
}
@@ -326,6 +346,13 @@ TEST_P(OVCompileAndInferRequestMultiThreading, CreateInferRequestsAndRunOnDiffer
} else {
execNet.set_property(ov::workload_type(WorkloadType::EFFICIENT));
}
+ if (i % 3 == 0) {
+ execNet.set_property(ov::hint::model_priority(ov::hint::Priority::HIGH));
+ } else if (i % 3 == 1) {
+ execNet.set_property(ov::hint::model_priority(ov::hint::Priority::MEDIUM));
+ } else {
+ execNet.set_property(ov::hint::model_priority(ov::hint::Priority::LOW));
+ }
auto req = execNet.create_infer_request();
req.infer();
} catch (...) {
@@ -351,7 +378,7 @@ TEST_P(OVCompileAndInferRequestMultiThreading, CreateInferRequestsAndRunOnDiffer
}
TEST_P(OVCompileAndInferRequestMultiThreading,
- CompileModelCreateInferRequestsAndRunOnDifferentThreadsWithWorkloadType) {
+ CompileModelCreateInferRequestsAndRunOnDifferentThreadsWithWorkloadTypeAndPriority) {
if (!isCommandQueueExtSupported()) {
GTEST_SKIP() << "Workload type update is not supported with current driver.\n";
}
@@ -375,6 +402,13 @@ TEST_P(OVCompileAndInferRequestMultiThreading,
} else {
compiled_models[i].set_property(ov::workload_type(WorkloadType::EFFICIENT));
}
+ if (i % 3 == 0) {
+ compiled_models[i].set_property(ov::hint::model_priority(ov::hint::Priority::HIGH));
+ } else if (i % 3 == 1) {
+ compiled_models[i].set_property(ov::hint::model_priority(ov::hint::Priority::MEDIUM));
+ } else {
+ compiled_models[i].set_property(ov::hint::model_priority(ov::hint::Priority::LOW));
+ }
auto req = compiled_models[i].create_infer_request();
req.infer();
} catch (...) {
@@ -406,11 +440,22 @@ TEST_P(OVCompileAndInferRequestMultiThreading,
ASSERT_EQ(compiled_models[i].get_property(ov::workload_type.name()).as<WorkloadType>(),
WorkloadType::EFFICIENT);
}
+
+ if (i % 3 == 0) {
+ ASSERT_EQ(compiled_models[i].get_property(ov::hint::model_priority.name()).as<ov::hint::Priority>(),
+ ov::hint::Priority::HIGH);
+ } else if (i % 3 == 1) {
+ ASSERT_EQ(compiled_models[i].get_property(ov::hint::model_priority.name()).as<ov::hint::Priority>(),
+ ov::hint::Priority::MEDIUM);
+ } else {
+ ASSERT_EQ(compiled_models[i].get_property(ov::hint::model_priority.name()).as<ov::hint::Priority>(),
+ ov::hint::Priority::LOW);
+ }
}
}
TEST_P(OVCompileAndInferRequestMultiThreading,
- CompileModelCreateInferRequestsAndRunOnDifferentThreadsWithWorkloadTypeAndSharedCommonQueueDisabled) {
+ CompileModelCreateInferRequestsAndRunOnDifferentThreadsWithWorkloadTypePriorityAndSharedCommonQueueDisabled) {
if (!isCommandQueueExtSupported()) {
GTEST_SKIP() << "Workload type update is not supported with current driver.\n";
}
@@ -435,6 +480,13 @@ TEST_P(OVCompileAndInferRequestMultiThreading,
} else {
compiled_models[i].set_property(ov::workload_type(WorkloadType::EFFICIENT));
}
+ if (i % 3 == 0) {
+ compiled_models[i].set_property(ov::hint::model_priority(ov::hint::Priority::HIGH));
+ } else if (i % 3 == 1) {
+ compiled_models[i].set_property(ov::hint::model_priority(ov::hint::Priority::MEDIUM));
+ } else {
+ compiled_models[i].set_property(ov::hint::model_priority(ov::hint::Priority::LOW));
+ }
auto req = compiled_models[i].create_infer_request();
req.infer();
} catch (...) {
@@ -466,6 +518,17 @@ TEST_P(OVCompileAndInferRequestMultiThreading,
ASSERT_EQ(compiled_models[i].get_property(ov::workload_type.name()).as<WorkloadType>(),
WorkloadType::EFFICIENT);
}
+
+ if (i % 3 == 0) {
+ ASSERT_EQ(compiled_models[i].get_property(ov::hint::model_priority.name()).as<ov::hint::Priority>(),
+ ov::hint::Priority::HIGH);
+ } else if (i % 3 == 1) {
+ ASSERT_EQ(compiled_models[i].get_property(ov::hint::model_priority.name()).as<ov::hint::Priority>(),
+ ov::hint::Priority::MEDIUM);
+ } else {
+ ASSERT_EQ(compiled_models[i].get_property(ov::hint::model_priority.name()).as<ov::hint::Priority>(),
+ ov::hint::Priority::LOW);
+ }
}
}