Skip to content

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

[NPUW] Fix position_ids Shape and KV Cache Name Issue for Qwen2.5 Omni Model (#30535)

Guoliang Shi666258669821
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 6d35a8bb37d..de0d4f5109f 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
@@ -414,7 +414,13 @@ void reshape_to_static(std::shared_ptr<ov::Model> model,
} else if (input_name.find("attention_mask") != std::string::npos) {
new_shape = ov::PartialShape({1, kvcache_size});
} else if (input_name.find("position_ids") != std::string::npos) {
- new_shape = ov::PartialShape({1, input_size});
+ const auto partial_shape_size = input.get_partial_shape().size();
+ // NB: Regular LLM uses 2D shapes, Qwen2.5 VL/Omni uses 3D shapes
+ // The first dimension (3) represents the three components of position encoding: time, height, and width
+ // enabling alignment across multimodal inputs like text, audio, and video
+ NPUW_ASSERT(partial_shape_size == 3u || partial_shape_size == 2u);
+ new_shape =
+ partial_shape_size == 3u ? ov::PartialShape({3, 1, input_size}) : ov::PartialShape({1, input_size});
} else {
const auto& partial_shape = input.get_partial_shape();
new_shape = partial_shape;
diff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.cpp b/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.cpp
index 5034be60e53..1bc4422bc59 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.cpp
@@ -247,11 +247,17 @@ void ov::npuw::LLMInferRequest::infer_generate(ov::SoPtr<ov::ITensor> input_ids,
LOG_DEBUG("Copying kv-cache from prefill to generate model.");
const std::size_t kStartOutputKVCacheLayers = 1u;
const auto& kvcache_compiled = m_kvcache_request->get_compiled_model();
+ // FIXME: Find only matching by names outputs and copy them, having previously checked that such inputs exist
for (std::size_t i = 0; i < kvcache_compiled->outputs().size() - 1; ++i) {
const auto& output_name = kvcache_compiled->outputs()[kStartOutputKVCacheLayers + i].get_any_name();
auto prefill_out_tensor = m_prefill_request->get_tensor(m_prefill_out_ports.at(output_name));
const auto& input_name = std::regex_replace(output_name, std::regex("present"), "past_key_values");
+ if (m_kvcache_in_ports.find(input_name) == m_kvcache_in_ports.end()) {
+ LOG_DEBUG("Input name " << input_name << " doesn't contain kv cache. Skipping.");
+ continue;
+ }
+
auto kvcache_in_tensor = m_kvcache_request->get_tensor(m_kvcache_in_ports.at(input_name));
// FIXME: We don't need to fill whole tensor with 0s, but only tensor.size() - num_stored_tokens
@@ -310,9 +316,15 @@ void ov::npuw::LLMInferRequest::infer_generate(ov::SoPtr<ov::ITensor> input_ids,
LOG_DEBUG("Write KV-cache for the new token to the correct input position for next iteration.");
const std::size_t kStartOutputKVCacheLayers = 1u;
const auto& kvcache_compiled = m_kvcache_request->get_compiled_model();
+ // FIXME: Find only matching by names outputs and copy them, having previously checked that such inputs exist
for (std::size_t i = 0; i < kvcache_compiled->outputs().size() - 1; ++i) {
const auto& output_name = kvcache_compiled->outputs()[kStartOutputKVCacheLayers + i].get_any_name();
const auto& input_name = std::regex_replace(output_name, std::regex("present"), "past_key_values");
+ if (m_kvcache_in_ports.find(input_name) == m_kvcache_in_ports.end()) {
+ LOG_DEBUG("Input name " << input_name << " doesn't contain kv cache. Skipping.");
+ continue;
+ }
+
auto kvcache_in_tensor = m_kvcache_request->get_tensor(m_kvcache_in_ports.at(input_name));
const auto& kv_dim = (output_name.find("value") != std::string::npos && kvcache_desc.v_tensors_transposed)
? 3u