Skip to content

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

NPUW: hfa as default prefill attn hint (#37538)

Koryun Khachatryand293d4b62e0e
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 102c5321493..fc2333f8aba 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
@@ -9,6 +9,7 @@
#include "embedding/redirect_new_kv_to_output.hpp"
#include "embedding/remove_empty_kv_inputs.hpp"
#include "infer_request_utils.hpp"
+#include "intel_npu/npu_private_properties.hpp"
#include "llm_compiled_model_utils.hpp"
#include "llm_infer_request.hpp"
#include "logging.hpp"
@@ -256,10 +257,13 @@ std::optional<NPUDesc> extract_npu_descriptor(const std::shared_ptr<const ov::IP
LOG_WARN(compiler_gate_support_msg << "unsupported");
}
- if (desc.arch == "5010" && desc.compiler_ver >= ONEAPI_MAKE_VERSION(8, 1)) {
- // Flash attention tile with GQA is supported starting from compiler version 8.1 on NPU5010
- desc.support_flash_attention_tile = true;
- }
+ static const std::unordered_set<std::string_view> flash_attention_tile_supported_platforms = {
+ ov::intel_npu::Platform::NPU5010,
+ ov::intel_npu::Platform::NPU6010};
+
+ // Flash attention tile with GQA is supported starting from compiler version 8.1 on supported platforms
+ desc.support_flash_attention_tile =
+ flash_attention_tile_supported_platforms.count(desc.arch) && desc.compiler_ver >= ONEAPI_MAKE_VERSION(8, 1);
return std::make_optional(std::move(desc));
}
@@ -427,6 +431,33 @@ void split_llm_properties(const ov::AnyMap& properties, ov::AnyMap& llm_properti
}
}
+// Decide on using fused flash attention tile based on provided option and NPU capabilities.
+// If hardware supports and attention hint is set to HFA, then we can use fused flash attention implementation
+// automatically, unless user explicitly disables it via NPUW_ATTN_HFA_FUSED=NO option.
+void resolve_hfa_fused_attention(::intel_npu::Config& cfg,
+ ov::AnyMap& other_props,
+ const std::optional<NPUDesc>& npudesc) {
+ uint32_t max_prompt_len = align_to(cfg.get<::intel_npu::NPUW_LLM_MAX_PROMPT_LEN>(), 64u);
+ const auto prefill_attn_hint_provided = cfg.has<::intel_npu::NPUW_LLM_PREFILL_ATTENTION_HINT>();
+ const auto hfa_fused_npu_supported = npudesc.has_value() && npudesc->support_flash_attention_tile;
+ const auto prompt_length_supported =
+ max_prompt_len >= 4096; // HFA fused attention tile is optimal prompt length >= 4096
+
+ // If NPUW_LLM_PREFILL_ATTENTION_HINT was not provided, set HFA automatically
+ // when the hardware and prompt length favor the fused flash attention tile implementation
+ if (!prefill_attn_hint_provided && hfa_fused_npu_supported && prompt_length_supported) {
+ cfg.update({{"NPUW_LLM_PREFILL_ATTENTION_HINT", "HFA"}});
+ LOG_INFO("Auto-selected NPUW_LLM_PREFILL_ATTENTION_HINT to HFA");
+ }
+
+ const auto is_hfa =
+ cfg.get<::intel_npu::NPUW_LLM_PREFILL_ATTENTION_HINT>() == ::intel_npu::npuw::llm::AttentionHint::HFA;
+ if (other_props.count("NPUW_ATTN_HFA_FUSED") == 0 && is_hfa && hfa_fused_npu_supported) {
+ other_props["NPUW_ATTN_HFA_FUSED"] = "YES";
+ LOG_INFO("Set NPUW_ATTN_HFA_FUSED to YES");
+ }
+}
+
void refine_dynamic_props(ov::AnyMap& llm_properties, const std::optional<NPUDesc>& npudesc) {
if (!npudesc) {
// No NPU device detected - no idea about the actual capabilities.
@@ -754,16 +785,7 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
refine_dynamic_props(npuw_llm_props, npudesc);
m_cfg.update(any_copy(npuw_llm_props));
- // Decide on using fused flash attention tile based on provided option and NPU capabilities.
- // If hardware supports and attention hint is set to HFA, then we can use fused flash attention implementation
- // automatically, unless user explicitly disables it via NPUW_ATTN_HFA_FUSED=NO option.
- const auto is_hfa =
- m_cfg.get<::intel_npu::NPUW_LLM_PREFILL_ATTENTION_HINT>() == ::intel_npu::npuw::llm::AttentionHint::HFA;
- const auto hfa_fused_npu_supported = npudesc.has_value() && npudesc->support_flash_attention_tile;
- if (other_props.count("NPUW_ATTN_HFA_FUSED") == 0 && is_hfa && hfa_fused_npu_supported) {
- other_props["NPUW_ATTN_HFA_FUSED"] = "YES";
- LOG_INFO("Set NPUW_ATTN_HFA_FUSED to YES");
- }
+ resolve_hfa_fused_attention(m_cfg, other_props, npudesc);
m_is_whisper = m_cfg.get<::intel_npu::NPUW_WHISPER>();
if (m_is_whisper) {