Skip to content

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

[NPUW] Support for granite-4.0-h-micro (#36556)

Anastasiya(Asya) Proninac899536ea60e
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 d8f46f52580..822c0162e13 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
@@ -359,6 +359,16 @@ ov::npuw::LLMInferRequest::LLMInferRequest(const std::shared_ptr<ov::npuw::LLMCo
}
}
+ // NOTE: Granite-4.0-h-micro uses no Positional Encoding, it doesn't need it because
+ // Mamba inherently preserves information about the order of tokens.
+ if (m_prefill_in_ports.find(layer_names::position_ids) == m_prefill_in_ports.end()) {
+ m_position_ids_present = false;
+ for (const auto& variant : m_generate_variant_in_ports) {
+ OPENVINO_ASSERT(variant.second.find(layer_names::position_ids) == variant.second.end(),
+ "Generate model variant unexpectedly has position_ids port while prefill hasn't!");
+ }
+ }
+
init_past_name_lists();
m_swa_cache = std::make_unique<SwaKVCacheHelper>(*this, m_npuw_llm_compiled_model->m_swa_window_size);
@@ -704,7 +714,10 @@ void ov::npuw::LLMInferRequest::zero_prefill_staging() {
uu::fill_tensor_bytes(m_prefill_request->get_tensor(type_ids_port->second), 0u);
}
uu::fill_tensor<int64_t>(m_prefill_request->get_tensor(m_prefill_in_ports.at(layer_names::attention_mask)), 0);
- uu::fill_tensor<int64_t>(m_prefill_request->get_tensor(m_prefill_in_ports.at(layer_names::position_ids)), 0);
+
+ if (m_position_ids_present) {
+ uu::fill_tensor<int64_t>(m_prefill_request->get_tensor(m_prefill_in_ports.at(layer_names::position_ids)), 0);
+ }
// Gemma4: Clear per_layer_inputs if present
if (auto per_layer_port = m_prefill_in_ports.find(layer_names::per_layer_inputs);
@@ -1095,7 +1108,10 @@ void ov::npuw::LLMInferRequest::infer_chunked_prefill(ov::SoPtr<ov::ITensor> inp
}
auto attn_mask_in_tensor = m_prefill_request->get_tensor(m_prefill_in_ports.at(layer_names::attention_mask));
- auto pos_ids_in_tensor = m_prefill_request->get_tensor(m_prefill_in_ports.at(layer_names::position_ids));
+ ov::SoPtr<ov::ITensor> pos_ids_in_tensor;
+ if (m_position_ids_present) {
+ pos_ids_in_tensor = m_prefill_request->get_tensor(m_prefill_in_ports.at(layer_names::position_ids));
+ }
const auto token_type_ids_it = m_prefill_in_ports.find(layer_names::token_type_ids);
const bool has_token_type_ids = token_type_ids_it != m_prefill_in_ports.end();
@@ -1180,28 +1196,30 @@ void ov::npuw::LLMInferRequest::infer_chunked_prefill(ov::SoPtr<ov::ITensor> inp
reinterpret_cast<uint8_t*>(input_ids_in_tensor->data()) + input_ids_in_tensor->get_byte_size() -
current_prefill_bytes);
- // NB: Regular LLM uses 2D position_ids [BATCH, SEQ_LEN], Qwen2.5 VL/Omni, Qwen3.5 VL use 3D position_ids
- // [3, BATCH, SEQ_LEN]
- // Copy postion ids with considering the 3D position_ids
- // The caller tensor is delta-relative during a continued prefill.
- auto last_dim = position_ids->get_shape().size() - 1;
- const uint32_t pos_src_offset = kvcache_desc.num_stored_tokens - m_continued_prefill_base;
- auto actual_position_ids_slice =
- ov::npuw::util::make_tensor_slice(position_ids,
- static_cast<uint32_t>(last_dim),
- pos_src_offset,
- pos_src_offset + static_cast<uint32_t>(current_prompts_len));
-
- auto pos_ids_slice =
- ov::npuw::util::make_tensor_slice(pos_ids_in_tensor,
- static_cast<uint32_t>(last_dim),
- static_cast<uint32_t>(chunk_prompt_len - current_prompts_len),
- static_cast<uint32_t>(chunk_prompt_len));
-
- // Copy with proper stride handling
- NPUW_ASSERT(pos_ids_slice._ptr &&
- "null slice of position IDs tensor — source tensor may be uninitialized or have wrong shape");
- actual_position_ids_slice->copy_to(pos_ids_slice._ptr);
+ if (m_position_ids_present) {
+ // NB: Regular LLM uses 2D position_ids [BATCH, SEQ_LEN], Qwen2.5 VL/Omni, Qwen3.5 VL use 3D
+ // position_ids [3, BATCH, SEQ_LEN] Copy postion ids with considering the 3D position_ids The caller
+ // tensor is delta-relative during a continued prefill.
+ auto last_dim = position_ids->get_shape().size() - 1;
+ const uint32_t pos_src_offset = kvcache_desc.num_stored_tokens - m_continued_prefill_base;
+ auto actual_position_ids_slice =
+ ov::npuw::util::make_tensor_slice(position_ids,
+ static_cast<uint32_t>(last_dim),
+ pos_src_offset,
+ pos_src_offset + static_cast<uint32_t>(current_prompts_len));
+
+ auto pos_ids_slice =
+ ov::npuw::util::make_tensor_slice(pos_ids_in_tensor,
+ static_cast<uint32_t>(last_dim),
+ static_cast<uint32_t>(chunk_prompt_len - current_prompts_len),
+ static_cast<uint32_t>(chunk_prompt_len));
+
+ // Copy with proper stride handling
+ NPUW_ASSERT(
+ pos_ids_slice._ptr &&
+ "null slice of position IDs tensor — source tensor may be uninitialized or have wrong shape");
+ actual_position_ids_slice->copy_to(pos_ids_slice._ptr);
+ }
// DeepStack (Qwen3-VL): scatter only the visual tokens that fall into the current
// chunk. The chunk's visual_pos_masks slice gives their chunk-local positions, and
@@ -1354,8 +1372,10 @@ void ov::npuw::LLMInferRequest::infer_whole_prefill(ov::SoPtr<ov::ITensor> input
util::copy_to_right(token_type_ids, padded_token_type_ids);
}
- auto padded_position_ids = m_prefill_request->get_tensor(m_prefill_in_ports.at(layer_names::position_ids));
- ov::npuw::util::pad_position_ids(padded_position_ids, position_ids);
+ if (m_position_ids_present) {
+ auto padded_position_ids = m_prefill_request->get_tensor(m_prefill_in_ports.at(layer_names::position_ids));
+ ov::npuw::util::pad_position_ids(padded_position_ids, position_ids);
+ }
if (const auto deepstack_it = m_prefill_in_ports.find(layer_names::deepstack_visual_embeds);
deepstack_it != m_prefill_in_ports.end()) {
@@ -1644,8 +1664,11 @@ void ov::npuw::LLMInferRequest::infer_generate(ov::SoPtr<ov::ITensor> input_ids,
uu::fill_tensor_bytes(m_kvcache_request->get_tensor(m_kvcache_in_ports.at(m_input_ids_name)), 0u);
uu::fill_tensor<int64_t>(m_kvcache_request->get_tensor(m_kvcache_in_ports.at(layer_names::attention_mask)),
0);
- uu::fill_tensor<int64_t>(m_kvcache_request->get_tensor(m_kvcache_in_ports.at(layer_names::position_ids)),
- 0);
+ if (m_position_ids_present) {
+ uu::fill_tensor<int64_t>(
+ m_kvcache_request->get_tensor(m_kvcache_in_ports.at(layer_names::position_ids)),
+ 0);
+ }
m_generate_initialized = true;
}
@@ -1734,8 +1757,10 @@ void ov::npuw::LLMInferRequest::infer_generate(ov::SoPtr<ov::ITensor> input_ids,
}
std::fill_n(kv_attn_mask->data<int64_t>() + kv_attn_mask->get_size() - input_tokens_len, input_tokens_len, 1);
- auto kv_pos_ids = m_kvcache_request->get_tensor(m_kvcache_in_ports.at(layer_names::position_ids));
- ov::npuw::util::pad_position_ids(kv_pos_ids, position_ids);
+ if (m_position_ids_present) {
+ auto kv_pos_ids = m_kvcache_request->get_tensor(m_kvcache_in_ports.at(layer_names::position_ids));
+ ov::npuw::util::pad_position_ids(kv_pos_ids, position_ids);
+ }
if (m_eagle3_ext.is_eagle3_model()) {
m_eagle3_ext.prepare_inputs(m_kvcache_request, m_kvcache_in_ports);
diff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.hpp b/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.hpp
index ba7e1616826..c7d88b1ccc3 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_infer_request.hpp
@@ -36,6 +36,7 @@ struct LLMPortNameRegistrationTestAccess;
struct LLMContinuedPrefillTestAccess;
struct LLMLongRopeModeTestAccess;
struct LLMSwaCacheTestAccess;
+struct LLMNoPositionIdsTestAccess;
} // namespace npuw
} // namespace test
} // namespace ov
@@ -224,6 +225,7 @@ protected:
// coefficients. Meaningless for models without LongRoPE, where it stays false.
bool m_longrope_long_mode = false;
+ bool m_position_ids_present = true;
int64_t m_first_position_id = 0;
uint64_t m_tokens_in_present_chunk = 0;
@@ -278,6 +280,7 @@ protected:
friend struct ov::test::npuw::LLMContinuedPrefillTestAccess;
friend struct ov::test::npuw::LLMLongRopeModeTestAccess;
friend struct ov::test::npuw::LLMSwaCacheTestAccess;
+ friend struct ov::test::npuw::LLMNoPositionIdsTestAccess;
};
} // namespace npuw
diff --git a/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/cut_lm_head.cpp b/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/cut_lm_head.cpp
index c3dcbdd63d9..d4b8dfc5e08 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/cut_lm_head.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/cut_lm_head.cpp
@@ -49,15 +49,17 @@ public:
// Matmul -> Convert -> Result
auto matmul_convert = opp::wrap_type<ov::op::v0::Convert>({matmul});
// MatMul -> Divide -> Tanh -> Multiply -> Result
- auto div = opp::wrap_type<ov::op::v1::Multiply, ov::op::v1::Divide>({matmul, opp::any_input()});
- auto tanh = opp::wrap_type<ov::op::v0::Tanh>({div});
+ // MatMul -> Divide -> Result (Granite-4.0-h-micro)
+ auto matmul_divide = opp::wrap_type<ov::op::v1::Multiply, ov::op::v1::Divide>({matmul, opp::any_input()});
+ auto tanh = opp::wrap_type<ov::op::v0::Tanh>({matmul_divide});
auto matmul_multiply = opp::wrap_type<ov::op::v1::Multiply>({tanh, opp::any_input()});
auto last_op = std::make_shared<opp::op::Or>(ov::OutputVector{matmul->output(0),
matmul_add->output(0),
matmul_transpose->output(0),
matmul_convert->output(0),
- matmul_multiply->output(0)});
+ matmul_multiply->output(0),
+ matmul_divide->output(0)});
auto res = opp::wrap_type<ov::op::v0::Result>({last_op->output(0)});
auto callback = [=, &lm_head_model](opp::Matcher& m) {
@@ -69,7 +71,8 @@ public:
std::static_pointer_cast<ov::op::v0::Result>(node_to_output.at(res).get_node_shared_ptr());
std::shared_ptr<ov::Node> matched_node_last_op = matched_matmul;
- for (const auto& p : {matmul_add, matmul_transpose, matmul_convert, matmul_multiply}) {
+ // matmul_divide must be checked after matmul_multiply, as divide is a part of the multiply chain too.
+ for (const auto& p : {matmul_add, matmul_transpose, matmul_convert, matmul_multiply, matmul_divide}) {
const auto it = node_to_output.find(p);
if (it != node_to_output.end()) {
matched_node_last_op = it->second.get_node_shared_ptr();
diff --git a/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/insert_vocab_sub128.cpp b/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/insert_vocab_sub128.cpp
index 6690868f91b..82a1d57fc03 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/insert_vocab_sub128.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/insert_vocab_sub128.cpp
@@ -54,14 +54,15 @@ public:
const auto matmul_add = opp::wrap_type<ov::op::v1::Add>({matmul, opp::any_input()});
const auto matmul_transpose = opp::wrap_type<ov::op::v1::Transpose>({matmul, opp::any_input()});
const auto matmul_convert = opp::wrap_type<ov::op::v0::Convert>({matmul});
- const auto div = opp::wrap_type<ov::op::v1::Multiply, ov::op::v1::Divide>({matmul, opp::any_input()});
- const auto tanh = opp::wrap_type<ov::op::v0::Tanh>({div});
+ const auto matmul_divide = opp::wrap_type<ov::op::v1::Multiply, ov::op::v1::Divide>({matmul, opp::any_input()});
+ const auto tanh = opp::wrap_type<ov::op::v0::Tanh>({matmul_divide});
const auto matmul_multiply = opp::wrap_type<ov::op::v1::Multiply>({tanh, opp::any_input()});
const auto lm_head_output = std::make_shared<opp::op::Or>(ov::OutputVector{matmul->output(0),
matmul_add->output(0),
matmul_transpose->output(0),
matmul_convert->output(0),
- matmul_multiply->output(0)});
+ matmul_multiply->output(0),
+ matmul_divide->output(0)});
const auto result = opp::wrap_type<ov::op::v0::Result>({lm_head_output->output(0)});
auto callback = [=](opp::Matcher& matcher) {
diff --git a/src/plugins/intel_npu/tests/unit/CMakeLists.txt b/src/plugins/intel_npu/tests/unit/CMakeLists.txt
index 7a7f0a57642..0be0744a202 100644
--- a/src/plugins/intel_npu/tests/unit/CMakeLists.txt
+++ b/src/plugins/intel_npu/tests/unit/CMakeLists.txt
@@ -196,6 +196,7 @@ target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/npuw/stored_tokens_state_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_infer_request_variant_switch_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_infer_request_port_names_test.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_infer_request_no_position_ids_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_trim_kvcache_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/sliding_window_manager_update_kv_cache_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/sliding_window_manager_generate_mask_test.cpp
diff --git a/src/plugins/intel_npu/tests/unit/npuw/gather_sub128_matcher_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/gather_sub128_matcher_test.cpp
index f5bfa81d75d..0efec67b5ed 100644
--- a/src/plugins/intel_npu/tests/unit/npuw/gather_sub128_matcher_test.cpp
+++ b/src/plugins/intel_npu/tests/unit/npuw/gather_sub128_matcher_test.cpp
@@ -4,25 +4,25 @@
#include <gtest/gtest.h>
+#include <algorithm>
#include <array>
#include <cstdint>
#include <map>
#include <memory>
-#include <algorithm>
#include <optional>
#include <string>
#include <tuple>
#include <vector>
-#include "lazy_tensor.hpp"
#include "intel_npu/config/npuw.hpp"
+#include "lazy_tensor.hpp"
#include "npuw_transformations/insert_vocab_sub128.hpp"
#include "openvino/core/graph_util.hpp"
#include "openvino/core/preprocess/pre_post_process.hpp"
#include "openvino/opsets/opset10.hpp"
#include "openvino/pass/graph_rewrite.hpp"
-#include "partitioning/patterns/opt.hpp"
#include "partitioning/partitioning.hpp"
+#include "partitioning/patterns/opt.hpp"
#include "transformations/rt_info/decompression.hpp"
namespace {
@@ -76,8 +76,7 @@ std::shared_ptr<ov::Model> make_parameter_gather_model(std::optional<float> weig
constexpr std::size_t hidden_size = 2048;
auto ids = std::make_shared<ov::opset10::Parameter>(ov::element::i32, ov::Shape{1, 1});
auto weights = std::make_shared<ov::opset10::Parameter>(weight_type, ov::Shape{vocab_size, hidden_size});
- auto zero_point =
- std::make_shared<ov::opset10::Parameter>(zero_point_type, ov::Shape{vocab_size, hidden_size});
+ auto zero_point = std::make_shared<ov::opset10::Parameter>(zero_point_type, ov::Shape{vocab_size, hidden_size});
auto scale = std::make_shared<ov::opset10::Parameter>(ov::element::f16, ov::Shape{vocab_size, hidden_size});
auto axis = ov::opset10::Constant::create(ov::element::i32, ov::Shape{}, {0});
@@ -139,17 +138,20 @@ bool run_host_gather(const std::shared_ptr<ov::Model>& model, ov::npuw::patterns
return rewrite.run_on_model(model);
}
-enum class VocabMatMulTerminal { Add, Transpose, Convert, Gated };
+enum class VocabMatMulTerminal { Add, Transpose, Convert, Gated, Divide };
std::shared_ptr<ov::Model> make_vocab_matmul_model(bool convert_before_matmul,
std::optional<VocabMatMulTerminal> terminal = std::nullopt,
std::size_t vocab_size = 4) {
auto hidden = std::make_shared<ov::opset10::Parameter>(ov::element::f32, ov::Shape{1, 2});
- auto weights = ov::opset10::Constant::create(ov::element::u8, ov::Shape{vocab_size, 2}, std::vector<uint8_t>(vocab_size * 2, 200));
+ auto weights = ov::opset10::Constant::create(ov::element::u8,
+ ov::Shape{vocab_size, 2},
+ std::vector<uint8_t>(vocab_size * 2, 200));
auto zero_point =
ov::opset10::Constant::create(ov::element::u8, ov::Shape{vocab_size, 1}, std::vector<uint8_t>(vocab_size, 128));
const auto scale_type = convert_before_matmul ? ov::element::f16 : ov::element::f32;
- auto scale = ov::opset10::Constant::create(scale_type, ov::Shape{vocab_size, 1}, std::vector<float>(vocab_size, 1.0f));
+ auto scale =
+ ov::opset10::Constant::create(scale_type, ov::Shape{vocab_size, 1}, std::vector<float>(vocab_size, 1.0f));
auto weight_convert = std::make_shared<ov::opset10::Convert>(weights, scale_type);
weight_convert->set_friendly_name("vocab_weight_convert");
auto zero_point_convert = std::make_shared<ov::opset10::Convert>(zero_point, scale_type);
@@ -163,7 +165,9 @@ std::shared_ptr<ov::Model> make_vocab_matmul_model(bool convert_before_matmul,
auto matmul = std::make_shared<ov::opset10::MatMul>(hidden, matmul_weights, false, true);
ov::Output<ov::Node> output = matmul;
if (terminal == VocabMatMulTerminal::Add) {
- auto bias = ov::opset10::Constant::create(ov::element::f32, ov::Shape{1, vocab_size}, std::vector<float>(vocab_size, 1.0f));
+ auto bias = ov::opset10::Constant::create(ov::element::f32,
+ ov::Shape{1, vocab_size},
+ std::vector<float>(vocab_size, 1.0f));
output = std::make_shared<ov::opset10::Add>(matmul, bias);
} else if (terminal == VocabMatMulTerminal::Transpose) {
auto order = ov::opset10::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});
@@ -176,17 +180,24 @@ std::shared_ptr<ov::Model> make_vocab_matmul_model(bool convert_before_matmul,
auto tanh = std::make_shared<ov::opset10::Tanh>(div);
auto multiplier = ov::opset10::Constant::create(ov::element::f32, ov::Shape{}, {2.0f});
output = std::make_shared<ov::opset10::Multiply>(tanh, multiplier);
+ } else if (terminal == VocabMatMulTerminal::Divide) {
+ auto divisor = ov::opset10::Constant::create(ov::element::f32, ov::Shape{}, {2.0f});
+ output = std::make_shared<ov::opset10::Divide>(matmul, divisor);
}
return std::make_shared<ov::Model>(ov::OutputVector{output}, ov::ParameterVector{hidden});
}
-std::shared_ptr<ov::Model> make_pretransposed_vocab_matmul_model(bool convert_before_matmul, std::size_t vocab_size = 4) {
+std::shared_ptr<ov::Model> make_pretransposed_vocab_matmul_model(bool convert_before_matmul,
+ std::size_t vocab_size = 4) {
auto hidden = std::make_shared<ov::opset10::Parameter>(ov::element::f32, ov::Shape{1, 2});
- auto weights = ov::opset10::Constant::create(ov::element::u8, ov::Shape{2, vocab_size}, std::vector<uint8_t>(vocab_size * 2, 200));
+ auto weights = ov::opset10::Constant::create(ov::element::u8,
+ ov::Shape{2, vocab_size},
+ std::vector<uint8_t>(vocab_size * 2, 200));
auto zero_point =
ov::opset10::Constant::create(ov::element::u8, ov::Shape{1, vocab_size}, std::vector<uint8_t>(vocab_size, 128));
const auto scale_type = convert_before_matmul ? ov::element::f16 : ov::element::f32;
- auto scale = ov::opset10::Constant::create(scale_type, ov::Shape{1, vocab_size}, std::vector<float>(vocab_size, 1.0f));
+ auto scale =
+ ov::opset10::Constant::create(scale_type, ov::Shape{1, vocab_size}, std::vector<float>(vocab_size, 1.0f));
auto weight_convert = std::make_shared<ov::opset10::Convert>(weights, scale_type);
weight_convert->set_friendly_name("vocab_weight_convert");
auto zero_point_convert = std::make_shared<ov::opset10::Convert>(zero_point, scale_type);
@@ -377,8 +388,8 @@ public:
TEST_P(InsertVocabSub128PrePostProcessingTest, PreservesVocabularyConverts) {
const auto [pretransposed_layout, convert_before_matmul] = GetParam();
- const auto model = pretransposed_layout ? make_pretransposed_vocab_matmul_model(convert_before_matmul) :
- make_vocab_matmul_model(convert_before_matmul);
+ const auto model = pretransposed_layout ? make_pretransposed_vocab_matmul_model(convert_before_matmul)
+ : make_vocab_matmul_model(convert_before_matmul);
EXPECT_TRUE(ov::npuw::InsertVocabSub128().run_on_model(model));
EXPECT_EQ(count_subtracts(model), 3u);
EXPECT_EQ(count_sub128_shifts(model), 2u);
@@ -401,14 +412,13 @@ TEST_P(InsertVocabSub128PrePostProcessingTest, PreservesVocabularyConverts) {
EXPECT_TRUE(contains_node(model, "vocab_zero_point_convert"));
}
-INSTANTIATE_TEST_SUITE_P(
- LayoutAndConversion,
- InsertVocabSub128PrePostProcessingTest,
- ::testing::Values(std::make_tuple(false, false),
- std::make_tuple(false, true),
- std::make_tuple(true, false),
- std::make_tuple(true, true)),
- InsertVocabSub128PrePostProcessingTest::getTestCaseName);
+INSTANTIATE_TEST_SUITE_P(LayoutAndConversion,
+ InsertVocabSub128PrePostProcessingTest,
+ ::testing::Values(std::make_tuple(false, false),
+ std::make_tuple(false, true),
+ std::make_tuple(true, false),
+ std::make_tuple(true, true)),
+ InsertVocabSub128PrePostProcessingTest::getTestCaseName);
class InsertVocabSub128LmHeadTerminalTest : public ::testing::TestWithParam<VocabMatMulTerminal> {
public:
@@ -422,6 +432,8 @@ public:
return "Convert";
case VocabMatMulTerminal::Gated:
return "Gated";
+ case VocabMatMulTerminal::Divide:
+ return "Divide";
}
return "Unknown";
}
@@ -440,7 +452,8 @@ INSTANTIATE_TEST_SUITE_P(LmHeadTerminal,
::testing::Values(VocabMatMulTerminal::Add,
VocabMatMulTerminal::Transpose,
VocabMatMulTerminal::Convert,
- VocabMatMulTerminal::Gated),
+ VocabMatMulTerminal::Gated,
+ VocabMatMulTerminal::Divide),
InsertVocabSub128LmHeadTerminalTest::getTestCaseName);
TEST(InsertVocabSub128LmHeadTerminalTest, SkipsManuallyAddedOutput) {
@@ -496,5 +509,3 @@ TEST(LazySubtract128Test, RejectsNonU8Input) {
EXPECT_THROW(shifted.eval(), ov::Exception);
EXPECT_THROW(shifted.eval_meta(), ov::Exception);
}
-
-
diff --git a/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_graph_options_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_graph_options_test.cpp
index 0a20680fde4..d21fe8956ae 100644
--- a/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_graph_options_test.cpp
+++ b/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_graph_options_test.cpp
@@ -13,6 +13,8 @@
#include <vector>
#include "llm_test_helpers.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/divide.hpp"
#include "openvino/op/slice.hpp"
#include "openvino/pass/stateful_to_stateless.hpp"
@@ -111,6 +113,21 @@ protected:
std::shared_ptr<ov::IPlugin> m_plugin;
};
+// Granite-4.0-h-micro style head: MatMul -> Divide -> Result
+std::shared_ptr<ov::Model> build_divide_head_llm_model() {
+ auto model = ov::test::npuw::build_llm_test_model();
+ for (const auto& result : model->get_results()) {
+ if (result->output(0).get_names().count("logits") == 0) {
+ continue;
+ }
+ const auto matmul_out = result->input_value(0);
+ const auto divisor = ov::op::v0::Constant::create(matmul_out.get_element_type(), ov::Shape{}, {8.0f});
+ result->input(0).replace_source_output(std::make_shared<ov::op::v1::Divide>(matmul_out, divisor));
+ }
+ model->validate_nodes_and_infer_types();
+ return model;
+}
+
TEST_F(LLMCompiledModelGraphOptionsTest, SparseMoEPreservesExpertFoldingForSmallModels) {
RecordingFactory recorder;
auto props = base_props();
@@ -150,6 +167,29 @@ TEST_F(LLMCompiledModelGraphOptionsTest, SharedHeadAddsHeadModelAndSlicesPrefill
EXPECT_GE(count_ops<ov::op::v8::Slice>(prefill->model), 1u);
}
+TEST_F(LLMCompiledModelGraphOptionsTest, SharedHeadWithDivideTerminalKeepsDivideInHead) {
+ RecordingFactory recorder;
+ auto props = base_props();
+ merge_props(props, {{"NPUW_LLM_SHARED_HEAD", "YES"}, {"NPUW_LLM_MAX_GENERATION_TOKEN_LEN", "8"}});
+
+ std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;
+ ASSERT_NO_THROW(compiled = std::make_unique<ov::npuw::LLMCompiledModel>(build_divide_head_llm_model(),
+ m_plugin,
+ props,
+ recorder.make_factory()));
+ ASSERT_NE(compiled, nullptr);
+
+ const auto* prefill = recorder.find_suffix("_prefill");
+ const auto* lm_head = recorder.find_suffix("_lm_head");
+ ASSERT_NE(prefill, nullptr);
+ ASSERT_NE(lm_head, nullptr);
+
+ // Head was split: the prefill exposes the embeddings cut point.
+ EXPECT_TRUE(find_output(prefill->model, ov::npuw::LLMCompiledModel::layer_names::output_embeds).has_value());
+ // The direct-Divide terminal moved into the extracted LM-head model.
+ EXPECT_GE(count_ops<ov::op::v1::Divide>(lm_head->model), 1u);
+}
+
TEST_F(LLMCompiledModelGraphOptionsTest, PromptResponseAndGenerationLengthsDriveStaticShapes) {
RecordingFactory recorder;
std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;
diff --git a/src/plugins/intel_npu/tests/unit/npuw/llm_infer_request_no_position_ids_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/llm_infer_request_no_position_ids_test.cpp
new file mode 100644
index 00000000000..3b12eebf4f1
--- /dev/null
+++ b/src/plugins/intel_npu/tests/unit/npuw/llm_infer_request_no_position_ids_test.cpp
@@ -0,0 +1,240 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <gtest/gtest.h>
+
+#include <algorithm>
+#include <cstdint>
+#include <cstring>
+#include <memory>
+#include <numeric>
+#include <string>
+#include <vector>
+
+#include "executor.hpp"
+#include "llm_compiled_model.hpp"
+#include "llm_infer_request.hpp"
+#include "llm_test_helpers.hpp"
+#include "openvino/openvino.hpp"
+#include "util.hpp"
+
+namespace ov::test::npuw {
+
+struct LLMNoPositionIdsTestAccess {
+ using Request = ov::npuw::LLMInferRequest;
+
+ static bool position_ids_present(const Request& req) {
+ return req.m_position_ids_present;
+ }
+};
+
+} // namespace ov::test::npuw
+
+namespace {
+
+using ov::test::npuw::build_llm_test_model;
+using ov::test::npuw::build_llm_test_model_without_position_ids;
+using ov::test::npuw::LLMNoPositionIdsTestAccess;
+using ov::test::npuw::NullPlugin;
+class FakeSubCompiledModel;
+
+class FakeSubInferRequest final : public ov::ISyncInferRequest {
+public:
+ explicit FakeSubInferRequest(std::shared_ptr<const FakeSubCompiledModel> compiled_model);
+
+ void infer() override;
+ ov::SoPtr<ov::ITensor> get_tensor(const ov::Output<const ov::Node>& port) const override {
+ return ov::ISyncInferRequest::get_tensor(port);
+ }
+ void set_tensor(const ov::Output<const ov::Node>& port, const ov::SoPtr<ov::ITensor>& tensor) override {
+ ov::ISyncInferRequest::set_tensor(port, tensor);
+ }
+ void check_tensors() const override {}
+ std::vector<ov::SoPtr<ov::IVariableState>> query_state() const override {
+ return {};
+ }
+ std::vector<ov::ProfilingInfo> get_profiling_info() const override {
+ return {};
+ }
+};
+
+class FakeSubCompiledModel final : public ov::npuw::ICompiledModel_v0 {
+public:
+ FakeSubCompiledModel(const std::shared_ptr<ov::Model>& model,
+ const std::shared_ptr<const ov::IPlugin>& plugin,
+ const ov::AnyMap&)
+ : ov::npuw::ICompiledModel_v0(model, plugin),
+ m_model(model) {}
+
+ void export_model(std::ostream&) const override {}
+ std::shared_ptr<const ov::Model> get_runtime_model() const override {
+ return m_model;
+ }
+ void set_property(const ov::AnyMap&) override {}
+ ov::Any get_property(const std::string&) const override {
+ return {};
+ }
+ std::shared_ptr<ov::ISyncInferRequest> create_sync_infer_request() const override {
+ auto self = std::static_pointer_cast<const FakeSubCompiledModel>(shared_from_this());
+ return std::make_shared<FakeSubInferRequest>(std::move(self));
+ }
+ std::shared_ptr<ov::npuw::IBaseInferRequest> create_base_infer_request() const override {
+ return {};
+ }
+ std::shared_ptr<ov::IAsyncInferRequest> wrap_async_infer_request(
+ std::shared_ptr<ov::npuw::IBaseInferRequest>) const override {
+ return std::make_shared<ov::IAsyncInferRequest>(create_sync_infer_request(),
+ intel_npu::make_executor("no_position_ids_task", 1),
+ intel_npu::make_executor("no_position_ids_callback", 1));
+ }
+ std::string submodel_device(std::size_t) const override {
+ return "CPU";
+ }
+ std::size_t num_submodels() const override {
+ // One CPU submodel, so init_pre_alloc_device() resolves to CPU staging
+ // instead of requesting NPU remote tensors from the stub plugin.
+ return 1;
+ }
+ std::shared_ptr<ov::npuw::weights::Bank> get_weights_bank() const override {
+ return {};
+ }
+ void set_weights_bank(std::shared_ptr<ov::npuw::weights::Bank>) override {}
+ void finalize_weights_bank() override {}
+ void reconstruct_closure() override {}
+ void serialize(std::ostream&, const ov::npuw::s11n::CompiledContext&) const override {}
+
+private:
+ std::shared_ptr<ov::Model> m_model;
+};
+
+FakeSubInferRequest::FakeSubInferRequest(std::shared_ptr<const FakeSubCompiledModel> compiled_model)
+ : ov::ISyncInferRequest(std::move(compiled_model)) {
+ for (const auto& input : get_compiled_model()->inputs()) {
+ ov::ISyncInferRequest::set_tensor(input,
+ ov::get_tensor_impl(ov::Tensor(input.get_element_type(), input.get_shape())));
+ }
+ for (const auto& output : get_compiled_model()->outputs()) {
+ ov::ISyncInferRequest::set_tensor(
+ output,
+ ov::get_tensor_impl(ov::Tensor(output.get_element_type(), output.get_shape())));
+ }
+}
+
+void FakeSubInferRequest::infer() {
+ for (const auto& output : get_compiled_model()->outputs()) {
+ auto tensor = ov::ISyncInferRequest::get_tensor(output);
+ std::memset(tensor->data(), 0, tensor->get_byte_size());
+ }
+}
+
+class NoPositionIdsFactory {
+public:
+ ov::npuw::LLMCompiledModel::CompiledModelFactory make_factory() {
+ return [](const std::shared_ptr<ov::Model>& model,
+ const std::shared_ptr<const ov::IPlugin>& plugin,
+ const ov::AnyMap& props) -> std::shared_ptr<ov::npuw::ICompiledModel_v0> {
+ return std::make_shared<FakeSubCompiledModel>(model, plugin, props);
+ };
+ }
+};
+
+ov::Tensor make_i64(std::initializer_list<size_t> shape, int64_t fill_value) {
+ ov::Tensor tensor(ov::element::i64, ov::Shape(shape));
+ std::fill_n(tensor.data<int64_t>(), tensor.get_size(), fill_value);
+ return tensor;
+}
+
+class LLMNoPositionIdsTest : public ::testing::Test {
+protected:
+ void build(const std::shared_ptr<ov::Model>& model, const ov::AnyMap& extra_props = {}) {
+ m_plugin = std::make_shared<NullPlugin>();
+ NoPositionIdsFactory factory;
+ ov::AnyMap props{{"NPUW_LLM", "YES"},
+ {"NPUW_DEVICES", "CPU"},
+ {"NPUW_LLM_MAX_PROMPT_LEN", "256"},
+ {"NPUW_LLM_MIN_RESPONSE_LEN", "64"},
+ {"NPUW_LLM_PREFILL_HINT", "DYNAMIC"},
+ {"NPUW_LLM_PREFILL_CHUNK_SIZE", "32"}};
+ for (const auto& kv : extra_props) {
+ props[kv.first] = kv.second;
+ }
+ m_compiled = std::make_shared<ov::npuw::LLMCompiledModel>(model, m_plugin, props, factory.make_factory());
+ ASSERT_NE(m_compiled, nullptr);
+ m_request = std::make_unique<ov::npuw::LLMInferRequest>(m_compiled);
+ ASSERT_NE(m_request, nullptr);
+ }
+
+ bool has_input(const std::string& name) {
+ return ov::npuw::util::find_port_by_name(m_request->get_inputs(), name).has_value();
+ }
+
+ void set_input(const std::string& name, const ov::Tensor& tensor) {
+ m_request->set_tensor(ov::npuw::util::find_port_by_name(m_request->get_inputs(), name).value(),
+ ov::get_tensor_impl(tensor));
+ }
+
+ ov::SoPtr<ov::ITensor> logits() {
+ return m_request->get_tensor(ov::npuw::util::find_port_by_name(m_request->get_outputs(), "logits").value());
+ }
+
+ std::shared_ptr<ov::IPlugin> m_plugin;
+ std::shared_ptr<ov::npuw::LLMCompiledModel> m_compiled;
+ std::unique_ptr<ov::npuw::LLMInferRequest> m_request;
+};
+
+// A NoPE model has no position_ids Parameter, so the request must flag its
+// absence and expose no position_ids input port.
+TEST_F(LLMNoPositionIdsTest, NoPositionIdsModelSetsFlagFalse) {
+ build(build_llm_test_model_without_position_ids());
+ EXPECT_FALSE(LLMNoPositionIdsTestAccess::position_ids_present(*m_request));
+ EXPECT_FALSE(has_input("position_ids"));
+}
+
+// Positive control: a standard RoPE model keeps the position_ids port and flag.
+TEST_F(LLMNoPositionIdsTest, PositionIdsModelSetsFlagTrue) {
+ build(build_llm_test_model());
+ EXPECT_TRUE(LLMNoPositionIdsTestAccess::position_ids_present(*m_request));
+ EXPECT_TRUE(has_input("position_ids"));
+}
+
+// A full chunked prefill followed by a generate step must run end-to-end without
+// touching the absent position_ids port, synthesizing positions internally.
+TEST_F(LLMNoPositionIdsTest, PrefillAndGenerateRunWithoutPositionIds) {
+ build(build_llm_test_model_without_position_ids());
+ ASSERT_FALSE(has_input("position_ids"));
+
+ // Multi-chunk prompt (72 tokens over a chunk size of 32) exercises the
+ // chunked-prefill loop where the position_ids tensor fetch is hoisted.
+ constexpr size_t kPromptLen = 72u;
+ set_input("input_ids", make_i64({1, kPromptLen}, 1));
+ set_input("attention_mask", make_i64({1, kPromptLen}, 1));
+ ASSERT_NO_THROW(m_request->infer());
+ ASSERT_NE(logits(), nullptr);
+
+ // Generate step: a single token with the history exposed in the mask.
+ set_input("input_ids", make_i64({1, 1}, 1));
+ set_input("attention_mask", make_i64({1, kPromptLen + 1}, 1));
+ ASSERT_NO_THROW(m_request->infer());
+ EXPECT_NE(logits(), nullptr);
+}
+
+// Static prefill (no chunking) must also run end-to-end without position_ids,
+// exercising the whole-prefill guard in infer_whole_prefill.
+TEST_F(LLMNoPositionIdsTest, PrefillAndGenerateRunWithoutPositionIdsStaticPrefill) {
+ build(build_llm_test_model_without_position_ids(), {{"NPUW_LLM_PREFILL_HINT", "STATIC"}});
+ ASSERT_FALSE(has_input("position_ids"));
+
+ constexpr size_t kPromptLen = 72u;
+ set_input("input_ids", make_i64({1, kPromptLen}, 1));
+ set_input("attention_mask", make_i64({1, kPromptLen}, 1));
+ ASSERT_NO_THROW(m_request->infer());
+ ASSERT_NE(logits(), nullptr);
+
+ set_input("input_ids", make_i64({1, 1}, 1));
+ set_input("attention_mask", make_i64({1, kPromptLen + 1}, 1));
+ ASSERT_NO_THROW(m_request->infer());
+ EXPECT_NE(logits(), nullptr);
+}
+
+} // namespace
diff --git a/src/plugins/intel_npu/tests/unit/npuw/llm_test_helpers.hpp b/src/plugins/intel_npu/tests/unit/npuw/llm_test_helpers.hpp
index fcc7179fcd4..1daf9df4704 100644
--- a/src/plugins/intel_npu/tests/unit/npuw/llm_test_helpers.hpp
+++ b/src/plugins/intel_npu/tests/unit/npuw/llm_test_helpers.hpp
@@ -63,6 +63,19 @@ inline std::shared_ptr<ov::Model> build_longrope_llm_test_model(int64_t context_
return mb.build_llm(cfg);
}
+/// Build an LLM test model with no position_ids input, mirroring models with NoPE
+/// such as granite-4.0-h-micro. An identity RoPE leaves setup_position_ids with
+/// no RoPE Range pattern, so the builder creates no position_ids Parameter and
+/// AddPositionIdsParam stays a no-op during compilation.
+inline std::shared_ptr<ov::Model> build_llm_test_model_without_position_ids() {
+ auto cfg = make_test_model_config();
+ cfg.rope = [](const ov::Output<ov::Node>& x, const std::string&) {
+ return x;
+ };
+ ModelBuilder mb;
+ return mb.build_llm(cfg);
+}
+
/// Build an LLM test model configured so that Attention::from() can unambiguously
/// identify the past-KV dimension in the isolated attention function body.
///