Skip to content

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

[NPUW] Continuous prefill: propose/grant protocol and capability (#37147)

Dylan Neve149a41af909a
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/config/npuw_option_defs.inc b/src/plugins/intel_npu/src/al/include/intel_npu/config/npuw_option_defs.inc
index 081be721abc..184749fbe6f 100644
--- a/src/plugins/intel_npu/src/al/include/intel_npu/config/npuw_option_defs.inc
+++ b/src/plugins/intel_npu/src/al/include/intel_npu/config/npuw_option_defs.inc
@@ -68,6 +68,7 @@ INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_LLM_OPTIMIZE_FP8, bool, false, ov::intel_npu::npu
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_LLM_ENABLE_PREFIX_CACHING, bool, false, ov::intel_npu::npuw::llm, enable_prefix_caching, "NPUW_LLM_ENABLE_PREFIX_CACHING", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_LLM_PREFIX_CACHING_BLOCK_SIZE, uint64_t, 256, ov::intel_npu::npuw::llm, prefix_caching_block_size, "NPUW_LLM_PREFIX_CACHING_BLOCK_SIZE", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_LLM_PREFIX_CACHING_MAX_NUM_BLOCKS, uint64_t, 128, ov::intel_npu::npuw::llm, prefix_caching_max_num_blocks, "NPUW_LLM_PREFIX_CACHING_MAX_NUM_BLOCKS", LLM, EXPOSED, CACHED, ALL)
+INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_LLM_ENABLE_CONTINUOUS_PREFILL, bool, false, ov::intel_npu::npuw::llm, enable_continuous_prefill, "NPUW_LLM_ENABLE_CONTINUOUS_PREFILL", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_LLM_CACHE_ROPE, bool, true, ov::intel_npu::npuw::llm, cache_rope, "NPUW_LLM_CACHE_ROPE", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_LLM_ENABLE_BLOCK_BASED_KV_CACHE, bool, false, ov::intel_npu::npuw::llm, enable_block_based_kv_cache, "NPUW_LLM_ENABLE_BLOCK_BASED_KV_CACHE", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_STRING_ENUM_OPT(NPUW_LLM_PREFILL_MOE_HINT, ::intel_npu::npuw::llm::MoEHint, MoEHintOptionTraits, ov::intel_npu::npuw::llm, prefill_moe_hint, "NPUW_LLM_PREFILL_MOE_HINT", LLM, EXPOSED, CACHED, ALL)
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 6b8c668f200..c7f88928df2 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
@@ -22,6 +22,18 @@ namespace ov::intel_npu::npuw {
inline constexpr ov::Property<ov::FileHandleProvider> weights_handle_provider{"NPUW_WEIGHTS_HANDLE_PROVIDER"};
+namespace llm {
+
+// Read-only compiled-model capability: continuous prefill is active for this
+// compiled model. Not a config option, so it is declared by hand rather than
+// generated from npuw_option_defs.inc. GenAI probes it by name; capability must
+// not be inferred from query_state() containing npuw_stored_tokens_state, which
+// every plugin build publishes.
+inline constexpr ov::Property<bool, ov::PropertyMutability::RO> continuous_prefill_supported{
+ "NPUW_LLM_CONTINUOUS_PREFILL_SUPPORTED"};
+
+} // namespace llm
+
} // namespace ov::intel_npu::npuw
#define INTEL_NPU_NPUW_DECLARE_PROPERTY_ALIAS(OPT, NS_PATH, NAME) \
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 93125976c06..b0ce321ec93 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
@@ -8,6 +8,7 @@
#include "embedding/prepare_embedding_model.hpp"
#include "embedding/redirect_new_kv_to_output.hpp"
#include "embedding/remove_empty_kv_inputs.hpp"
+#include "infer_request_utils.hpp"
#include "llm_compiled_model_utils.hpp"
#include "llm_infer_request.hpp"
#include "logging.hpp"
@@ -802,6 +803,21 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
}
}
+ // Continuous prefill is opt-in and mutually exclusive with the hash prefix cache.
+ // The prefix cache restore step unconditionally overwrites num_stored_tokens and
+ // its helper hashes absolute token positions of a full prompt. Neither holds under
+ // the delta-input contract, so the combination fails compilation instead of
+ // silently misbehaving, mirroring the block-KV and prefix-caching exclusion.
+ m_enable_continuous_prefill = m_cfg.get<::intel_npu::NPUW_LLM_ENABLE_CONTINUOUS_PREFILL>();
+ if (m_enable_continuous_prefill) {
+ OPENVINO_ASSERT(!m_cfg.get<::intel_npu::NPUW_LLM_ENABLE_PREFIX_CACHING>(),
+ "NPUW_LLM_ENABLE_CONTINUOUS_PREFILL and NPUW_LLM_ENABLE_PREFIX_CACHING "
+ "cannot be enabled simultaneously. Continuous prefill receives delta-only "
+ "inputs which the hash prefix cache cannot process. "
+ "Please disable one of the two options.");
+ LOG_INFO("Continuous prefill is enabled");
+ }
+
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};
@@ -1282,6 +1298,13 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
}
implement_properties();
+
+ if (m_enable_continuous_prefill && !compute_continuous_prefill_supported()) {
+ LOG_WARN("NPUW_LLM_ENABLE_CONTINUOUS_PREFILL is set, but continuous prefill is not "
+ "supported for this compiled model. NPUW_LLM_CONTINUOUS_PREFILL_SUPPORTED "
+ "reports false and full-history behaviour stays in effect.");
+ }
+
LOG_DEBUG("Done");
}
@@ -1613,6 +1636,8 @@ std::shared_ptr<ov::npuw::LLMCompiledModel> ov::npuw::LLMCompiledModel::deserial
// Deserialize config
stream & compiled->m_cfg;
compiled->implement_properties();
+ // Not serialized. Recomputed from the deserialized config so older blobs stay loadable.
+ compiled->m_enable_continuous_prefill = compiled->m_cfg.get<::intel_npu::NPUW_LLM_ENABLE_CONTINUOUS_PREFILL>();
// Deserialize KV cache model variants
stream & compiled->m_kvcache_sizes;
@@ -1670,6 +1695,63 @@ void ov::npuw::LLMCompiledModel::set_property(const ov::AnyMap& properties) {
OPENVINO_NOT_IMPLEMENTED;
}
+bool ov::npuw::LLMCompiledModel::compute_continuous_prefill_supported() const {
+ // Static exclusions for continuous prefill. Every condition here is knowable at
+ // compile or import time. Per-turn limits like capacity, alignment and the
+ // watermark are applied dynamically by the propose/grant channel instead.
+ if (!m_enable_continuous_prefill) {
+ return false; // opt-in feature
+ }
+ if (!m_use_chunk_prefill) {
+ return false; // whole (STATIC) prefill has no continuation path
+ }
+ if (m_is_whisper || m_is_embedding || m_is_eagle) {
+ return false; // out of scope pipelines
+ }
+ if (m_longrope_context_limit > 0u) {
+ return false; // LongRoPE threshold can be crossed mid-generation
+ }
+ OPENVINO_ASSERT(m_prefill_compiled, "Continuous prefill probe requires a compiled prefill model.");
+ const auto& prefill_inputs = m_prefill_compiled->inputs();
+ for (const auto& input : prefill_inputs) {
+ // A port can carry several names, so every one of them must clear the
+ // exclusions; get_any_name() could return one that hides a match.
+ for (const auto& name : input.get_names()) {
+ if (ov::npuw::util::starts_with_past_lincache(name)) {
+ return false; // linear/hybrid state has no generate->prefill path
+ }
+ if (ov::npuw::util::matchLoRAMatMulAString(name) || ov::npuw::util::matchLoRAMatMulBString(name) ||
+ ov::npuw::util::matchLoRAMatMulAlphaString(name)) {
+ return false; // adapter change is only detected after the caller sliced
+ }
+ if (name == ov::npuw::LLMInferRequest::layer_names::inputs_embeds) {
+ return false; // VLM is out of scope in v1
+ }
+ if (name == ov::npuw::LLMInferRequest::layer_names::token_type_ids) {
+ return false; // token type ids are not routed through a continued prefill
+ }
+ }
+ }
+ // Position ids must form a single linear sequence: 3-D M-RoPE cannot be validated
+ // as a contiguous continuation and is excluded statically. A read-only property
+ // must never throw, so a dynamic rank is treated as unsupported rather than
+ // queried through PartialShape::size(), which asserts a static rank.
+ const auto position_ids_port =
+ ov::npuw::util::find_port_by_name(prefill_inputs, ov::npuw::LLMInferRequest::layer_names::position_ids);
+ if (!position_ids_port.has_value()) {
+ return false;
+ }
+ const auto& position_ids_rank = position_ids_port.value().get_partial_shape().rank();
+ if (position_ids_rank.is_dynamic() || position_ids_rank.get_length() >= 3) {
+ return false;
+ }
+ // Every static exclusion above passed, but this change carries the protocol only:
+ // nothing attaches the coordinator to the variable state yet, so a proposal would
+ // throw. A capability the request cannot honour must never be advertised, so the
+ // answer stays false until the delta prefill path lands and lifts this.
+ return false;
+}
+
ov::Any ov::npuw::LLMCompiledModel::get_property(const std::string& name) const {
OPENVINO_SUPPRESS_DEPRECATED_START
if (name == ov::intel_npu::npuw::llm::prefill_config.name() ||
@@ -1677,6 +1759,10 @@ ov::Any ov::npuw::LLMCompiledModel::get_property(const std::string& name) const
OPENVINO_THROW(name, " is write-only option!");
}
+ if (name == ov::intel_npu::npuw::llm::continuous_prefill_supported.name()) {
+ return compute_continuous_prefill_supported();
+ }
+
auto&& configIterator = m_prop_to_opt.find(name);
if (configIterator != m_prop_to_opt.cend()) {
return std::get<1>(configIterator->second)(m_cfg);
@@ -1737,6 +1823,7 @@ void ov::npuw::LLMCompiledModel::implement_properties() {
BIND(npuw::llm::optimize_fp8, NPUW_LLM_OPTIMIZE_FP8, get),
BIND(npuw::llm::cache_rope, NPUW_LLM_CACHE_ROPE, get),
BIND(npuw::llm::enable_block_based_kv_cache, NPUW_LLM_ENABLE_BLOCK_BASED_KV_CACHE, get),
+ BIND(npuw::llm::enable_continuous_prefill, NPUW_LLM_ENABLE_CONTINUOUS_PREFILL, get),
BIND(npuw::llm::prefill_moe_hint, NPUW_LLM_PREFILL_MOE_HINT, get),
BIND(npuw::llm::generate_moe_hint, NPUW_LLM_GENERATE_MOE_HINT, get),
BIND(npuw::llm::generate_pyramid, NPUW_LLM_GENERATE_PYRAMID, get),
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 c903dd94ae4..fa5785b0d75 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
@@ -136,6 +136,13 @@ private:
uint64_t m_prefix_caching_max_num_blocks = 0;
uint64_t m_longrope_context_limit = 0;
+ // Continuous prefill support. Opted in via NPUW_LLM_ENABLE_CONTINUOUS_PREFILL and
+ // mutually exclusive with hash prefix caching, which fails compilation.
+ bool m_enable_continuous_prefill = false;
+ // Computes the NPUW_LLM_CONTINUOUS_PREFILL_SUPPORTED read-only property from
+ // compiled model state. Not serialized, recomputed identically after import.
+ bool compute_continuous_prefill_supported() const;
+
// Friend declarations for PrefixCachingHelper to access protected members
friend class PrefixCachingHelper;
diff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_continuation.hpp b/src/plugins/intel_npu/src/plugin/npuw/llm_continuation.hpp
new file mode 100644
index 00000000000..5302b3b923a
--- /dev/null
+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_continuation.hpp
@@ -0,0 +1,208 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <algorithm>
+#include <cstdint>
+#include <optional>
+
+#include "logging.hpp"
+#include "openvino/core/except.hpp"
+
+namespace ov {
+namespace npuw {
+
+/**
+ * @brief Transaction coordinator for continuous prefill.
+ *
+ * Owns the propose/grant negotiation and the request-level transaction state
+ * machine. The caller proposes a common token prefix through the
+ * npuw_stored_tokens_state variable state, the coordinator clamps it by every
+ * limit the plugin owns and grants an effective keep K. A granted keep is a
+ * command, so the next inference must be the matching delta-only prefill.
+ *
+ * Three states. While IDLE the state reports the committed live token count
+ * and accepts one proposal, a reset, or ordinary inference. PENDING means a
+ * command is armed or executing: a positive keep demands the delta-only
+ * prefill, a zero keep demands a full prefill from position zero. Any failure
+ * after mutation started poisons the request as POISONED, where only reset()
+ * is accepted: the caller sent only the delta, so recovering by falling back
+ * to an ordinary prefill would treat the delta as the whole conversation.
+ *
+ * The keep rule is K = C * floor(min(K_common, K_max, W) / C), where C is the
+ * prefill chunk size, K_max is how many past tokens the chunked prefill can
+ * represent, and W is the prefill-produced watermark. The rule is evaluated
+ * here at propose time and nowhere else.
+ *
+ * Note for callers of the variable state: a write is not idempotent. You write
+ * X and read back Y <= X, and must always slice at the granted value.
+ */
+class ContinuationCoordinator {
+public:
+ enum class Stage : uint8_t {
+ IDLE,
+ PENDING,
+ POISONED,
+ };
+
+ ContinuationCoordinator() = default;
+
+ void enable(uint32_t chunk_size, uint32_t max_prompt_len) {
+ OPENVINO_ASSERT(chunk_size > 0u && max_prompt_len > chunk_size,
+ "Continuous prefill requires 0 < chunk_size < max_prompt_len, got chunk_size=",
+ chunk_size,
+ " max_prompt_len=",
+ max_prompt_len);
+ m_enabled = true;
+ m_chunk_size = chunk_size;
+ m_k_max = max_prompt_len - chunk_size;
+ }
+
+ bool enabled() const {
+ return m_enabled;
+ }
+
+ Stage stage() const {
+ return m_stage;
+ }
+
+ // Variable-state side, driven by StoredTokensState.
+
+ // A proposal from set_state(N). Validates, applies the keep rule, stores the
+ // result as the pending command, and returns the granted keep. A zero grant
+ // arms a reset: preserving zero tokens is a full reset, not a continuation
+ // with an empty prefix.
+ uint32_t propose(int64_t k_common) {
+ OPENVINO_ASSERT(m_enabled, "Continuous prefill is not enabled for this request.");
+ OPENVINO_ASSERT(m_stage == Stage::IDLE,
+ "npuw_stored_tokens_state: a proposal is accepted only while the request is idle; "
+ "current state does not accept a new proposal. Complete or reset() the pending "
+ "operation first.");
+ OPENVINO_ASSERT(k_common >= 0, "npuw_stored_tokens_state: proposed prefix must be non-negative.");
+ // Growth is an error. Validating against total KV capacity instead would let
+ // a caller present uninitialised memory as a valid prefix.
+ OPENVINO_ASSERT(static_cast<uint64_t>(k_common) <= m_live_tokens,
+ "npuw_stored_tokens_state: proposed prefix (",
+ k_common,
+ ") exceeds the live token count (",
+ m_live_tokens,
+ "). Growth is an error.");
+
+ const uint32_t clamped = std::min({static_cast<uint32_t>(k_common), m_k_max, m_watermark});
+ const uint32_t granted = m_chunk_size * (clamped / m_chunk_size);
+
+ m_pending_keep = granted;
+ m_stage = Stage::PENDING;
+ LOG_DEBUG("Continuous prefill: proposed " << k_common << ", granted " << granted << " (K_max=" << m_k_max
+ << ", W=" << m_watermark << ", C=" << m_chunk_size << ")");
+ return granted;
+ }
+
+ // The grant returned by get_state(), meaning the prefix the plugin will honour.
+ int64_t query() const {
+ switch (m_stage) {
+ case Stage::IDLE:
+ return static_cast<int64_t>(m_live_tokens);
+ case Stage::PENDING:
+ return static_cast<int64_t>(m_pending_keep);
+ case Stage::POISONED:
+ return 0;
+ }
+ return 0;
+ }
+
+ // reset() is a control operation rather than a proposal. It discards any pending
+ // keep and arms a zero keep, idempotently. The physical reset happens on the
+ // next validated full prefill. This is also the only recovery from POISONED.
+ void request_reset() {
+ m_pending_keep = 0u;
+ m_stage = Stage::PENDING;
+ }
+
+ // Infer-request side.
+
+ // What the next inference must be: no value means ordinary inference, zero
+ // means the pending reset's full prefill, positive means the delta-only
+ // prefill at exactly that keep. Throws if the request is poisoned.
+ std::optional<uint32_t> pending() const {
+ if (!m_enabled) {
+ return std::nullopt;
+ }
+ OPENVINO_ASSERT(m_stage != Stage::POISONED,
+ "Continuous prefill: the request is poisoned by a previous failure. "
+ "Call reset() on npuw_stored_tokens_state and re-send the full history.");
+ return m_stage == Stage::PENDING ? std::optional<uint32_t>(m_pending_keep) : std::nullopt;
+ }
+
+ // Preflight failed before any mutation. Consume the command and return to IDLE
+ // with the last committed counters intact. Only a pending keep may be aborted:
+ // a pending reset deliberately stays pending until the full prompt arrives.
+ void abort_preflight() {
+ OPENVINO_ASSERT(m_stage == Stage::PENDING && m_pending_keep > 0u,
+ "Continuous prefill: abort_preflight() without a pending keep command.");
+ m_pending_keep = 0u;
+ m_stage = Stage::IDLE;
+ }
+
+ // An exception after live state mutation began poisons the request. No new
+ // count is published and only reset() can start recovery. Runs on exception
+ // paths, so it must never throw.
+ void poison() {
+ m_pending_keep = 0u;
+ m_stage = Stage::POISONED;
+ }
+
+ // Publish a committed prefill, full or continued. The new live count is also
+ // the new prefill-produced watermark. Legal for an ordinary idle prefill or
+ // a pending command that just executed; a commit must never clear the
+ // poisoning that only reset() owns.
+ void commit_prefill(uint32_t live_tokens) {
+ OPENVINO_ASSERT(m_stage != Stage::POISONED, "Continuous prefill: commit_prefill() on a poisoned request.");
+ m_live_tokens = live_tokens;
+ m_watermark = live_tokens;
+ m_pending_keep = 0u;
+ m_stage = Stage::IDLE;
+ }
+
+ // Publish the result of an ordinary generate step. Generate-produced KV must
+ // not advance the watermark; a speculative-decoding trim may even lower the
+ // live count below it, in which case the watermark is clamped down. Generate
+ // only runs when no command is pending, so anything but IDLE is an error.
+ void publish_generate(uint32_t live_tokens) {
+ OPENVINO_ASSERT(m_stage == Stage::IDLE, "Continuous prefill: publish_generate() outside the idle state.");
+ m_live_tokens = live_tokens;
+ m_watermark = std::min(m_watermark, live_tokens);
+ }
+
+ uint32_t live_tokens() const {
+ return m_live_tokens;
+ }
+
+ uint32_t watermark() const {
+ return m_watermark;
+ }
+
+ uint32_t chunk_size() const {
+ return m_chunk_size;
+ }
+
+ uint32_t k_max() const {
+ return m_k_max;
+ }
+
+private:
+ bool m_enabled = false;
+ Stage m_stage = Stage::IDLE;
+ // Valid while PENDING: a positive value is a granted keep, zero is a reset.
+ // The stage keeps "no command" distinct from "a command to keep 0".
+ uint32_t m_pending_keep = 0u;
+ uint32_t m_live_tokens = 0u;
+ uint32_t m_watermark = 0u;
+ uint32_t m_chunk_size = 0u;
+ uint32_t m_k_max = 0u;
+};
+
+} // namespace npuw
+} // namespace ov
diff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_stored_tokens_state.hpp b/src/plugins/intel_npu/src/plugin/npuw/llm_stored_tokens_state.hpp
index ffa45c1f18e..ed5d7d5084c 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/llm_stored_tokens_state.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_stored_tokens_state.hpp
@@ -4,6 +4,7 @@
#pragma once
+#include "llm_continuation.hpp"
#include "openvino/runtime/itensor.hpp"
#include "openvino/runtime/ivariable_state.hpp"
#include "openvino/runtime/make_tensor.hpp"
@@ -11,34 +12,75 @@
namespace ov {
namespace npuw {
+class LLMInferRequest;
+
// Special VariableState for already processed/stored tokens in LLM.
// Allows external pipelines to call reset on that state where needed.
+//
+// When continuous prefill is enabled for the owning request, this state also
+// becomes the propose/grant negotiation channel. A set_state(N) call is a
+// proposal that the first N tokens are unchanged. The plugin clamps N by every
+// limit it owns and stores the result as a pending command. A get_state() call
+// returns the grant, which is the prefix the plugin will honour. reset() is a
+// control operation that discards any pending keep and requires the next
+// inference to be a full prefill at cache position zero.
+//
+// A write is not idempotent. The caller writes X and reads back Y <= X, and
+// must slice its input at Y, never at X.
+//
+// Without continuous prefill the legacy contract is unchanged. get_state()
+// returns the stored token count, reset() zeroes it and set_state() throws.
class StoredTokensState : public ov::IVariableState {
public:
friend class ov::npuw::LLMInferRequest;
StoredTokensState() : ov::IVariableState("npuw_stored_tokens_state") {
auto tensor = ov::Tensor(ov::element::i64, ov::Shape{1});
m_state = ov::get_tensor_impl(tensor);
- reset();
+ m_state->data<int64_t>()[0] = 0;
}
void reset() override {
+ if (has_continuation()) {
+ m_coordinator->request_reset();
+ }
m_state->data<int64_t>()[0] = 0;
}
- void set_state(const ov::SoPtr<ov::ITensor>&) override {
- OPENVINO_THROW("StoredTokensState::set_state() should not be called!");
+ void set_state(const ov::SoPtr<ov::ITensor>& new_state) override {
+ if (!has_continuation()) {
+ OPENVINO_THROW("npuw_stored_tokens_state: set_state() is a continuous prefill proposal and requires "
+ "NPUW_LLM_ENABLE_CONTINUOUS_PREFILL on a model where "
+ "NPUW_LLM_CONTINUOUS_PREFILL_SUPPORTED reports true.");
+ }
+ OPENVINO_ASSERT(new_state, "npuw_stored_tokens_state: set_state() received a null tensor.");
+ OPENVINO_ASSERT(new_state->get_element_type() == ov::element::i64,
+ "npuw_stored_tokens_state: proposal tensor must be i64, got ",
+ new_state->get_element_type());
+ OPENVINO_ASSERT(new_state->get_size() == 1u,
+ "npuw_stored_tokens_state: proposal tensor must be a scalar (one element), got ",
+ new_state->get_size(),
+ " elements.");
+ m_coordinator->propose(new_state->data<int64_t>()[0]);
}
- // Returns a copy of state to prevent external modfication.
+ // Returns a copy of state to prevent external modification.
ov::SoPtr<ov::ITensor> get_state() const override {
- const auto* state_data = m_state->data<int64_t>();
auto result = ov::Tensor(ov::element::i64, ov::Shape{1});
- result.data<int64_t>()[0] = state_data[0];
+ result.data<int64_t>()[0] = has_continuation() ? m_coordinator->query() : m_state->data<int64_t>()[0];
return ov::get_tensor_impl(result);
}
private:
+ // Wire the negotiation channel. The coordinator is owned by LLMInferRequest,
+ // which also owns (and outlives) this state.
+ void attach_continuation(ContinuationCoordinator* coordinator) {
+ m_coordinator = coordinator;
+ }
+
+ bool has_continuation() const {
+ return m_coordinator != nullptr && m_coordinator->enabled();
+ }
+
int64_t get_num_stored_tokens() const {
return m_state->data<int64_t>()[0];
}
@@ -46,6 +88,8 @@ private:
void set_num_stored_tokens(int64_t num_tokens) {
m_state->data<int64_t>()[0] = num_tokens;
}
+
+ ContinuationCoordinator* m_coordinator = nullptr;
};
} // namespace npuw
diff --git a/src/plugins/intel_npu/src/plugin/sources.cmake b/src/plugins/intel_npu/src/plugin/sources.cmake
index ba4fee8a8d5..2773eb6cbf3 100644
--- a/src/plugins/intel_npu/src/plugin/sources.cmake
+++ b/src/plugins/intel_npu/src/plugin/sources.cmake
@@ -69,6 +69,7 @@ set(NPUW_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_compiled_model.hpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_compiled_model_utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_compiled_model_utils.hpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_continuation.hpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_continuous_kvcache_strategy.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_continuous_kvcache_strategy.hpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_eagle3_extension.cpp
diff --git a/src/plugins/intel_npu/tests/unit/CMakeLists.txt b/src/plugins/intel_npu/tests/unit/CMakeLists.txt
index 86b51928679..ef290f9e116 100644
--- a/src/plugins/intel_npu/tests/unit/CMakeLists.txt
+++ b/src/plugins/intel_npu/tests/unit/CMakeLists.txt
@@ -153,6 +153,7 @@ target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/npu/executor_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_compiled_model_graph_options_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/gqa_compiled_model_test.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_continuation_test.cpp
${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/lincache_utils_test.cpp
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 3fac67a5b7e..7ace85679d0 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
@@ -230,6 +230,36 @@ TEST_F(LLMCompiledModelGraphOptionsTest, GeneratePyramidBuildsTwoStaticGenerateV
::testing::UnorderedElementsAre(ov::Shape({1, 1152}), ov::Shape({1, 2176})));
}
+TEST_F(LLMCompiledModelGraphOptionsTest, ContinuousPrefillOptionAndCapabilitySurface) {
+ RecordingFactory recorder;
+ std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;
+
+ ASSERT_NO_THROW(compiled = create_compiled_model({{"NPUW_LLM_ENABLE_CONTINUOUS_PREFILL", "YES"},
+ {"NPUW_LLM_PREFILL_HINT", "DYNAMIC"},
+ {"NPUW_LLM_PREFILL_CHUNK_SIZE", "32"}},
+ recorder));
+ ASSERT_NE(compiled, nullptr);
+
+ EXPECT_TRUE(compiled->get_property("NPUW_LLM_ENABLE_CONTINUOUS_PREFILL").as<bool>());
+ // The capability read must never throw. This change carries the protocol
+ // only, so it reports false even for an otherwise eligible model.
+ ov::Any supported;
+ ASSERT_NO_THROW(supported = compiled->get_property("NPUW_LLM_CONTINUOUS_PREFILL_SUPPORTED"));
+ EXPECT_FALSE(supported.as<bool>());
+}
+
+TEST_F(LLMCompiledModelGraphOptionsTest, ContinuousPrefillRejectsPrefixCaching) {
+ RecordingFactory recorder;
+ // The hash prefix cache cannot process delta-only inputs, so the combination
+ // fails compilation instead of silently misbehaving.
+ EXPECT_THROW(create_compiled_model({{"NPUW_LLM_ENABLE_CONTINUOUS_PREFILL", "YES"},
+ {"NPUW_LLM_ENABLE_PREFIX_CACHING", "YES"},
+ {"NPUW_LLM_PREFILL_HINT", "DYNAMIC"},
+ {"NPUW_LLM_PREFILL_CHUNK_SIZE", "32"}},
+ recorder),
+ ov::Exception);
+}
+
TEST(HybridModelBuilderTest, HybridLinearAttnModelBuilds) {
std::shared_ptr<ov::Model> model;
ASSERT_NO_THROW(model = ov::test::npuw::build_hybrid_llm_test_model());
diff --git a/src/plugins/intel_npu/tests/unit/npuw/llm_continuation_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/llm_continuation_test.cpp
new file mode 100644
index 00000000000..4699022a379
--- /dev/null
+++ b/src/plugins/intel_npu/tests/unit/npuw/llm_continuation_test.cpp
@@ -0,0 +1,265 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "llm_continuation.hpp"
+
+#include <gtest/gtest.h>
+
+#include <memory>
+
+#include "llm_stored_tokens_state.hpp"
+#include "openvino/runtime/make_tensor.hpp"
+
+namespace {
+
+using ov::npuw::ContinuationCoordinator;
+using Stage = ov::npuw::ContinuationCoordinator::Stage;
+
+constexpr uint32_t CHUNK = 1024u;
+constexpr uint32_t MAX_PROMPT = 4096u;
+
+ContinuationCoordinator make_enabled() {
+ ContinuationCoordinator c;
+ c.enable(CHUNK, MAX_PROMPT);
+ return c;
+}
+
+// Brings the coordinator to an idle state with the given committed prefill history.
+ContinuationCoordinator make_after_prefill(uint32_t prefill_tokens, uint32_t generated_tokens = 0u) {
+ auto c = make_enabled();
+ c.commit_prefill(prefill_tokens);
+ if (generated_tokens > 0u) {
+ c.publish_generate(prefill_tokens + generated_tokens);
+ }
+ return c;
+}
+
+ov::SoPtr<ov::ITensor> scalar_i64(int64_t value) {
+ auto tensor = ov::Tensor(ov::element::i64, ov::Shape{1});
+ tensor.data<int64_t>()[0] = value;
+ return ov::get_tensor_impl(tensor);
+}
+
+int64_t read_scalar(const ov::SoPtr<ov::ITensor>& tensor) {
+ return tensor->data<int64_t>()[0];
+}
+
+// The keep rule. K = C * floor(min(K_common, K_max, W) / C).
+
+TEST(NPUWContinuation, KeepRuleGrantsAlignedValue) {
+ auto c = make_after_prefill(3000u, 50u);
+ // W = 3000, K_max = 3072, propose the full live history.
+ EXPECT_EQ(c.propose(3050), 2048u);
+ EXPECT_EQ(c.stage(), Stage::PENDING);
+}
+
+TEST(NPUWContinuation, KeepRuleClampsToWatermark) {
+ auto c = make_after_prefill(2048u, 500u);
+ // 2548 live tokens but only 2048 were produced by prefill.
+ EXPECT_EQ(c.propose(2548), 2048u);
+}
+
+TEST(NPUWContinuation, KeepRuleClampsToCapacity) {
+ ContinuationCoordinator c;
+ c.enable(1024u, 4096u);
+ c.commit_prefill(4000u);
+ // K_max = 4096 - 1024 = 3072, rounded stays 3072.
+ EXPECT_EQ(c.propose(4000), 3072u);
+}
+
+TEST(NPUWContinuation, KeepRuleRoundsDownToChunk) {
+ auto c = make_after_prefill(1500u);
+ EXPECT_EQ(c.propose(1500), 1024u);
+}
+
+TEST(NPUWContinuation, SubChunkHistoryGrantsZeroAndArmsReset) {
+ auto c = make_after_prefill(1000u);
+ EXPECT_EQ(c.propose(1000), 0u);
+ // A zero keep is a full reset, not a continuation with an empty prefix.
+ EXPECT_EQ(c.stage(), Stage::PENDING);
+ EXPECT_EQ(c.pending(), 0u);
+ EXPECT_EQ(c.query(), 0);
+}
+
+TEST(NPUWContinuation, GrowthIsRejected) {
+ auto c = make_after_prefill(2048u);
+ EXPECT_THROW(c.propose(2049), ov::Exception);
+ // A rejected proposal leaves the request idle with the committed count readable.
+ EXPECT_EQ(c.stage(), Stage::IDLE);
+ EXPECT_EQ(c.query(), 2048);
+}
+
+TEST(NPUWContinuation, NegativeProposalIsRejected) {
+ auto c = make_after_prefill(2048u);
+ EXPECT_THROW(c.propose(-1), ov::Exception);
+}
+
+TEST(NPUWContinuation, SecondProposalWhilePendingIsRejected) {
+ auto c = make_after_prefill(3072u);
+ EXPECT_EQ(c.propose(3072), 3072u);
+ EXPECT_THROW(c.propose(2048), ov::Exception);
+}
+
+TEST(NPUWContinuation, ProposalWhileResetPendingIsRejected) {
+ auto c = make_after_prefill(2048u);
+ c.request_reset();
+ EXPECT_THROW(c.propose(2048), ov::Exception);
+}
+
+// The grant readback.
+
+TEST(NPUWContinuation, QueryReturnsLiveTokensWhileIdle) {
+ auto c = make_after_prefill(2048u, 10u);
+ EXPECT_EQ(c.query(), 2058);
+}
+
+TEST(NPUWContinuation, QueryReturnsGrantWhilePending) {
+ auto c = make_after_prefill(3000u);
+ c.propose(3000);
+ EXPECT_EQ(c.query(), 2048);
+}
+
+TEST(NPUWContinuation, PublishingLiveCountDoesNotReArmCommand) {
+ auto c = make_after_prefill(2048u);
+ c.propose(2048);
+ c.commit_prefill(2500u);
+ // After the commit there is no pending command, only the published count.
+ EXPECT_EQ(c.stage(), Stage::IDLE);
+ EXPECT_FALSE(c.pending().has_value());
+ EXPECT_EQ(c.query(), 2500);
+}
+
+// The transaction state machine.
+
+TEST(NPUWContinuation, PreflightAbortConsumesCommandAndKeepsCounters) {
+ auto c = make_after_prefill(3000u, 20u);
+ c.propose(3000);
+ c.abort_preflight();
+ EXPECT_EQ(c.stage(), Stage::IDLE);
+ EXPECT_EQ(c.query(), 3020);
+ EXPECT_FALSE(c.pending().has_value());
+}
+
+TEST(NPUWContinuation, PreflightAbortRequiresAPendingKeep) {
+ // Only a pending keep may be aborted. A pending reset stays pending until the
+ // full prompt arrives, and aborting a poisoned request must not clear the
+ // poisoning that only reset() owns.
+ auto idle = make_after_prefill(3000u);
+ EXPECT_THROW(idle.abort_preflight(), ov::Exception);
+
+ auto reset_pending = make_after_prefill(3000u);
+ reset_pending.request_reset();
+ EXPECT_THROW(reset_pending.abort_preflight(), ov::Exception);
+ EXPECT_EQ(reset_pending.stage(), Stage::PENDING);
+ EXPECT_EQ(reset_pending.pending(), 0u);
+
+ auto poisoned = make_after_prefill(3000u);
+ poisoned.propose(3000);
+ poisoned.poison();
+ EXPECT_THROW(poisoned.abort_preflight(), ov::Exception);
+ EXPECT_EQ(poisoned.stage(), Stage::POISONED);
+}
+
+TEST(NPUWContinuation, FailureDuringInferencePoisonsTheRequest) {
+ auto c = make_after_prefill(3000u);
+ c.propose(3000);
+ c.poison();
+ EXPECT_EQ(c.stage(), Stage::POISONED);
+ EXPECT_EQ(c.query(), 0);
+ // Poisoned requests reject inference until reset() is called.
+ EXPECT_THROW(c.pending(), ov::Exception);
+}
+
+TEST(NPUWContinuation, ResetRecoversAPoisonedRequest) {
+ auto c = make_after_prefill(3000u);
+ c.propose(3000);
+ c.poison();
+ c.request_reset();
+ EXPECT_EQ(c.stage(), Stage::PENDING);
+ EXPECT_EQ(c.pending(), 0u);
+ // Idempotent while already pending.
+ c.request_reset();
+ EXPECT_EQ(c.stage(), Stage::PENDING);
+ EXPECT_EQ(c.pending(), 0u);
+}
+
+TEST(NPUWContinuation, ResetDiscardsAPendingKeep) {
+ auto c = make_after_prefill(3000u);
+ c.propose(3000);
+ c.request_reset();
+ EXPECT_EQ(c.pending(), 0u);
+ EXPECT_EQ(c.query(), 0);
+}
+
+TEST(NPUWContinuation, CommitAfterResetPrefillReturnsToIdle) {
+ auto c = make_after_prefill(2048u);
+ c.request_reset();
+ c.commit_prefill(500u);
+ EXPECT_EQ(c.stage(), Stage::IDLE);
+ EXPECT_EQ(c.query(), 500);
+ EXPECT_EQ(c.watermark(), 500u);
+}
+
+TEST(NPUWContinuation, CommitAndPublishRejectInvalidStates) {
+ // A commit must never clear the poisoning that only reset() owns.
+ auto poisoned = make_after_prefill(3000u);
+ poisoned.propose(3000);
+ poisoned.poison();
+ EXPECT_THROW(poisoned.commit_prefill(3000u), ov::Exception);
+ EXPECT_THROW(poisoned.publish_generate(3000u), ov::Exception);
+ EXPECT_EQ(poisoned.stage(), Stage::POISONED);
+
+ // Generate only runs when no command is pending, so a publish with an armed
+ // command is a sequencing error. A commit from PENDING is the ordinary
+ // transaction commit and stays legal.
+ auto armed = make_after_prefill(3000u);
+ armed.propose(3000);
+ EXPECT_THROW(armed.publish_generate(3100u), ov::Exception);
+ EXPECT_EQ(armed.stage(), Stage::PENDING);
+ EXPECT_EQ(armed.pending(), 2048u);
+}
+
+// Watermark accounting.
+
+TEST(NPUWContinuation, WatermarkFollowsPrefillOnly) {
+ auto c = make_enabled();
+ c.commit_prefill(2048u);
+ EXPECT_EQ(c.watermark(), 2048u);
+ c.publish_generate(2148u);
+ EXPECT_EQ(c.watermark(), 2048u);
+ EXPECT_EQ(c.live_tokens(), 2148u);
+}
+
+TEST(NPUWContinuation, SpeculativeTrimClampsWatermarkDown) {
+ auto c = make_enabled();
+ c.commit_prefill(2048u);
+ // A trim below the watermark must lower it, or a later grant could point at
+ // tokens that no longer exist.
+ c.publish_generate(1500u);
+ EXPECT_EQ(c.watermark(), 1500u);
+ EXPECT_THROW(c.propose(2048), ov::Exception);
+ EXPECT_EQ(c.propose(1500), 1024u);
+}
+
+TEST(NPUWContinuation, DisabledCoordinatorReportsNoCommand) {
+ ContinuationCoordinator c;
+ EXPECT_FALSE(c.enabled());
+ EXPECT_FALSE(c.pending().has_value());
+ EXPECT_THROW(c.propose(0), ov::Exception);
+}
+
+// The variable-state channel keeps its legacy contract without a coordinator.
+
+TEST(NPUWStoredTokensState, LegacySetStateThrows) {
+ auto state = std::make_shared<ov::npuw::StoredTokensState>();
+ EXPECT_THROW(state->set_state(scalar_i64(1)), ov::Exception);
+}
+
+TEST(NPUWStoredTokensState, LegacyResetZeroes) {
+ auto state = std::make_shared<ov::npuw::StoredTokensState>();
+ state->reset();
+ EXPECT_EQ(read_scalar(state->get_state()), 0);
+}
+
+} // anonymous namespace
diff --git a/src/plugins/intel_npu/tests/unit/npuw/npuw_options_smoke_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/npuw_options_smoke_test.cpp
index 7afbd482ac8..46a36158db7 100644
--- a/src/plugins/intel_npu/tests/unit/npuw/npuw_options_smoke_test.cpp
+++ b/src/plugins/intel_npu/tests/unit/npuw/npuw_options_smoke_test.cpp
@@ -157,6 +157,7 @@ std::vector<Case> make_cases() {
"NPUW_LLM_PREFIX_CACHING_MAX_NUM_BLOCKS",
"32",
uint64_t{32}),
+ bool_case<::intel_npu::NPUW_LLM_ENABLE_CONTINUOUS_PREFILL>("NPUW_LLM_ENABLE_CONTINUOUS_PREFILL", "YES", true),
enum_case<::intel_npu::NPUW_LLM_PREFILL_HINT>("NPUW_LLM_PREFILL_HINT", "STATIC", "STATIC"),
enum_case<::intel_npu::NPUW_LLM_PREFILL_ATTENTION_HINT>("NPUW_LLM_PREFILL_ATTENTION_HINT",
"DYNAMIC",