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 Dynamic Prompt: use chunk 1024 (#31868)
Dmitry Matveevd5956968deb7
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 296eaef3d61..3d48f0dc77a 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@@ -110,7 +110,7 @@ DEFINE_OPT(NPUW_LLM_MAX_PROMPT_LEN, uint32_t, 1024, npuw::llm::max_prompt_len, RDEFINE_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);DEFINE_OPT(NPUW_LLM_CACHE_ROPE, bool, true, npuw::llm::cache_rope, CompileTime);-DEFINE_OPT(NPUW_LLM_PREFILL_CHUNK_SIZE, uint64_t, 256, npuw::llm::prefill_chunk_size, RunTime);+DEFINE_OPT(NPUW_LLM_PREFILL_CHUNK_SIZE, uint64_t, 1024, npuw::llm::prefill_chunk_size, RunTime);DEFINE_OPT(NPUW_LLM_SHARED_HEAD, bool, true, npuw::llm::shared_lm_head, CompileTime);DEFINE_OPT(NPUW_LLM_MAX_LORA_RANK, uint32_t, 32, npuw::llm::max_lora_rank, RunTime);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.hppindex 972d98d753b..245305c8646 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@@ -462,7 +462,7 @@ static constexpr ov::Property<bool> cache_rope{"NPUW_LLM_CACHE_ROPE"};* Prompt chunk size for chunk prefill.* The chunk size should be a power of two.* Chunk prefill feature is disabled in case the value is 0.- * Default value: 0.+ * Default value: 1024.*/static constexpr ov::Property<uint64_t> prefill_chunk_size{"NPUW_LLM_PREFILL_CHUNK_SIZE"};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.cppindex bdf0e650539..28f3302505f 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@@ -843,37 +843,35 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& mconst ::intel_npu::npuw::llm::PrefillHint prefill_hint = m_cfg.get<::intel_npu::NPUW_LLM_PREFILL_HINT>();m_prefill_chunk_size = m_cfg.get<::intel_npu::NPUW_LLM_PREFILL_CHUNK_SIZE>();m_use_chunk_prefill = (prefill_hint == ::intel_npu::npuw::llm::PrefillHint::DYNAMIC && m_prefill_chunk_size > 0);- const auto prompt_alignment = static_cast<uint32_t>(m_use_chunk_prefill ? m_prefill_chunk_size : 64u);const uint32_t batch_dim = m_cfg.get<::intel_npu::NPUW_LLM_BATCH_DIM>();const uint32_t seq_len_dim = m_cfg.get<::intel_npu::NPUW_LLM_SEQ_LEN_DIM>();KVAxesPosition axes{batch_dim, seq_len_dim};- const uint32_t max_prompt_len = align_to(m_cfg.get<::intel_npu::NPUW_LLM_MAX_PROMPT_LEN>(), prompt_alignment);+ uint32_t max_prompt_len = align_to(m_cfg.get<::intel_npu::NPUW_LLM_MAX_PROMPT_LEN>(), 64u);const uint32_t min_response_len = align_to(m_cfg.get<::intel_npu::NPUW_LLM_MIN_RESPONSE_LEN>(), 64u);- LOG_VERB("Enabled prefill chunking: " << m_use_chunk_prefill);- LOG_VERB("Prefill chunk size: " << m_prefill_chunk_size);- LOG_VERB("Maximum prompt length: " << max_prompt_len);-- auto is_power_of_two = [](uint64_t n) {- return n > 0 && (n & (n - 1)) == 0;- };+ // If chunk size covers the entire prompt, just follow the static behavior.+ // Otherwise, use chunking and align the prompt size to the chunk size.if (m_use_chunk_prefill) {- if (!is_power_of_two(m_prefill_chunk_size)) {- OPENVINO_THROW("Configuration Error: chunk size (",- m_prefill_chunk_size,- ") is not power of 2. Please adjust NPUW_LLM_PREFILL_CHUNK_SIZE.");- }-- if (max_prompt_len % m_prefill_chunk_size) {- OPENVINO_THROW("Configuration Error: The maximum prompt length (",- max_prompt_len,- ") is not a multiple of chunk size (",- m_prefill_chunk_size,- "). Please adjust NPUW_LLM_MAX_PROMPT_LEN to be a multiple of NPUW_LLM_PREFILL_CHUNK_SIZE.");+ if (m_prefill_chunk_size >= max_prompt_len) {+ m_use_chunk_prefill = false;+ } else {+ const auto is_power_of_two = [](uint64_t n) {+ return n > 0 && (n & (n - 1)) == 0;+ };+ if (!is_power_of_two(m_prefill_chunk_size)) {+ OPENVINO_THROW("Configuration Error: chunk size (",+ m_prefill_chunk_size,+ ") is not power of 2. Please adjust NPUW_LLM_PREFILL_CHUNK_SIZE.");+ }+ max_prompt_len = align_to(max_prompt_len, static_cast<uint32_t>(m_prefill_chunk_size));}}+ LOG_VERB("Enabled prefill chunking: " << m_use_chunk_prefill);+ LOG_VERB("Prefill chunk size: " << m_prefill_chunk_size);+ LOG_VERB("Maximum prompt length: " << max_prompt_len);+m_kvcache_desc = KVCacheDesc{max_prompt_len, max_prompt_len + min_response_len, 0u, seq_len_dim};LOG_DEBUG("Make prefill model with static shapes");m_max_lora_rank = m_cfg.get<::intel_npu::NPUW_LLM_MAX_LORA_RANK>();