Skip to content

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

[NPUW] Add Eagle3 (top-1) pipeline support with new I/O (#32494)

Guoliang Shi09e3db07413a
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 134534a1bf0..b13ecb83fa4 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
@@ -154,6 +154,7 @@ DEFINE_OPT(NPUW_LLM_ENABLE_PREFIX_CACHING, bool, false, npuw::llm::enable_prefix
DEFINE_OPT(NPUW_LLM_PREFIX_CACHING_BLOCK_SIZE, uint64_t, 256, npuw::llm::prefix_caching_block_size, RunTime);
DEFINE_OPT(NPUW_LLM_PREFIX_CACHING_MAX_NUM_BLOCKS, uint64_t, 128, npuw::llm::prefix_caching_max_num_blocks, RunTime);
DEFINE_OPT(NPUW_WHISPER, bool, false, npuw::whisper::enabled, RunTime);
+DEFINE_OPT(NPUW_EAGLE, bool, false, npuw::eagle::enabled, RunTime);
DEFINE_ANYMAP_OPT(NPUW_LLM_PREFILL_CONFIG, npuw::llm::prefill_config);
DEFINE_ANYMAP_OPT(NPUW_LLM_ADDITIONAL_PREFILL_CONFIG, npuw::llm::additional_prefill_config);
DEFINE_ANYMAP_OPT(NPUW_LLM_GENERATE_CONFIG, npuw::llm::generate_config);
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 3e56df01cdd..a7c008a5428 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
@@ -666,6 +666,16 @@ namespace whisper {
static constexpr ov::Property<bool> enabled{"NPUW_WHISPER"};
} // namespace whisper
+namespace eagle {
+/**
+ * @brief
+ * Type: bool.
+ * Tell NPUW that you want to pass Eagle3 model for speculative decoding.
+ * Default value: false.
+ */
+static constexpr ov::Property<bool> enabled{"NPUW_EAGLE"};
+} // namespace eagle
+
} // namespace npuw
} // namespace intel_npu
} // namespace ov
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 73075e39633..88d8e02df63 100644
--- a/src/plugins/intel_npu/src/al/src/config/npuw.cpp
+++ b/src/plugins/intel_npu/src/al/src/config/npuw.cpp
@@ -81,6 +81,7 @@ void intel_npu::registerNPUWLLMOptions(OptionsDesc& desc) {
desc.add<NPUW_LLM_GENERATE_ATTENTION_HINT>();
desc.add<NPUW_LLM_SHARED_HEAD>();
desc.add<NPUW_WHISPER>();
+ desc.add<NPUW_EAGLE>();
}
std::string ov::npuw::s11n::anyToString(const ov::Any& var) {
diff --git a/src/plugins/intel_npu/src/plugin/include/properties.hpp b/src/plugins/intel_npu/src/plugin/include/properties.hpp
index 438ccd716d1..87e4313eedd 100644
--- a/src/plugins/intel_npu/src/plugin/include/properties.hpp
+++ b/src/plugins/intel_npu/src/plugin/include/properties.hpp
@@ -138,7 +138,8 @@ private:
ov::intel_npu::npuw::llm::additional_generate_config.name(),
ov::intel_npu::npuw::llm::generate_attn_hint.name(),
ov::intel_npu::npuw::llm::shared_lm_head_config.name(),
- ov::intel_npu::npuw::llm::additional_shared_lm_head_config.name()};
+ ov::intel_npu::npuw::llm::additional_shared_lm_head_config.name(),
+ ov::intel_npu::npuw::eagle::enabled.name()};
const std::vector<ov::PropertyName> _internalSupportedProperties = {ov::internal::caching_properties.name(),
ov::internal::caching_with_mmap.name(),
diff --git a/src/plugins/intel_npu/src/plugin/npuw/infer_request_utils.cpp b/src/plugins/intel_npu/src/plugin/npuw/infer_request_utils.cpp
index d4e4ff66371..66fe11f1be0 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/infer_request_utils.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/infer_request_utils.cpp
@@ -20,6 +20,13 @@ ov::SoPtr<ov::ITensor> ov::npuw::util::make_tensor_slice(ov::SoPtr<ov::ITensor>
return ov::get_tensor_impl(ov::Tensor(ov::make_tensor(tensor), start_shape, end_shape));
}
+void ov::npuw::util::copy_to_right(const ov::SoPtr<ov::ITensor>& src, const ov::SoPtr<ov::ITensor>& dst) {
+ OPENVINO_ASSERT(src->get_byte_size() <= dst->get_byte_size());
+ std::copy_n(reinterpret_cast<uint8_t*>(src->data()),
+ src->get_byte_size(),
+ reinterpret_cast<uint8_t*>(dst->data()) + dst->get_byte_size() - src->get_byte_size());
+}
+
void ov::npuw::util::copy_by_planes(ov::SoPtr<ov::ITensor> src_tensor, ov::SoPtr<ov::ITensor> dst_tensor) {
// [1, H, S1, E] -> [1, H, S2, E]
const int N = 0;
diff --git a/src/plugins/intel_npu/src/plugin/npuw/infer_request_utils.hpp b/src/plugins/intel_npu/src/plugin/npuw/infer_request_utils.hpp
index 022d49b56a1..255ac0733ee 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/infer_request_utils.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/infer_request_utils.hpp
@@ -26,6 +26,8 @@ void copy_by_planes(ov::SoPtr<ov::ITensor> src_tensor, ov::SoPtr<ov::ITensor> ds
void copy_columns_by_row_chunks(ov::SoPtr<ov::ITensor> src, ov::SoPtr<ov::ITensor>& dst);
+void copy_to_right(const ov::SoPtr<ov::ITensor>& src, const ov::SoPtr<ov::ITensor>& dst);
+
void copy_tensor_by_dim(ov::SoPtr<ov::ITensor> src_tensor,
ov::SoPtr<ov::ITensor> dst_tensor,
uint32_t kv_dim_src,
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 1f98e0eea5f..8d56febd6f6 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
@@ -789,6 +789,17 @@ std::shared_ptr<ov::Model> redirect_new_kv_to_output(const std::shared_ptr<ov::M
for (std::size_t i = ov::npuw::LLMInferRequest::layer_ids::kStartOutputKVCacheLayers; i < model->outputs().size();
++i) {
auto kvout = model->output(i);
+
+ // Skip outputs that are not KV cache (e.g., last_hidden_state)
+ // KV cache outputs follow the pattern: present.{layer}.key or present.{layer}.value
+ const auto& output_name = kvout.get_any_name();
+ bool is_kv_cache =
+ (output_name.find("present") != std::string::npos) &&
+ (output_name.find("key") != std::string::npos || output_name.find("value") != std::string::npos);
+ if (!is_kv_cache) {
+ continue;
+ }
+
auto kvrslt = kvout.get_node();
auto kvcat = kvrslt->inputs()[0].get_source_output().get_node();
auto kvval = kvcat->inputs()[1].get_source_output();
@@ -831,6 +842,7 @@ void patch_phi3_sliding_mask(const std::shared_ptr<ov::Model>& model) {
model->validate_nodes_and_infer_types();
}
}
+
} // namespace
class CutLMHead : public ov::pass::MatcherPass {
@@ -971,6 +983,8 @@ void reshape_to_static(std::shared_ptr<ov::Model> model,
const auto& partial_shape = input.get_partial_shape();
new_shape = partial_shape;
new_shape[0] = 1; // batch_dim
+ } else if (ov::npuw::matchEagle3HiddenStatesString(input_name)) {
+ new_shape = ov::npuw::Eagle3Extension::get_static_input(model, input, input_size);
} else if (ov::npuw::util::matchLoRAMatMulAString(input_name)) {
new_shape = ov::PartialShape({lora_rank, input.get_partial_shape()[1]});
} else if (ov::npuw::util::matchLoRAMatMulAlphaString(input_name)) {
@@ -1447,6 +1461,7 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
ov::AnyMap other_props;
split_llm_properties(properties, npuw_llm_props, other_props);
auto use_whisper_key = pop_option(other_props, std::string("NPUW_WHISPER"));
+ auto use_eagle_key = pop_option(other_props, std::string("NPUW_EAGLE"));
// Solely used for serialization at the moment
m_non_llm_props = other_props;
@@ -1471,6 +1486,11 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
m_cfg.update({{"NPUW_LLM_OPTIMIZE_V_TENSORS", "NO"}});
}
+ m_is_eagle = use_eagle_key.value_or(false).as<bool>() == true;
+ if (m_is_eagle) {
+ LOG_INFO("Eagle3 speculative decoding mode enabled");
+ }
+
LOG_DEBUG("Creating kvcache model as clone of passed one.");
auto kvcache_model = model->clone();
LOG_DEBUG("Transform kvcache model from stateful to stateless.");
@@ -1916,6 +1936,7 @@ void ov::npuw::LLMCompiledModel::serialize(std::ostream& stream, const ov::npuw:
write(model_stream, m_prefix_caching_max_num_blocks);
write(model_stream, m_gemma_sliding_window_size);
write(model_stream, m_is_whisper);
+ write(model_stream, m_is_eagle);
// Write config
write(model_stream, m_cfg);
@@ -2140,6 +2161,7 @@ std::shared_ptr<ov::npuw::LLMCompiledModel> ov::npuw::LLMCompiledModel::deserial
read(model_stream, compiled->m_prefix_caching_max_num_blocks);
read(model_stream, compiled->m_gemma_sliding_window_size);
read(model_stream, compiled->m_is_whisper);
+ read(model_stream, compiled->m_is_eagle);
// Deserialize config
read(model_stream, compiled->m_cfg);
@@ -2255,6 +2277,7 @@ void ov::npuw::LLMCompiledModel::implement_properties() {
BIND(npuw::llm::prefill_attn_hint, NPUW_LLM_PREFILL_ATTENTION_HINT, getString),
BIND(npuw::llm::generate_attn_hint, NPUW_LLM_GENERATE_ATTENTION_HINT, getString),
BIND(npuw::llm::shared_lm_head, NPUW_LLM_SHARED_HEAD, get),
- BIND(npuw::whisper::enabled, NPUW_WHISPER, get)});
+ BIND(npuw::whisper::enabled, NPUW_WHISPER, get),
+ BIND(npuw::eagle::enabled, NPUW_EAGLE, get)});
#undef BIND
}
diff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.hpp b/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.hpp
index 6294881ca1e..7dd32994984 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_compiled_model.hpp
@@ -124,6 +124,8 @@ private:
void compile_generate_model_variants(const std::vector<std::shared_ptr<ov::Model>>& generate_model_variants,
const std::shared_ptr<const ov::IPlugin>& plugin,
const ov::AnyMap& generate_config);
+
+ bool m_is_eagle = false;
};
} // namespace npuw
diff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_eagle3_extension.cpp b/src/plugins/intel_npu/src/plugin/npuw/llm_eagle3_extension.cpp
new file mode 100644
index 00000000000..e6f04445943
--- /dev/null
+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_eagle3_extension.cpp
@@ -0,0 +1,204 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "llm_eagle3_extension.hpp"
+
+#include <algorithm>
+#include <cstring>
+
+#include "infer_request_utils.hpp"
+#include "logging.hpp"
+#include "openvino/runtime/make_tensor.hpp"
+#include "util.hpp"
+
+namespace ov {
+namespace npuw {
+
+bool matchEagle3HiddenStatesString(const std::string& input) {
+ return input == Eagle3LayerNames::hidden_states;
+}
+
+ov::PartialShape Eagle3Extension::get_static_input(const std::shared_ptr<ov::Model>& model,
+ const ov::Output<ov::Node>& input,
+ uint32_t input_size) {
+ const auto& input_name = input.get_any_name();
+ const auto& input_shape = input.get_partial_shape();
+
+ // Check if this is an Eagle3 hidden_states input
+ if (matchEagle3HiddenStatesString(input_name)) {
+ OPENVINO_ASSERT(input_shape.size() == 3u,
+ "Eagle3 hidden_states must have 3 dimensions: [batch, seq_len, hidden_size]");
+
+ if (input_shape[2].is_static()) {
+ return ov::PartialShape({1, input_size, input_shape[2]});
+ }
+
+ for (const auto& model_output : model->outputs()) {
+ if (model_output.get_any_name() == Eagle3LayerNames::last_hidden_state) {
+ const auto& output_shape = model_output.get_partial_shape();
+ OPENVINO_ASSERT(output_shape.size() == 3u,
+ "Eagle3 last_hidden_state must have 3 dimensions: [batch, seq_len, hidden_size]");
+ if (output_shape[2].is_static()) {
+ return ov::PartialShape({1, input_size, output_shape[2]});
+ }
+ }
+ }
+
+ OPENVINO_THROW("Eagle3 hidden_states hidden_size dimension is dynamic and "
+ "could not be inferred from last_hidden_state output");
+ }
+
+ return ov::PartialShape();
+}
+
+void Eagle3Extension::validate_hidden_state_tensor(const ov::SoPtr<ov::ITensor>& tensor, const std::string& name) {
+ OPENVINO_ASSERT(ov::element::f32 == tensor->get_element_type() || ov::element::f16 == tensor->get_element_type(),
+ name + " input must be float32 or float16");
+ OPENVINO_ASSERT(tensor->get_shape().size() == 3,
+ name + " input must have 3 dimensions: [batch, token_length, embedding_size]");
+}
+
+void Eagle3Extension::store_hidden_state_inputs(const ov::IInferRequest& request,
+ const std::vector<ov::Output<const ov::Node>>& inputs) {
+ // Only draft models need hidden state inputs
+ if (m_role != Eagle3ModelRole::Draft) {
+ return;
+ }
+
+ auto hidden_states_port = util::find_port_by_name(inputs, Eagle3LayerNames::hidden_states);
+ OPENVINO_ASSERT(hidden_states_port.has_value(),
+ "Eagle3 Draft model requires 'hidden_states' input to be provided by user");
+ auto hidden_states_tensor = request.get_tensor(hidden_states_port.value());
+ validate_hidden_state_tensor(hidden_states_tensor, "hidden_states");
+ m_hidden_states = hidden_states_tensor;
+}
+
+} // namespace npuw
+} // namespace ov
+
+namespace {
+
+void pad_hidden_state_input(const ov::SoPtr<ov::ITensor>& hidden_state,
+ const ov::SoPtr<ov::ITensor>& padded_hidden_state) {
+ // Pad the token_length dimension (dimension 1) of hidden state input [batch, token_length, embedding_size]
+ auto hidden_state_shape = hidden_state->get_shape();
+ auto padded_shape = padded_hidden_state->get_shape();
+ OPENVINO_ASSERT(hidden_state_shape.size() == 3,
+ "Hidden state input should have 3 dimensions: [batch, token_length, embedding_size]");
+ OPENVINO_ASSERT(padded_shape.size() == 3,
+ "Padded hidden state should have 3 dimensions: [batch, token_length, embedding_size]");
+
+ OPENVINO_ASSERT(hidden_state_shape[0] == 1, "Batch size must be 1 for Eagle3 hidden states");
+ OPENVINO_ASSERT(padded_shape[0] == 1, "Padded batch size must be 1 for Eagle3 hidden states");
+
+ OPENVINO_ASSERT(padded_shape[2] == hidden_state_shape[2], "Embedding size must match");
+ OPENVINO_ASSERT(padded_shape[1] >= hidden_state_shape[1], "Padded token length must be >= input token length");
+
+ // Zero-fill the padded tensor
+ ov::npuw::util::fill_tensor_bytes(padded_hidden_state, 0u);
+
+ // Copy hidden state data to the right side
+ ov::npuw::util::copy_to_right(hidden_state, padded_hidden_state);
+}
+
+} // anonymous namespace
+
+namespace ov {
+namespace npuw {
+
+void Eagle3Extension::initialize(bool is_eagle_model,
+ const std::unordered_map<std::string, ov::Output<const ov::Node>>& in_ports,
+ const std::unordered_map<std::string, ov::Output<const ov::Node>>& out_ports) {
+ if (!is_eagle_model) {
+ m_role = Eagle3ModelRole::None;
+ return;
+ }
+
+ // It's an Eagle3 model, now determine if it's Draft or Target based on inputs/outputs
+ bool has_hidden_states_input = in_ports.find(Eagle3LayerNames::hidden_states) != in_ports.end();
+ bool has_last_hidden_state_output = out_ports.find(Eagle3LayerNames::last_hidden_state) != out_ports.end();
+
+ if (has_hidden_states_input && has_last_hidden_state_output) {
+ m_role = Eagle3ModelRole::Draft;
+ LOG_INFO("Eagle3 Draft Model detected");
+ } else if (!has_hidden_states_input && has_last_hidden_state_output) {
+ m_role = Eagle3ModelRole::Target;
+ LOG_INFO("Eagle3 Target Model detected");
+ } else {
+ OPENVINO_THROW(
+ "Eagle3 mode enabled via NPUW_EAGLE property, but model structure doesn't match Draft or Target pattern. "
+ "Draft requires: hidden_states input + last_hidden_state output. "
+ "Target requires: last_hidden_state output only.");
+ }
+}
+
+void Eagle3Extension::prepare_inputs(const std::shared_ptr<ov::IAsyncInferRequest>& request,
+ const std::unordered_map<std::string, ov::Output<const ov::Node>>& in_ports) {
+ // Only draft models need to prepare Eagle3 inputs
+ if (m_role != Eagle3ModelRole::Draft) {
+ return;
+ }
+
+ auto hidden_states_it = in_ports.find(Eagle3LayerNames::hidden_states);
+ OPENVINO_ASSERT(hidden_states_it != in_ports.end(), "Eagle3 Draft model must have hidden_states input port");
+ OPENVINO_ASSERT(m_hidden_states, "Eagle3 Draft model requires hidden_states input tensor to be provided");
+ auto padded_hidden_states = request->get_tensor(hidden_states_it->second);
+ pad_hidden_state_input(m_hidden_states, padded_hidden_states);
+}
+
+void Eagle3Extension::update_last_hidden_state(
+ const std::shared_ptr<ov::IAsyncInferRequest>& request,
+ const std::unordered_map<std::string, ov::Output<const ov::Node>>& out_ports) {
+ auto last_hidden_state_it = out_ports.find(Eagle3LayerNames::last_hidden_state);
+ OPENVINO_ASSERT(last_hidden_state_it != out_ports.end(), "Eagle3 model must have last_hidden_state output port");
+
+ m_last_hidden_state = request->get_tensor(last_hidden_state_it->second);
+
+ LOG_VERB("Eagle3 " << (m_role == Eagle3ModelRole::Draft ? "Draft" : "Target")
+ << ": Retrieved last_hidden_state output tensor");
+}
+
+void Eagle3Extension::prepare_inputs_for_chunk(
+ const std::shared_ptr<ov::IAsyncInferRequest>& request,
+ const std::unordered_map<std::string, ov::Output<const ov::Node>>& in_ports,
+ uint32_t chunk_start_token,
+ uint32_t chunk_token_count) {
+ // Only draft models need chunk-specific input preparation
+ if (m_role != Eagle3ModelRole::Draft) {
+ return;
+ }
+
+ OPENVINO_ASSERT(chunk_token_count > 0, "Chunk token count must be greater than 0");
+ OPENVINO_ASSERT(m_hidden_states, "Eagle3 Draft model requires hidden_states input tensor to be provided");
+
+ auto hidden_states_it = in_ports.find(Eagle3LayerNames::hidden_states);
+ OPENVINO_ASSERT(hidden_states_it != in_ports.end(), "Eagle3 Draft model must have hidden_states input port");
+
+ auto padded_tensor = request->get_tensor(hidden_states_it->second);
+
+ // Get original tensor shape: [batch, seq_len, embedding_size]
+ const auto& original_shape = m_hidden_states->get_shape();
+ OPENVINO_ASSERT(original_shape.size() == 3,
+ "hidden_states tensor must have 3 dimensions: [batch, seq_len, embedding_size]");
+
+ constexpr uint32_t seq_dim = 1;
+ uint32_t total_tokens = static_cast<uint32_t>(original_shape[seq_dim]);
+
+ // Validate chunk boundaries
+ OPENVINO_ASSERT(chunk_start_token < total_tokens,
+ "chunk_start_token (" + std::to_string(chunk_start_token) + ") must be less than total_tokens (" +
+ std::to_string(total_tokens) + ")");
+
+ uint32_t chunk_end_token = std::min(chunk_start_token + chunk_token_count, total_tokens);
+
+ // Create tensor slice for current chunk along the sequence dimension
+ auto chunk_tensor = util::make_tensor_slice(m_hidden_states, seq_dim, chunk_start_token, chunk_end_token);
+
+ pad_hidden_state_input(chunk_tensor, padded_tensor);
+ LOG_VERB("Eagle3 Draft: Set hidden_states chunk [" << chunk_start_token << ":" << chunk_end_token
+ << "] for chunk processing");
+}
+
+} // namespace npuw
+} // namespace ov
diff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_eagle3_extension.hpp b/src/plugins/intel_npu/src/plugin/npuw/llm_eagle3_extension.hpp
new file mode 100644
index 00000000000..59df5649930
--- /dev/null
+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_eagle3_extension.hpp
@@ -0,0 +1,97 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <algorithm>
+#include <memory>
+#include <optional>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "infer_request_utils.hpp"
+#include "openvino/core/descriptor/output.hpp"
+#include "openvino/runtime/iasync_infer_request.hpp"
+#include "openvino/runtime/itensor.hpp"
+
+namespace ov {
+namespace npuw {
+
+// Layer names for Eagle3 speculative decoding
+struct Eagle3LayerNames {
+ static constexpr const char* hidden_states = "hidden_states";
+ static constexpr const char* last_hidden_state = "last_hidden_state";
+};
+
+// Utility functions for Eagle3 layer name matching
+bool matchEagle3HiddenStatesString(const std::string& input);
+
+// Model roles for Eagle3 speculative decoding
+enum class Eagle3ModelRole {
+ None, ///< Not an Eagle3 model
+ Target, ///< Target model: only outputs last_hidden_state
+ Draft ///< Draft model: has hidden_states as input, and outputs last_hidden_state
+};
+
+// Extension for Eagle3 speculative decoding
+// Handles Eagle3-specific input/output logic for draft and target models
+class Eagle3Extension {
+public:
+ // Get static shape for Eagle3 input tensors
+ static ov::PartialShape get_static_input(const std::shared_ptr<ov::Model>& model,
+ const ov::Output<ov::Node>& input,
+ uint32_t input_size);
+
+ // Detect Eagle3 model role (Draft/Target/None) based on is_eagle flag and inputs/outputs
+ void initialize(bool is_eagle_model,
+ const std::unordered_map<std::string, ov::Output<const ov::Node>>& in_ports,
+ const std::unordered_map<std::string, ov::Output<const ov::Node>>& out_ports);
+
+ // Returns true if model is Eagle3 draft or target
+ bool is_eagle3_model() const {
+ return m_role != Eagle3ModelRole::None;
+ }
+
+ Eagle3ModelRole get_role() const {
+ return m_role;
+ }
+
+ // Store hidden state inputs from user request (must be called before prepare_inputs/prepare_inputs_for_chunk)
+ void store_hidden_state_inputs(const ov::IInferRequest& request,
+ const std::vector<ov::Output<const ov::Node>>& inputs);
+
+ // Prepare Eagle3 new input tensors (hidden_states)
+ void prepare_inputs(const std::shared_ptr<ov::IAsyncInferRequest>& request,
+ const std::unordered_map<std::string, ov::Output<const ov::Node>>& in_ports);
+
+ // Prepare Eagle3 new input tensors for chunked prefill
+ void prepare_inputs_for_chunk(const std::shared_ptr<ov::IAsyncInferRequest>& request,
+ const std::unordered_map<std::string, ov::Output<const ov::Node>>& in_ports,
+ uint32_t chunk_start_token,
+ uint32_t chunk_token_count);
+
+ // Retrieve and store last_hidden_state output tensor for draft and target models
+ void update_last_hidden_state(const std::shared_ptr<ov::IAsyncInferRequest>& request,
+ const std::unordered_map<std::string, ov::Output<const ov::Node>>& out_ports);
+
+ ov::SoPtr<ov::ITensor> get_hidden_states() const {
+ return m_hidden_states;
+ }
+
+ ov::SoPtr<ov::ITensor> get_last_hidden_state() const {
+ return m_last_hidden_state;
+ }
+
+private:
+ void validate_hidden_state_tensor(const ov::SoPtr<ov::ITensor>& tensor, const std::string& name);
+
+ Eagle3ModelRole m_role = Eagle3ModelRole::None;
+
+ ov::SoPtr<ov::ITensor> m_hidden_states; ///< Draft model input: hidden_states
+ ov::SoPtr<ov::ITensor> m_last_hidden_state; ///< Draft/Target model output: last_hidden_state
+};
+
+} // namespace npuw
+} // namespace ov
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 6f7be566497..863bf60ec56 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
@@ -123,13 +123,6 @@ std::pair<uint32_t, uint32_t> get_lora_dims_by_name(const std::string& state_nam
return std::make_pair(low_rank_dim, full_rank_dim);
}
-void copy_to_right(const ov::SoPtr<ov::ITensor>& src, const ov::SoPtr<ov::ITensor>& dst) {
- OPENVINO_ASSERT(src->get_byte_size() <= dst->get_byte_size());
- std::copy_n(reinterpret_cast<uint8_t*>(src->data()),
- src->get_byte_size(),
- reinterpret_cast<uint8_t*>(dst->data()) + dst->get_byte_size() - src->get_byte_size());
-}
-
void fill_sliding_mask(const ov::SoPtr<ov::ITensor>& mask, int64_t curr_pos, int64_t window_size) {
auto start = curr_pos - window_size;
auto end = curr_pos;
@@ -198,6 +191,8 @@ ov::npuw::LLMInferRequest::LLMInferRequest(const std::shared_ptr<ov::npuw::LLMCo
init_pre_alloc_device();
init_lora_states();
+ m_eagle3_ext.initialize(m_npuw_llm_compiled_model->m_is_eagle, m_prefill_in_ports, m_prefill_out_ports);
+
const bool use_chunk_prefill = m_npuw_llm_compiled_model->m_use_chunk_prefill;
if (use_chunk_prefill) {
// FIXME: enable w/o chunking as well. Although need to align the paddings beforehand
@@ -816,6 +811,13 @@ void ov::npuw::LLMInferRequest::infer_chunked_prefill(ov::SoPtr<ov::ITensor> inp
// Copy with proper stride handling
actual_position_ids_slice->copy_to(pos_ids_slice._ptr);
+ if (m_eagle3_ext.is_eagle3_model()) {
+ m_eagle3_ext.prepare_inputs_for_chunk(m_prefill_request,
+ m_prefill_in_ports,
+ kvcache_desc.num_stored_tokens,
+ static_cast<uint32_t>(current_prompts_len));
+ }
+
// Update history size for dynamic context:
// dynamic attention selector needs history size to determin the past KV shape and attention mask shape
m_prefill_base_request->update_history_size(kvcache_desc.num_stored_tokens);
@@ -882,12 +884,16 @@ void ov::npuw::LLMInferRequest::infer_whole_prefill(ov::SoPtr<ov::ITensor> input
auto padded_token_type_ids = m_prefill_request->get_tensor(m_prefill_in_ports.at(layer_names::token_type_ids));
std::fill_n(reinterpret_cast<uint8_t*>(padded_token_type_ids->data()), token_type_ids->get_byte_size(), 0);
- copy_to_right(token_type_ids, padded_token_type_ids);
+ 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));
pad_position_ids(padded_position_ids, position_ids);
+ if (m_eagle3_ext.is_eagle3_model()) {
+ m_eagle3_ext.prepare_inputs(m_prefill_request, m_prefill_in_ports);
+ }
+
m_prefill_request->infer();
auto& kvcache_desc = m_npuw_llm_compiled_model->m_kvcache_desc;
kvcache_desc.num_stored_tokens += static_cast<uint32_t>(input_ids->get_shape()[layer_ids::INPUT_IDS_SEQ_LEN_DIM]);
@@ -931,6 +937,10 @@ void ov::npuw::LLMInferRequest::infer_prefill(ov::SoPtr<ov::ITensor> input_ids,
m_logits = m_prefill_request->get_tensor(m_prefill_out_ports.at(layer_names::logits));
}
+ if (m_eagle3_ext.is_eagle3_model()) {
+ m_eagle3_ext.update_last_hidden_state(m_prefill_request, m_prefill_out_ports);
+ }
+
m_generate_initialized = false;
LOG_DEBUG("Done");
@@ -998,7 +1008,7 @@ void ov::npuw::LLMInferRequest::infer_generate(ov::SoPtr<ov::ITensor> input_ids,
if (token_type_ids) {
auto kv_token_type_ids = m_kvcache_request->get_tensor(m_kvcache_in_ports.at(layer_names::token_type_ids));
- copy_to_right(token_type_ids, kv_token_type_ids);
+ util::copy_to_right(token_type_ids, kv_token_type_ids);
}
// NOTE: Attention mask pattern for generate model requires the set of "1"
@@ -1019,6 +1029,10 @@ void ov::npuw::LLMInferRequest::infer_generate(ov::SoPtr<ov::ITensor> input_ids,
auto kv_pos_ids = m_kvcache_request->get_tensor(m_kvcache_in_ports.at(layer_names::position_ids));
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);
+ }
+
m_kvcache_request->infer();
kvcache_desc.num_stored_tokens += input_tokens_len;
@@ -1048,6 +1062,10 @@ void ov::npuw::LLMInferRequest::infer_generate(ov::SoPtr<ov::ITensor> input_ids,
m_logits = m_kvcache_request->get_tensor(m_kvcache_out_ports.at(layer_names::logits));
}
+ if (m_eagle3_ext.is_eagle3_model()) {
+ m_eagle3_ext.update_last_hidden_state(m_kvcache_request, m_kvcache_out_ports);
+ }
+
LOG_DEBUG("Done");
}
@@ -1072,6 +1090,9 @@ void ov::npuw::LLMInferRequest::infer() {
OPENVINO_ASSERT(ov::element::i64 == attention_mask->get_element_type());
OPENVINO_ASSERT(ov::element::i64 == position_ids->get_element_type());
+ // Eagle3: Accept and validate hidden state inputs
+ m_eagle3_ext.store_hidden_state_inputs(*this, inputs);
+
if (m_first_run) {
// Most of the models have position_ids->data<int64_t>()[0] == 0 for the first infer
// But gemma3 has it == 1
@@ -1120,10 +1141,25 @@ void ov::npuw::LLMInferRequest::infer() {
}
ov::SoPtr<ov::ITensor> ov::npuw::LLMInferRequest::get_tensor(const ov::Output<const ov::Node>& port) const {
- // NB: If asked for logits...
- if (port == get_outputs()[0]) {
+ const auto& port_names = port.get_names();
+
+ if (port_names.count("logits") > 0) {
+ if (!m_logits) {
+ OPENVINO_THROW("Logits tensor is not available. Please run inference first.");
+ }
return m_logits;
}
+
+ if (m_eagle3_ext.is_eagle3_model()) {
+ if (port_names.count(Eagle3LayerNames::last_hidden_state) > 0) {
+ auto last_hidden_state = m_eagle3_ext.get_last_hidden_state();
+ if (!last_hidden_state) {
+ OPENVINO_THROW("Last hidden state tensor is not available. Please run inference first.");
+ }
+ return last_hidden_state;
+ }
+ }
+
return ov::ISyncInferRequest::get_tensor(port);
}
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 a586a2eb47b..7609ce68ce6 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
@@ -8,6 +8,7 @@
#include "base_sync_infer_request.hpp"
#include "llm_compiled_model.hpp"
+#include "llm_eagle3_extension.hpp"
#include "llm_lora_states.hpp"
#include "llm_prefix_caching.hpp"
#include "openvino/core/descriptor/output.hpp"
@@ -143,6 +144,9 @@ protected:
uint64_t m_tokens_in_present_chunk = 0;
+ // Support Eagle3 speculative decoding
+ Eagle3Extension m_eagle3_ext;
+
// Support LoRA
std::vector<ov::SoPtr<ov::IVariableState>> m_variableStates;
void init_lora_states();
diff --git a/src/plugins/intel_npu/src/plugin/npuw/serialization.hpp b/src/plugins/intel_npu/src/plugin/npuw/serialization.hpp
index 155980ea98a..53fc4b45f6e 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/serialization.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/serialization.hpp
@@ -34,7 +34,7 @@ const constexpr ov::npuw::s11n::IndicatorType NPUW_COMPILED_MODEL_INDICATOR =
const constexpr ov::npuw::s11n::IndicatorType NPUW_LLM_COMPILED_MODEL_INDICATOR =
{char{0x4c}, char{0x4c}, char{0x4d}, char{0x43}, char{0x4d}, char{0x4f}};
-const constexpr char* NPUW_SERIALIZATION_VERSION = "0.15";
+const constexpr char* NPUW_SERIALIZATION_VERSION = "0.16";
// Forward declaration
namespace intel_npu {
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
index fbba6d79e8c..7f17a22afb2 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
@@ -382,6 +382,7 @@ void Plugin::init_options() {
REGISTER_OPTION(NPUW_LLM_PREFIX_CACHING_BLOCK_SIZE);
REGISTER_OPTION(NPUW_LLM_PREFIX_CACHING_MAX_NUM_BLOCKS);
REGISTER_OPTION(NPUW_WHISPER);
+ REGISTER_OPTION(NPUW_EAGLE);
REGISTER_OPTION(NPUW_LLM_PREFILL_HINT);
REGISTER_OPTION(NPUW_LLM_PREFILL_CONFIG);
REGISTER_OPTION(NPUW_LLM_ADDITIONAL_PREFILL_CONFIG);
diff --git a/src/plugins/intel_npu/src/plugin/src/properties.cpp b/src/plugins/intel_npu/src/plugin/src/properties.cpp
index c47ba4df611..0174830de75 100644
--- a/src/plugins/intel_npu/src/plugin/src/properties.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/properties.cpp
@@ -486,6 +486,7 @@ void Properties::registerPluginProperties() {
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::llm::additional_shared_lm_head_config,
NPUW_LLM_ADDITIONAL_SHARED_LM_HEAD_CONFIG);
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::whisper::enabled, NPUW_WHISPER);
+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::npuw::eagle::enabled, NPUW_EAGLE);
// 2. Metrics (static device and enviroment properties)
// ========