Skip to content

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

NPUW: Introduce a knob to properly enable dynamic prompt (#29333)

Dmitry Matveev9e3fc64ed824
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.hpp
index c5c2e1b5886..4e7b6dc8f58 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
@@ -76,10 +76,55 @@ DEFINE_OPT(NPUW_LLM_OPTIMIZE_V_TENSORS, bool, true, npuw::llm::optimize_v_tensor
namespace npuw {
namespace llm {
+enum class PrefillHint { DYNAMIC, STATIC };
enum class GenerateHint { FAST_COMPILE, BEST_PERF };
} // namespace llm
} // namespace npuw
+struct NPUW_LLM_PREFILL_HINT final : OptionBase<NPUW_LLM_PREFILL_HINT, ::intel_npu::npuw::llm::PrefillHint> {
+ static std::string_view key() {
+ return ov::intel_npu::npuw::llm::prefill_hint.name();
+ }
+
+ static constexpr std::string_view getTypeName() {
+ return "::intel_npu::npuw::llm::PrefillHint";
+ }
+
+ static ::intel_npu::npuw::llm::PrefillHint defaultValue() {
+ return ::intel_npu::npuw::llm::PrefillHint::STATIC;
+ }
+
+ static ::intel_npu::npuw::llm::PrefillHint parse(std::string_view val) {
+ if (val == "DYNAMIC") {
+ return ::intel_npu::npuw::llm::PrefillHint::DYNAMIC;
+ } else if (val == "STATIC") {
+ return ::intel_npu::npuw::llm::PrefillHint::STATIC;
+ }
+ OPENVINO_THROW("Unsupported \"PREFILL_HINT\" provided: ", val);
+ return {};
+ }
+
+ static std::string toString(const ::intel_npu::npuw::llm::PrefillHint& val) {
+ switch (val) {
+ case ::intel_npu::npuw::llm::PrefillHint::DYNAMIC:
+ return "DYNAMIC";
+ case ::intel_npu::npuw::llm::PrefillHint::STATIC:
+ return "STATIC";
+ default:
+ OPENVINO_THROW("Can't convert provided \"PREFILL_HINT\" : ", int(val), " to string.");
+ }
+ return {};
+ }
+
+ static OptionMode mode() {
+ return OptionMode::CompileTime;
+ }
+
+ static bool isPublic() {
+ return true;
+ }
+};
+
struct NPUW_LLM_GENERATE_HINT final : OptionBase<NPUW_LLM_GENERATE_HINT, ::intel_npu::npuw::llm::GenerateHint> {
static std::string_view key() {
return ov::intel_npu::npuw::llm::generate_hint.name();
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/npuw_private_properties.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/npuw_private_properties.hpp
index bbf7073a046..cefbc831f2e 100644
--- a/src/plugins/intel_npu/src/al/include/intel_npu/npuw_private_properties.hpp
+++ b/src/plugins/intel_npu/src/al/include/intel_npu/npuw_private_properties.hpp
@@ -432,6 +432,16 @@ static constexpr ov::Property<uint32_t> min_response_len{"NPUW_LLM_MIN_RESPONSE_
*/
static constexpr ov::Property<bool> optimize_v_tensors{"NPUW_LLM_OPTIMIZE_V_TENSORS"};
+/**
+ * @brief
+ * Type: std::string.
+ * Hint for prefill stage. NPUW will use optimal configuration based on the passed preference via hint.
+ * Passing this hint with "NPUW_LLM_PREFILL_CONFIG" will generate a error.
+ * Possible values: "DYNAMIC", "STATIC".
+ * Default value: "STATIC".
+ */
+static constexpr ov::Property<std::string> prefill_hint{"NPUW_LLM_PREFILL_HINT"};
+
/**
* @brief
* Type: ov::AnyMap.
@@ -444,7 +454,7 @@ static constexpr ov::Property<ov::AnyMap> prefill_config{"NPUW_LLM_PREFILL_CONFI
* @brief
* Type: std::string.
* Hint for generation stage. NPUW will use optimal configuration based on the passed preference via hint.
- * Hint is ignored if used with "NPUW_LLM_GENERATE_CONFIG".
+ * Passing this hint with "NPUW_LLM_GENERATE_CONFIG" will generate a error.
* Possible values: "FAST_COMPILE", "BEST_PERF".
* Default value: "FAST_COMPILE".
*/
diff --git a/src/plugins/intel_npu/src/al/src/config/npuw.cpp b/src/plugins/intel_npu/src/al/src/config/npuw.cpp
index 0ed344596fe..707d78105c2 100644
--- a/src/plugins/intel_npu/src/al/src/config/npuw.cpp
+++ b/src/plugins/intel_npu/src/al/src/config/npuw.cpp
@@ -62,5 +62,6 @@ void intel_npu::registerNPUWLLMOptions(OptionsDesc& desc) {
desc.add<NPUW_LLM_MAX_PROMPT_LEN>();
desc.add<NPUW_LLM_MIN_RESPONSE_LEN>();
desc.add<NPUW_LLM_OPTIMIZE_V_TENSORS>();
+ desc.add<NPUW_LLM_PREFILL_HINT>();
desc.add<NPUW_LLM_GENERATE_HINT>();
}
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.cpp
index 50b0989af77..638aa33face 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
@@ -507,8 +507,17 @@ ov::AnyMap get_default_common_config(const std::shared_ptr<ov::Model>& model, co
return config;
}
-ov::AnyMap get_default_prefill_config(const std::shared_ptr<ov::Model>& model, const std::optional<NPUDesc>& npudesc) {
+ov::AnyMap get_default_prefill_config(const std::shared_ptr<ov::Model>& model,
+ const std::optional<NPUDesc>& npudesc,
+ const ::intel_npu::npuw::llm::PrefillHint hint) {
auto config = get_default_common_config(model, npudesc);
+ if (hint == ::intel_npu::npuw::llm::PrefillHint::DYNAMIC) {
+ if (is_cw_compressed(model)) {
+ // NB: These two ifs are not combined into one with && deliberately
+ // there may be later changes w.r.t. required compiler versions for GQ
+ config.emplace("NPUW_ONLINE_PIPELINE", "SPATIAL");
+ }
+ }
if (npudesc.has_value() && npudesc->arch == "4000" && npudesc->max_tiles != -1) {
config.emplace("NPU_DPU_GROUPS", npudesc->max_tiles);
}
@@ -645,8 +654,14 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
prefill_model = cvt_kvcache_to_fp16(prefill_model);
auto npudesc = extract_npu_descriptor(plugin);
+
+ // NB: PREFILL_HINT is only applicable for default prefill config!
+ if (prefill_config_opt.has_value() && npuw_llm_props.count(ov::intel_npu::npuw::llm::prefill_hint.name())) {
+ OPENVINO_THROW("PREFILL_HINT only works with default prefill config!");
+ }
+ const ::intel_npu::npuw::llm::PrefillHint prefill_hint = m_cfg.get<::intel_npu::NPUW_LLM_PREFILL_HINT>();
auto prefill_config =
- prefill_config_opt.value_or(get_default_prefill_config(prefill_model, npudesc)).as<ov::AnyMap>();
+ prefill_config_opt.value_or(get_default_prefill_config(prefill_model, npudesc, prefill_hint)).as<ov::AnyMap>();
// NB: GENERATE_HINT is only applicable for default generate config!
if (generate_config_opt.has_value() && npuw_llm_props.count(ov::intel_npu::npuw::llm::generate_hint.name())) {
@@ -905,6 +920,7 @@ void ov::npuw::LLMCompiledModel::implement_properties() {
BIND(npuw::llm::max_prompt_len, NPUW_LLM_MAX_PROMPT_LEN, get),
BIND(npuw::llm::min_response_len, NPUW_LLM_MIN_RESPONSE_LEN, get),
BIND(npuw::llm::optimize_v_tensors, NPUW_LLM_OPTIMIZE_V_TENSORS, get),
+ BIND(npuw::llm::prefill_hint, NPUW_LLM_PREFILL_HINT, getString),
BIND(npuw::llm::generate_hint, NPUW_LLM_GENERATE_HINT, getString)});
#undef BIND
}