Skip to content

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

NPUW: Batched scoring as a composable element (reranker / embedding) (#36375)

Dylan Nevec2a7d9d05619
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 a6d9c4e7481..faf040e795b 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
@@ -94,6 +94,7 @@ INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_WHISPER_EOS_TOKEN, uint64_t, 50257, ov::intel_npu
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_WHISPER_DECOMPOSE_SDPA, bool, false, ov::intel_npu::npuw::whisper, whisper_decompose_sdpa, "NPUW_WHISPER_DECOMPOSE_SDPA", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_EAGLE, bool, false, ov::intel_npu::npuw::eagle, enabled, "NPUW_EAGLE", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_TEXT_EMBED, bool, false, ov::intel_npu::npuw::text_embed, enabled, "NPUW_TEXT_EMBED", LLM, EXPOSED, CACHED, ALL)
+INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_TEXT_RERANK, bool, false, ov::intel_npu::npuw::text_rerank, enabled, "NPUW_TEXT_RERANK", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_KOKORO, bool, false, ov::intel_npu::npuw::kokoro, enabled, "NPUW_KOKORO", KOKORO, EXPOSED, UNCACHED, ALL)
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_KOKORO_BLOCK_SIZE, uint64_t, 200, ov::intel_npu::npuw::kokoro, block_size, "NPUW_KOKORO_BLOCK_SIZE", KOKORO, EXPOSED, UNCACHED, ALL)
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_KOKORO_OVERLAP_SIZE, uint64_t, 20, ov::intel_npu::npuw::kokoro, overlap_size, "NPUW_KOKORO_OVERLAP_SIZE", KOKORO, EXPOSED, UNCACHED, ALL)
diff --git a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
index d3b8a11fdee..92fd3cc2b3e 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
@@ -25,13 +25,16 @@
#include "openvino/runtime/internal_properties.hpp"
#include "openvino/runtime/properties.hpp"
#include "openvino/util/common_util.hpp"
+#include "orc/schema_npuw.hpp"
#include "pa_compiled_model.hpp"
#include "partitioning/patterns/opt.hpp"
#include "pipelines/kokoro/kokoro_compiled_model.hpp"
#include "plugin.hpp"
+#include "serialization.hpp"
#include "unfold_sync_infer_request.hpp"
#include "util.hpp"
#include "v1/elements/accuracy_checked.hpp"
+#include "v1/elements/batched.hpp"
#include "v1/elements/failsafe.hpp"
// required for get_properties_per_device()
@@ -328,7 +331,19 @@ std::shared_ptr<ov::npuw::ICompiledModel> ov::npuw::ICompiledModel::create(
compiled_model = std::make_shared<ov::npuw::GQACompiledModel>(model, plugin, config);
} else if (properties.count(use_llm_key) && properties.at(use_llm_key).as<bool>() == true) {
LOG_INFO("ov::npuw::LLMCompiledModel will be created.");
- compiled_model = std::make_shared<ov::npuw::LLMCompiledModel>(model, plugin, config);
+ auto llm_compiled_model = std::make_shared<ov::npuw::LLMCompiledModel>(model, plugin, config);
+ const auto scoring_tags = ov::npuw::batched::scoring_tags(config);
+ if (scoring_tags.text_rerank || scoring_tags.text_embed) {
+ // Single-shot scoring pipelines (text rerank / embedding) may submit
+ // batched [N, ...] inputs, while the LLM pipeline pins everything to a
+ // static batch of 1. The batched element unrolls such an infer row by
+ // row over the unchanged batch-1 inner request.
+ LOG_INFO("Wrapping with ov::npuw::batched::CompiledModel.");
+ compiled_model =
+ std::make_shared<ov::npuw::batched::CompiledModel>(llm_compiled_model, plugin, scoring_tags);
+ } else {
+ compiled_model = llm_compiled_model;
+ }
} else if (properties.count(use_pa_key) && properties.at(use_pa_key).as<bool>() == true) {
LOG_INFO("ov::npuw::PACompiledModel will be created.");
compiled_model = std::make_shared<ov::npuw::PACompiledModel>(model, plugin, config);
@@ -343,6 +358,71 @@ std::shared_ptr<ov::npuw::ICompiledModel> ov::npuw::ICompiledModel::create(
return compiled_model;
}
+namespace {
+bool is_partitioned_orc(std::istream& stream) {
+ const auto header = ov::npuw::orc::is_orc(stream);
+ return header.has_value() && header->schema_uuid == ov::npuw::orc::schema_npuw::NPUW_ORC_PARTITIONED_SCHEMA;
+}
+
+bool has_npuw_indicator(std::istream& stream) {
+ const auto start = stream.tellg();
+ ov::npuw::s11n::IndicatorType indicator;
+ const bool found = ov::npuw::orc::try_read_bytes(stream, indicator.data(), indicator.size()) &&
+ indicator == NPUW_SERIALIZATION_INDICATOR;
+ stream.clear();
+ stream.seekg(start);
+ return found;
+}
+} // anonymous namespace
+
+bool ov::npuw::ICompiledModel::is_npuw_blob(std::istream& stream) {
+ return is_partitioned_orc(stream) || has_npuw_indicator(stream);
+}
+
+std::shared_ptr<ov::npuw::ICompiledModel> ov::npuw::ICompiledModel::import_model(
+ std::istream& stream,
+ const std::shared_ptr<const ov::IPlugin>& plugin,
+ const ov::AnyMap& properties) {
+ LOG_INFO("Choosing which NPUW CompiledModel to import");
+ LOG_BLOCK();
+
+ // The partitioned CompiledModel is a plain ORC container with no indicator
+ // header of its own.
+ if (is_partitioned_orc(stream)) {
+ return ov::npuw::CompiledModel::import_model(stream, plugin, properties);
+ }
+
+ const auto stream_start_pos = stream.tellg();
+ ov::npuw::s11n::IndicatorType serialization_indicator;
+ OPENVINO_ASSERT(
+ ov::npuw::orc::try_read_bytes(stream, serialization_indicator.data(), serialization_indicator.size()) &&
+ serialization_indicator == NPUW_SERIALIZATION_INDICATOR,
+ "Couldn't deserialize NPUW blob - no NPUW serialization indicator found!");
+ ov::npuw::s11n::IndicatorType compiled_model_indicator;
+ OPENVINO_ASSERT(
+ ov::npuw::orc::try_read_bytes(stream, compiled_model_indicator.data(), compiled_model_indicator.size()),
+ "Couldn't deserialize NPUW blob - no compiled model indicator found!");
+ stream.clear();
+ stream.seekg(stream_start_pos);
+
+ if (compiled_model_indicator == NPUW_FLUX2_COMPILED_MODEL_INDICATOR) {
+ return ov::npuw::Flux2CompiledModel::import_model(stream, plugin, properties);
+ } else if (compiled_model_indicator == NPUW_GQA_COMPILED_MODEL_INDICATOR) {
+ return ov::npuw::GQACompiledModel::import_model(stream, plugin, properties);
+ } else if (compiled_model_indicator == NPUW_LLM_COMPILED_MODEL_INDICATOR) {
+ // Properties are required for ov::weights_path
+ return ov::npuw::LLMCompiledModel::import_model(stream, plugin, properties);
+ } else if (compiled_model_indicator == NPUW_BATCHED_COMPILED_MODEL_INDICATOR) {
+ return ov::npuw::batched::CompiledModel::import_model(stream, plugin, properties);
+ } else if (compiled_model_indicator == NPUW_COMPILED_MODEL_INDICATOR) {
+ // The flat CompiledModel moved to the ORC container above; its old
+ // indicator-headed layout has no reader anymore.
+ OPENVINO_THROW("Legacy flat NPUW CompiledModel blobs are no longer supported. Re-export the model with "
+ "the current ORC serializer.");
+ }
+ OPENVINO_THROW("Couldn't deserialize NPUW blob - fatal error!");
+}
+
ov::npuw::ICompiledModel::ICompiledModel(const std::shared_ptr<ov::Model>& model,
const std::shared_ptr<const ov::IPlugin>& plugin)
: ov::ICompiledModel(model, plugin) {}
diff --git a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp
index fe638604dd1..0133c6d3ddf 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp
@@ -38,6 +38,14 @@ public:
static std::shared_ptr<ov::npuw::ICompiledModel> create(const std::shared_ptr<ov::Model>& model,
const std::shared_ptr<const ov::IPlugin>& plugin,
const ov::AnyMap& properties);
+ // True when the stream holds an NPUW blob: a partitioned ORC container or an
+ // indicator-headed blob. The stream position is left where it was.
+ static bool is_npuw_blob(std::istream& stream);
+ // Imports any NPUW blob, routing it to the matching implementation's
+ // import_model(). The import counterpart of create().
+ static std::shared_ptr<ov::npuw::ICompiledModel> import_model(std::istream& stream,
+ const std::shared_ptr<const ov::IPlugin>& plugin,
+ const ov::AnyMap& properties);
ICompiledModel(const std::shared_ptr<ov::Model>& model, const std::shared_ptr<const ov::IPlugin>& plugin);
};
diff --git a/src/plugins/intel_npu/src/plugin/npuw/flux2_compiled_model.cpp b/src/plugins/intel_npu/src/plugin/npuw/flux2_compiled_model.cpp
index 7290d19ba12..1442dcc14b6 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/flux2_compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/flux2_compiled_model.cpp
@@ -202,12 +202,7 @@ ov::npuw::Flux2CompiledModel::Flux2CompiledModel(PreparedState prepared,
void ov::npuw::Flux2CompiledModel::export_model(std::ostream& stream) const {
using namespace ov::npuw::s11n;
- write(stream, NPUW_SERIALIZATION_INDICATOR);
- write(stream, NPUW_FLUX2_COMPILED_MODEL_INDICATOR);
- write(stream, OPENVINO_VERSION_MAJOR);
- write(stream, OPENVINO_VERSION_MINOR);
- write(stream, OPENVINO_VERSION_PATCH);
- write(stream, std::string(NPUW_SERIALIZATION_VERSION));
+ write_header(stream, NPUW_FLUX2_COMPILED_MODEL_INDICATOR);
m_compiled_model->export_model(stream);
}
@@ -220,40 +215,7 @@ std::shared_ptr<ov::npuw::ICompiledModel> ov::npuw::Flux2CompiledModel::import_m
using namespace ov::npuw::s11n;
- ov::npuw::s11n::IndicatorType serialization_indicator;
- read(stream, serialization_indicator);
- NPUW_ASSERT(serialization_indicator == NPUW_SERIALIZATION_INDICATOR);
-
- ov::npuw::s11n::IndicatorType flux2_indicator;
- read(stream, flux2_indicator);
- NPUW_ASSERT(flux2_indicator == NPUW_FLUX2_COMPILED_MODEL_INDICATOR);
-
- int vmajor, vminor, vpatch;
- std::string s11n_version;
- read(stream, vmajor);
- read(stream, vminor);
- read(stream, vpatch);
- read(stream, s11n_version);
-
- if (vmajor != OPENVINO_VERSION_MAJOR || vminor != OPENVINO_VERSION_MINOR || vpatch != OPENVINO_VERSION_PATCH ||
- s11n_version != std::string(NPUW_SERIALIZATION_VERSION)) {
- OPENVINO_THROW("Flux2 blob was serialized with a different OV version (",
- vmajor,
- '.',
- vminor,
- '.',
- vpatch,
- " / NPUW s11n ",
- s11n_version,
- "); current is ",
- OPENVINO_VERSION_MAJOR,
- '.',
- OPENVINO_VERSION_MINOR,
- '.',
- OPENVINO_VERSION_PATCH,
- " / NPUW s11n ",
- NPUW_SERIALIZATION_VERSION);
- }
+ read_and_check_header(stream, NPUW_FLUX2_COMPILED_MODEL_INDICATOR, "Flux2CompiledModel");
// The rest of the stream is the inner CompiledModel ORC blob.
// After import it is fully self-contained; no outer Flux2 wrapper is needed
diff --git a/src/plugins/intel_npu/src/plugin/npuw/gqa_compiled_model.cpp b/src/plugins/intel_npu/src/plugin/npuw/gqa_compiled_model.cpp
index 68e7173cad2..8b8d85eea29 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/gqa_compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/gqa_compiled_model.cpp
@@ -217,12 +217,7 @@ ov::npuw::GQACompiledModel::GQACompiledModel(PreparedState prepared,
void ov::npuw::GQACompiledModel::export_model(std::ostream& stream) const {
using namespace ov::npuw::s11n;
- write(stream, NPUW_SERIALIZATION_INDICATOR);
- write(stream, NPUW_GQA_COMPILED_MODEL_INDICATOR);
- write(stream, OPENVINO_VERSION_MAJOR);
- write(stream, OPENVINO_VERSION_MINOR);
- write(stream, OPENVINO_VERSION_PATCH);
- write(stream, std::string(NPUW_SERIALIZATION_VERSION));
+ write_header(stream, NPUW_GQA_COMPILED_MODEL_INDICATOR);
m_compiled_model->export_model(stream);
}
@@ -235,40 +230,7 @@ std::shared_ptr<ov::npuw::ICompiledModel> ov::npuw::GQACompiledModel::import_mod
using namespace ov::npuw::s11n;
- ov::npuw::s11n::IndicatorType serialization_indicator;
- read(stream, serialization_indicator);
- NPUW_ASSERT(serialization_indicator == NPUW_SERIALIZATION_INDICATOR);
-
- ov::npuw::s11n::IndicatorType gqa_indicator;
- read(stream, gqa_indicator);
- NPUW_ASSERT(gqa_indicator == NPUW_GQA_COMPILED_MODEL_INDICATOR);
-
- int vmajor, vminor, vpatch;
- std::string s11n_version;
- read(stream, vmajor);
- read(stream, vminor);
- read(stream, vpatch);
- read(stream, s11n_version);
-
- if (vmajor != OPENVINO_VERSION_MAJOR || vminor != OPENVINO_VERSION_MINOR || vpatch != OPENVINO_VERSION_PATCH ||
- s11n_version != std::string(NPUW_SERIALIZATION_VERSION)) {
- OPENVINO_THROW("GQA blob was serialized with a different OV version (",
- vmajor,
- '.',
- vminor,
- '.',
- vpatch,
- " / NPUW s11n ",
- s11n_version,
- "); current is ",
- OPENVINO_VERSION_MAJOR,
- '.',
- OPENVINO_VERSION_MINOR,
- '.',
- OPENVINO_VERSION_PATCH,
- " / NPUW s11n ",
- NPUW_SERIALIZATION_VERSION);
- }
+ read_and_check_header(stream, NPUW_GQA_COMPILED_MODEL_INDICATOR, "GQACompiledModel");
// The rest of the stream is the inner CompiledModel ORC blob.
// After import it is fully self-contained; no outer GQA wrapper is needed
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 09d7d887b81..702780f8e31 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
@@ -911,6 +911,10 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
auto use_text_embed_key = pop_option(other_props, std::string("NPUW_TEXT_EMBED"));
m_is_embedding = use_text_embed_key.value_or(false).as<bool>() == true;
+ // The rerank tag only gates the batched wrapper at the entry point. Pop it here
+ // so it stays out of the submodel configs, like the embed tag above.
+ pop_option(other_props, std::string("NPUW_TEXT_RERANK"));
+
if (m_is_embedding) {
// Both embedding flavours only ever prefill; what differs is how they attend. An
// autoregressive embedder (Qwen3-Embedding-style) has a causal mask and a KV cache to
@@ -1518,15 +1522,7 @@ void ov::npuw::LLMCompiledModel::export_model(std::ostream& stream) const {
}
// Write header regardless of encryption requirement - to identify NPUW serializated blobs
- // Serialize magic number first
- write(stream, NPUW_SERIALIZATION_INDICATOR);
- // Serilize LLMCompiledModel identifier
- write(stream, NPUW_LLM_COMPILED_MODEL_INDICATOR);
- // Serialize general meta info
- write(stream, OPENVINO_VERSION_MAJOR);
- write(stream, OPENVINO_VERSION_MINOR);
- write(stream, OPENVINO_VERSION_PATCH);
- write(stream, std::string(NPUW_SERIALIZATION_VERSION));
+ write_header(stream, NPUW_LLM_COMPILED_MODEL_INDICATOR);
// Serialize encrypted flag
write(stream, encryption_required);
// Write flow identifier
@@ -1654,44 +1650,8 @@ std::shared_ptr<ov::npuw::LLMCompiledModel> ov::npuw::LLMCompiledModel::import_m
using namespace ov::npuw::s11n;
- // Sanity check magic number
- ov::npuw::s11n::IndicatorType serialization_indicator;
- read(stream, serialization_indicator);
- NPUW_ASSERT(serialization_indicator == NPUW_SERIALIZATION_INDICATOR && "This blob wasn't serialized via NPUW!");
-
- ov::npuw::s11n::IndicatorType llm_compiled_indicator;
- read(stream, llm_compiled_indicator);
- NPUW_ASSERT(llm_compiled_indicator == NPUW_LLM_COMPILED_MODEL_INDICATOR &&
- "This blob wasn't serialized via LLMCompiledModel!");
-
- // Deserialize general meta info
- int vmajor, vminor, vpatch;
- std::string s11n_version;
- read(stream, vmajor);
- read(stream, vminor);
- read(stream, vpatch);
- read(stream, s11n_version);
-
- if (vmajor != OPENVINO_VERSION_MAJOR || vminor != OPENVINO_VERSION_MINOR || vpatch != OPENVINO_VERSION_PATCH ||
- s11n_version != std::string(NPUW_SERIALIZATION_VERSION)) {
- OPENVINO_THROW("This blobs was serialized with different OV version!",
- "\nSerialized by OV ",
- vmajor,
- '.',
- vminor,
- '.',
- vpatch,
- "\nCurrent OV version ",
- OPENVINO_VERSION_MAJOR,
- '.',
- OPENVINO_VERSION_MINOR,
- '.',
- OPENVINO_VERSION_PATCH,
- "\nNPUW serialized by version ",
- s11n_version,
- "\nNPUW current serialization version ",
- NPUW_SERIALIZATION_VERSION);
- }
+ // Sanity check the header (magic numbers + versions)
+ read_and_check_header(stream, NPUW_LLM_COMPILED_MODEL_INDICATOR, "LLMCompiledModel");
bool encrypted = false;
read(stream, encrypted);
@@ -2032,6 +1992,7 @@ void ov::npuw::LLMCompiledModel::implement_properties() {
BIND(npuw::whisper::whisper_eos_token, NPUW_WHISPER_EOS_TOKEN, get),
BIND(npuw::whisper::whisper_decompose_sdpa, NPUW_WHISPER_DECOMPOSE_SDPA, get),
BIND(npuw::eagle::enabled, NPUW_EAGLE, get),
- BIND(npuw::text_embed::enabled, NPUW_TEXT_EMBED, get)});
+ BIND(npuw::text_embed::enabled, NPUW_TEXT_EMBED, get),
+ BIND(npuw::text_rerank::enabled, NPUW_TEXT_RERANK, get)});
#undef BIND
}
diff --git a/src/plugins/intel_npu/src/plugin/npuw/llm_lora_states.hpp b/src/plugins/intel_npu/src/plugin/npuw/llm_lora_states.hpp
index 02a2223530f..1862d50d631 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/llm_lora_states.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/llm_lora_states.hpp
@@ -4,42 +4,11 @@
#pragma once
-#include "openvino/runtime/itensor.hpp"
-#include "openvino/runtime/ivariable_state.hpp"
+#include "variable_state.hpp"
namespace ov {
namespace npuw {
-class VariableState final : public ov::IVariableState {
-public:
- VariableState(const std::string& name, const ov::SoPtr<ov::ITensor>& tensor) : ov::IVariableState(name) {
- m_state = tensor;
- clear_state_updated();
- }
-
- void set_state(const ov::SoPtr<ov::ITensor>& newState) override {
- m_state = newState;
- m_state_updapted = true;
- }
-
- void reset() override {
- OPENVINO_THROW("VariableState::reset() is not implemented");
- }
-
- ~VariableState() override = default;
-
- bool is_state_updated() const {
- return m_state_updapted;
- }
-
- void clear_state_updated() {
- m_state_updapted = false;
- }
-
-private:
- bool m_state_updapted;
-};
-
struct LoRANames {
static constexpr const char* MatMul_A = "MatMul\\.A";
static constexpr const char* MatMul_B = "MatMul\\.B";
diff --git a/src/plugins/intel_npu/src/plugin/npuw/serialization.cpp b/src/plugins/intel_npu/src/plugin/npuw/serialization.cpp
index 4d9df617fc0..30779130de2 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/serialization.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/serialization.cpp
@@ -12,6 +12,7 @@
#include "logging.hpp"
#include "moe_transformations/moe_transformation.hpp"
#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
+#include "openvino/core/version.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/util/op_types.hpp"
#include "openvino/reference/convert.hpp"
@@ -421,3 +422,52 @@ void ov::npuw::orc::serialize_weightless(Stream& stream,
}
}
}
+
+void ov::npuw::s11n::write_header(std::ostream& stream, const IndicatorType& model_indicator) {
+ write(stream, NPUW_SERIALIZATION_INDICATOR);
+ write(stream, model_indicator);
+ write(stream, OPENVINO_VERSION_MAJOR);
+ write(stream, OPENVINO_VERSION_MINOR);
+ write(stream, OPENVINO_VERSION_PATCH);
+ write(stream, std::string(NPUW_SERIALIZATION_VERSION));
+}
+
+void ov::npuw::s11n::read_and_check_header(std::istream& stream,
+ const IndicatorType& expected,
+ const std::string& what) {
+ IndicatorType serialization_indicator;
+ read(stream, serialization_indicator);
+ OPENVINO_ASSERT(serialization_indicator == NPUW_SERIALIZATION_INDICATOR, "This blob wasn't serialized via NPUW!");
+
+ IndicatorType model_indicator;
+ read(stream, model_indicator);
+ OPENVINO_ASSERT(model_indicator == expected, "This blob wasn't serialized via ", what, "!");
+
+ int vmajor = 0, vminor = 0, vpatch = 0;
+ std::string s11n_version;
+ read(stream, vmajor);
+ read(stream, vminor);
+ read(stream, vpatch);
+ read(stream, s11n_version);
+
+ if (vmajor != OPENVINO_VERSION_MAJOR || vminor != OPENVINO_VERSION_MINOR || vpatch != OPENVINO_VERSION_PATCH ||
+ s11n_version != std::string(NPUW_SERIALIZATION_VERSION)) {
+ OPENVINO_THROW("This blob was serialized with a different OV version!",
+ "\nSerialized by OV ",
+ vmajor,
+ '.',
+ vminor,
+ '.',
+ vpatch,
+ "\nCurrent OV version ",
+ OPENVINO_VERSION_MAJOR,
+ '.',
+ OPENVINO_VERSION_MINOR,
+ '.',
+ OPENVINO_VERSION_PATCH,
+ "\nNPUW serialized by version ",
+ s11n_version,
+ "\nNPUW current serialization version ",
+ NPUW_SERIALIZATION_VERSION);
+ }
+}
diff --git a/src/plugins/intel_npu/src/plugin/npuw/serialization.hpp b/src/plugins/intel_npu/src/plugin/npuw/serialization.hpp
index 137a643d5e7..9a2ca14d656 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/serialization.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/serialization.hpp
@@ -52,7 +52,11 @@ const constexpr ov::npuw::s11n::IndicatorType NPUW_GQA_COMPILED_MODEL_INDICATOR
const constexpr ov::npuw::s11n::IndicatorType NPUW_FLUX2_COMPILED_MODEL_INDICATOR =
{char{0x46}, char{0x4c}, char{0x32}, char{0x43}, char{0x4d}, char{0x4f}};
-const constexpr char* NPUW_SERIALIZATION_VERSION = "0.33";
+// BAT = 0x42,0x41,0x54 + CMO = 0x43,0x4d,0x4f
+const constexpr ov::npuw::s11n::IndicatorType NPUW_BATCHED_COMPILED_MODEL_INDICATOR =
+ {char{0x42}, char{0x41}, char{0x54}, char{0x43}, char{0x4d}, char{0x4f}};
+
+const constexpr char* NPUW_SERIALIZATION_VERSION = "0.34";
// Forward declaration
namespace intel_npu {
@@ -240,6 +244,16 @@ inline void read_any(std::istream& stream, ov::Any& var) {
read(stream, var);
}
+// Writes the common NPUW blob header: the NPUW serialization indicator, the
+// given model indicator, and the serializing OV + NPUW s11n versions.
+void write_header(std::ostream& stream, const IndicatorType& model_indicator);
+
+// Reads and validates a header written by write_header(). Throws if the
+// stream wasn't serialized via NPUW, if the model indicator doesn't match
+// `expected` (`what` names the expected producer in the error message), or
+// if the blob was serialized by a different OV / NPUW s11n version.
+void read_and_check_header(std::istream& stream, const IndicatorType& expected, const std::string& what);
+
} // namespace s11n
// --------------------------------------------------------------------------
diff --git a/src/plugins/intel_npu/src/plugin/npuw/v1/elements/batched.cpp b/src/plugins/intel_npu/src/plugin/npuw/v1/elements/batched.cpp
new file mode 100644
index 00000000000..3c00c1fa817
--- /dev/null
+++ b/src/plugins/intel_npu/src/plugin/npuw/v1/elements/batched.cpp
@@ -0,0 +1,317 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "batched.hpp"
+
+#include <algorithm>
+#include <memory>
+#include <utility>
+
+#include "../../logging.hpp"
+#include "../../serialization.hpp"
+#include "../../util.hpp"
+#include "../../variable_state.hpp"
+#include "intel_npu/npuw_private_properties.hpp"
+#include "openvino/core/except.hpp"
+#include "openvino/core/version.hpp"
+#include "openvino/runtime/iremote_context.hpp"
+#include "openvino/runtime/make_tensor.hpp"
+#include "openvino/runtime/tensor.hpp"
+
+namespace {
+// A port name for error messages. get_any_name() throws on a tensor with no
+// names, so fall back to the node's friendly name.
+std::string port_name(const ov::Output<const ov::Node>& port) {
+ const auto& names = port.get_names();
+ return names.empty() ? port.get_node()->get_friendly_name() : port.get_any_name();
+}
+} // anonymous namespace
+
+ov::npuw::batched::ScoringTags ov::npuw::batched::scoring_tags(const ov::AnyMap& properties) {
+ const auto is_enabled = [&properties](const std::string& key) {
+ const auto it = properties.find(key);
+ return it != properties.end() && it->second.as<bool>();
+ };
+ ScoringTags tags;
+ tags.text_rerank = is_enabled(ov::intel_npu::npuw::text_rerank::enabled.name());
+ tags.text_embed = is_enabled(ov::intel_npu::npuw::text_embed::enabled.name());
+ return tags;
+}
+
+ov::npuw::batched::CompiledModel::CompiledModel(const std::shared_ptr<ov::npuw::ICompiledModel>& inner,
+ const std::shared_ptr<const ov::IPlugin>& plugin,
+ const ScoringTags& tags)
+ : ov::npuw::ICompiledModel(nullptr, plugin), // I/O comes from the inner via inputs()/outputs()
+ m_inner(inner),
+ m_tags(tags) {
+ OPENVINO_ASSERT(m_inner != nullptr, "Batched compiled model requires an inner compiled model");
+}
+
+const std::vector<ov::Output<const ov::Node>>& ov::npuw::batched::CompiledModel::inputs() const {
+ return m_inner->inputs();
+}
+
+const std::vector<ov::Output<const ov::Node>>& ov::npuw::batched::CompiledModel::outputs() const {
+ return m_inner->outputs();
+}
+
+void ov::npuw::batched::CompiledModel::export_model(std::ostream& stream) const {
+ // The wrap is part of the blob. A batched header goes first, the complete inner
+ // blob follows with its own header, and import reconstructs the wrapper from the
+ // header alone.
+ // The inner blob checks its own versions, but the wrapper header needs a
+ // version of its own in case its format ever changes.
+ ov::npuw::s11n::write_header(stream, NPUW_BATCHED_COMPILED_MODEL_INDICATOR);
+ // The scoring tags are wrapper state, so they ride the wrapper's own header.
+ ov::npuw::s11n::write(stream, m_tags.text_rerank);
+ ov::npuw::s11n::write(stream, m_tags.text_embed);
+ m_inner->export_model(stream);
+}
+
+std::shared_ptr<ov::npuw::ICompiledModel> ov::npuw::batched::CompiledModel::import_model(
+ std::istream& stream,
+ const std::shared_ptr<const ov::IPlugin>& plugin,
+ const ov::AnyMap& properties) {
+ LOG_INFO("Deserializing batched::CompiledModel...");
+
+ ov::npuw::s11n::read_and_check_header(stream, NPUW_BATCHED_COMPILED_MODEL_INDICATOR, "batched::CompiledModel");
+
+ ScoringTags tags;
+ ov::npuw::s11n::read(stream, tags.text_rerank);
+ ov::npuw::s11n::read(stream, tags.text_embed);
+
+ // The inner blob carries its own indicator header - the common NPUW dispatch
+ // picks the right implementation, so the wrapper stays agnostic of what it wraps.
+ auto inner = ov::npuw::ICompiledModel::import_model(stream, plugin, properties);
+ return std::make_shared<CompiledModel>(inner, plugin, tags);
+}
+
+std::shared_ptr<const ov::Model> ov::npuw::batched::CompiledModel::get_runtime_model() const {
+ return m_inner->get_runtime_model();
+}
+
+void ov::npuw::batched::CompiledModel::set_property(const ov::AnyMap& properties) {
+ m_inner->set_property(properties);
+}
+
+ov::Any ov::npuw::batched::CompiledModel::get_property(const std::string& name) const {
+ // The scoring tags live with the wrapper, not the inner model, which stays
+ // unaware of the wrap. Answer them here so the public compiled model reports
+ // them truthfully, on compile and after import alike.
+ if (name == ov::intel_npu::npuw::text_rerank::enabled.name()) {
+ return m_tags.text_rerank;
+ }
+ if (name == ov::intel_npu::npuw::text_embed::enabled.name()) {
+ return m_tags.text_embed;
+ }
+ return m_inner->get_property(name);
+}
+
+void ov::npuw::batched::CompiledModel::release_memory() {
+ m_inner->release_memory();
+}
+
+std::shared_ptr<ov::ISyncInferRequest> ov::npuw::batched::CompiledModel::create_sync_infer_request() const {
+ auto self = std::static_pointer_cast<const ov::ICompiledModel>(shared_from_this());
+ auto inner_request = m_inner->create_infer_request();
+ OPENVINO_ASSERT(inner_request != nullptr, "Batched element: inner compiled model returned a null request");
+ return std::make_shared<InferRequest>(self, std::move(inner_request));
+}
+
+ov::npuw::batched::InferRequest::InferRequest(const std::shared_ptr<const ov::ICompiledModel>& compiled_model,
+ std::shared_ptr<ov::IAsyncInferRequest> inner_request)
+ : ov::ISyncInferRequest(compiled_model),
+ m_inner(std::move(inner_request)) {
+ OPENVINO_ASSERT(m_inner != nullptr, "Batched element requires a non-null inner request");
+
+ m_profile.report_on_die = ov::npuw::profiling_enabled();
+ m_profile.area = "batched/execution";
+
+ // The stacked outputs are allocated through the compiled model's context when
+ // there is one, the way the core allocates its own batched inputs, so a device
+ // gets host memory it can map. Without a device there is no context and they
+ // are plain host tensors.
+ try {
+ m_context = compiled_model->get_context();
+ } catch (const ov::Exception&) {
+ m_context = {};
+ }
+}
+
+ov::SoPtr<ov::ITensor> ov::npuw::batched::InferRequest::get_tensor(const ov::Output<const ov::Node>& port) const {
+ // A caller-bound tensor first, then the element's own stacked output, else
+ // the inner request's tensor: the ports are the same objects, so a batch-1
+ // caller works on the inner's buffers directly and nothing is allocated for it.
+ if (auto bound = ov::ISyncInferRequest::get_tensor(port)) {
+ return bound;
+ }
+ const auto own = m_own_outputs.find(port.get_tensor_ptr());
+ if (own != m_own_outputs.end() && own->second) {
+ return own->second;
+ }
+ return m_inner->get_tensor(port);
+}
+
+ov::npuw::batched::InferRequest::BatchedInputs ov::npuw::batched::InferRequest::extract_batch() const {
+ const auto& in_ports = get_inputs();
+ OPENVINO_ASSERT(!in_ports.empty(), "Batched element: the wrapped model has no inputs");
+
+ // The batch contract: every input's leading dimension is either the batch size
+ // N (the input carries per-row data, sliced by infer()) or exactly 1 (the input
+ // is broadcast, bound whole to every row). N is whatever the batched inputs
+ // agree on - two inputs with different leading dimensions > 1 are an error -
+ // and with every input at 1 the infer is a plain batch-1 one.
+ BatchedInputs inputs;
+ inputs.tensors.reserve(in_ports.size());
+ for (const auto& port : in_ports) {
+ auto tensor = get_tensor(port);
+ OPENVINO_ASSERT(tensor, "Batched element: no tensor is set for input '", port_name(port), "'");
+ const auto& shape = tensor->get_shape();
+ OPENVINO_ASSERT(!shape.empty(),
+ "Batched element: input '",
+ port_name(port),
+ "' has no leading (batch) dimension");
+ OPENVINO_ASSERT(shape[0] > 0,
+ "Batched element: input '",
+ port_name(port),
+ "' has a zero-sized batch dimension - batch size must be > 0");
+ if (shape[0] > 1) {
+ OPENVINO_ASSERT(inputs.batch == 1 || inputs.batch == shape[0],
+ "Batched element: input '",
+ port_name(port),
+ "' has batch dimension ",
+ shape[0],
+ " which is neither the inferred batch size ",
+ inputs.batch,
+ " nor 1 (broadcast).");
+ inputs.batch = shape[0];
+ }
+ inputs.tensors.push_back(std::move(tensor));
+ }
+ return inputs;
+}
+
+void ov::npuw::batched::InferRequest::infer() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+
+ const auto& in_ports = get_inputs();
+ const auto& out_ports = get_outputs();
+
+ BatchedInputs inputs;
+ m_profile["1.extract_batch"].record([&]() {
+ inputs = extract_batch();
+ });
+ const std::size_t batch = inputs.batch;
+
+ // Broadcast inputs are bound whole, once. Batched inputs are rebound per row
+ // to the row's [1, ...] view below.
+ for (std::size_t i = 0; i < in_ports.size(); ++i) {
+ if (inputs.tensors[i]->get_shape()[0] == 1) {
+ m_inner->set_tensor(in_ports[i], inputs.tensors[i]);
+ }
+ }
+
+ // States the inner exposes as ov::npuw::VariableState are kept out of the
+ // per-row reset: that type holds data bound for the model's lifetime, not
+ // per-inference data, so it must survive the row loop and by design
+ // implements no reset().
+ auto inner_states = m_inner->query_state();
+ inner_states.erase(std::remove_if(inner_states.begin(),
+ inner_states.end(),
+ [](const ov::SoPtr<ov::IVariableState>& state) {
+ return std::dynamic_pointer_cast<ov::npuw::VariableState>(state._ptr) !=
+ nullptr;
+ }),
+ inner_states.end());
+
+ // Unroll row by row: reset the inner state so each row is scored as an
+ // independent prompt, bind the row's view of every batched input, run the
+ // batch-1 inner request, and copy its outputs into row `row` of the [N, ...]
+ // public outputs.
+ for (std::size_t row = 0; row < batch; ++row) {
+ m_profile["2.bind_row"].record([&]() {
+ for (const auto& state : inner_states) {
+ state->reset();
+ }
+ for (std::size_t i = 0; i < in_ports.size(); ++i) {
+ const auto& full = inputs.tensors[i];
+ if (full->get_shape()[0] != 1) {
+ m_inner->set_tensor(in_ports[i], ov::npuw::util::view(full, 0, row, 1));
+ }
+ }
+ });
+ m_profile["3.inner_infer"].record([&]() {
+ m_inner->infer();
+ });
+ if (row == 0) {
+ // The wrapped model's ports are dynamic - the output shapes are only
+ // known once the first row has been scored.
+ prepare_outputs(batch);
+ }
+ m_profile["4.copy_row_out"].record([&]() {
+ for (const auto& port : out_ports) {
+ m_inner->get_tensor(port)->copy_to(ov::npuw::util::view(get_tensor(port), 0, row, 1)._ptr);
+ }
+ });
+ }
+}
+
+void ov::npuw::batched::InferRequest::prepare_outputs(std::size_t batch) {
+ for (const auto& port : get_outputs()) {
+ const auto inner_out = m_inner->get_tensor(port);
+ OPENVINO_ASSERT(inner_out && !inner_out->get_shape().empty() && inner_out->get_shape()[0] == 1,
+ "Batched element: output '",
+ port_name(port),
+ "' of the inner request is not a [1, ...] tensor");
+ const auto type = inner_out->get_element_type();
+ ov::Shape shape = inner_out->get_shape();
+ shape[0] = batch;
+
+ // A caller-bound tensor stays bound and is written into, the way plugins
+ // treat dynamic outputs: set_shape() resizes an owning tensor when the
+ // produced shape differs and throws for a fixed view too small for the data.
+ if (const auto bound = ov::ISyncInferRequest::get_tensor(port)) {
+ OPENVINO_ASSERT(bound->get_element_type() == type,
+ "Batched element: output '",
+ port_name(port),
+ "' is bound to a tensor of type ",
+ bound->get_element_type(),
+ ", but this inference produces type ",
+ type,
+ " - bind a tensor of the produced type or leave the output unset.");
+ bound->set_shape(shape);
+ continue;
+ }
+ // The element's own output is reused while the shape holds and allocated
+ // afresh when it changes: a device tensor cannot grow in place.
+ auto& own = m_own_outputs[port.get_tensor_ptr()];
+ if (!own || own->get_element_type() != type || own->get_shape() != shape) {
+ own = allocate_output(type, shape);
+ }
+ }
+}
+
+ov::SoPtr<ov::ITensor> ov::npuw::batched::InferRequest::allocate_output(const ov::element::Type& type,
+ const ov::Shape& shape) const {
+ if (m_context) {
+ return m_context->create_host_tensor(type, shape);
+ }
+ return ov::get_tensor_impl(ov::Tensor(type, shape));
+}
+
+void ov::npuw::batched::InferRequest::check_tensors() const {
+ // No-op: the public outputs are sized on infer once the batch is known, and
+ // the batched inputs are validated and then unrolled by infer() - the per-row
+ // [1, ...] tensors are checked by the inner request.
+}
+
+std::vector<ov::SoPtr<ov::IVariableState>> ov::npuw::batched::InferRequest::query_state() const {
+ // The batched element resets inner state between rows and exposes no
+ // cross-call state of its own, so it presents an empty state list.
+ return {};
+}
+
+std::vector<ov::ProfilingInfo> ov::npuw::batched::InferRequest::get_profiling_info() const {
+ return m_inner->get_profiling_info();
+}
diff --git a/src/plugins/intel_npu/src/plugin/npuw/v1/elements/batched.hpp b/src/plugins/intel_npu/src/plugin/npuw/v1/elements/batched.hpp
new file mode 100644
index 00000000000..af0b6c64f50
--- /dev/null
+++ b/src/plugins/intel_npu/src/plugin/npuw/v1/elements/batched.hpp
@@ -0,0 +1,116 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <memory>
+#include <mutex>
+#include <unordered_map>
+#include <vector>
+
+#include "../../compiled_model.hpp"
+#include "../../perf.hpp"
+#include "openvino/runtime/iasync_infer_request.hpp"
+#include "openvino/runtime/iremote_context.hpp"
+#include "openvino/runtime/isync_infer_request.hpp"
+#include "openvino/runtime/so_ptr.hpp"
+
+namespace ov::npuw::batched {
+
+// The scoring tags (NPUW_TEXT_RERANK / NPUW_TEXT_EMBED) that request the wrap.
+// Recorded on the wrapper and written into the batched blob header.
+struct ScoringTags {
+ bool text_rerank = false;
+ bool text_embed = false;
+};
+
+// Extract the scoring tags from the compile properties.
+ScoringTags scoring_tags(const ov::AnyMap& properties);
+
+// Decorator that adds batch > 1 execution on top of a batch-1 inner compiled
+// model. Like failsafe and accuracy_checked it forwards everything to the inner
+// and exposes the inner's own ports. A [N, ...] inference is unrolled into N
+// [1, ...] inferences with a state reset between rows, so it is only valid for
+// single-shot scoring (rerank, embedding), never for generation. Applied at
+// ICompiledModel::create(); the blob carries a batched header in front of the
+// inner blob so import rebuilds the wrap on its own.
+class CompiledModel final : public ov::npuw::ICompiledModel {
+public:
+ // Consumes the batched header, imports the nested inner blob and wraps it.
+ static std::shared_ptr<ov::npuw::ICompiledModel> import_model(std::istream& stream,
+ const std::shared_ptr<const ov::IPlugin>& plugin,
+ const ov::AnyMap& properties);
+
+ CompiledModel(const std::shared_ptr<ov::npuw::ICompiledModel>& inner,
+ const std::shared_ptr<const ov::IPlugin>& plugin,
+ const ScoringTags& tags);
+
+ // The inner model's ports, the wrapper adds no I/O of its own.
+ const std::vector<ov::Output<const ov::Node>>& inputs() const override;
+ const std::vector<ov::Output<const ov::Node>>& outputs() const override;
+
+ void export_model(std::ostream& stream) const override;
+ std::shared_ptr<const ov::Model> get_runtime_model() const override;
+
+ void set_property(const ov::AnyMap& properties) override;
+
+ // Scoring tags come from the wrapper, everything else from the inner.
+ ov::Any get_property(const std::string& name) const override;
+
+ void release_memory() override;
+
+ std::shared_ptr<ov::ISyncInferRequest> create_sync_infer_request() const override;
+
+private:
+ std::shared_ptr<ov::npuw::ICompiledModel> m_inner;
+ ScoringTags m_tags;
+};
+
+// Unrolls one [N, ...] inference over the batch-1 inner request. Inputs with a
+// leading dim of N are sliced per row, a leading dim of 1 means broadcast. The
+// inner state is reset before every row and the row outputs are copied into the
+// [N, ...] public outputs. A tensor the caller bound is written into in place, an
+// unbound output is the element's own, allocated through the compiled model's
+// context when there is a device. With nothing bound the public tensors are the
+// inner's own, so a batch-1 caller works on them directly.
+class InferRequest final : public ov::ISyncInferRequest {
+public:
+ InferRequest(const std::shared_ptr<const ov::ICompiledModel>& compiled_model,
+ std::shared_ptr<ov::IAsyncInferRequest> inner_request);
+
+ void infer() override;
+ void check_tensors() const override;
+ ov::SoPtr<ov::ITensor> get_tensor(const ov::Output<const ov::Node>& port) const override;
+
+ std::vector<ov::SoPtr<ov::IVariableState>> query_state() const override;
+ std::vector<ov::ProfilingInfo> get_profiling_info() const override;
+
+private:
+ // Public input tensors of one infer() call and the batch size they agree on.
+ struct BatchedInputs {
+ std::vector<ov::SoPtr<ov::ITensor>> tensors; // parallel to get_inputs()
+ std::size_t batch = 1;
+ };
+
+ // Derive N from the public inputs: every leading dim is N or 1, else throw.
+ BatchedInputs extract_batch() const;
+
+ // Size the public outputs to [batch, ...] once the first row has produced the
+ // inner shapes: a bound tensor is set_shape()'d in place, the element's own is
+ // reused while the shape holds and reallocated when it changes.
+ void prepare_outputs(std::size_t batch);
+ // Host memory from the compiled model's context when there is one, else a plain tensor.
+ ov::SoPtr<ov::ITensor> allocate_output(const ov::element::Type& type, const ov::Shape& shape) const;
+
+ std::shared_ptr<ov::IAsyncInferRequest> m_inner;
+ ov::SoPtr<ov::IRemoteContext> m_context;
+ // The element's own stacked outputs, by port; a caller-bound tensor lives in the base request instead.
+ std::unordered_map<std::shared_ptr<ov::descriptor::Tensor>, ov::SoPtr<ov::ITensor>> m_own_outputs;
+ mutable std::mutex m_mutex;
+
+ using MS = ov::npuw::perf::metric<ov::npuw::perf::MSec>;
+ ov::npuw::perf::Profile<MS> m_profile;
+};
+
+} // namespace ov::npuw::batched
diff --git a/src/plugins/intel_npu/src/plugin/npuw/variable_state.hpp b/src/plugins/intel_npu/src/plugin/npuw/variable_state.hpp
new file mode 100644
index 00000000000..0be89acbcdc
--- /dev/null
+++ b/src/plugins/intel_npu/src/plugin/npuw/variable_state.hpp
@@ -0,0 +1,48 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "openvino/runtime/itensor.hpp"
+#include "openvino/runtime/ivariable_state.hpp"
+
+namespace ov {
+namespace npuw {
+
+// A variable state over a tensor that is bound for the lifetime of the model
+// (e.g. LoRA adapter weights), not per-inference data. It deliberately
+// implements no reset(): such a state has no meaningful "initial" value to
+// return to, so resetting it is an error.
+class VariableState final : public ov::IVariableState {
+public:
+ VariableState(const std::string& name, const ov::SoPtr<ov::ITensor>& tensor) : ov::IVariableState(name) {
+ m_state = tensor;
+ clear_state_updated();
+ }
+
+ void set_state(const ov::SoPtr<ov::ITensor>& newState) override {
+ m_state = newState;
+ m_state_updapted = true;
+ }
+
+ void reset() override {
+ OPENVINO_THROW("VariableState::reset() is not implemented");
+ }
+
+ ~VariableState() override = default;
+
+ bool is_state_updated() const {
+ return m_state_updapted;
+ }
+
+ void clear_state_updated() {
+ m_state_updapted = false;
+ }
+
+private:
+ bool m_state_updapted;
+};
+
+} // namespace npuw
+} // namespace ov
diff --git a/src/plugins/intel_npu/src/plugin/sources.cmake b/src/plugins/intel_npu/src/plugin/sources.cmake
index 7526bf18577..b4ee6530459 100644
--- a/src/plugins/intel_npu/src/plugin/sources.cmake
+++ b/src/plugins/intel_npu/src/plugin/sources.cmake
@@ -229,9 +229,12 @@ set(NPUW_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/npuw/util_xarch.hpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/v1/elements/accuracy_checked.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/v1/elements/accuracy_checked.hpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/npuw/v1/elements/batched.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/npuw/v1/elements/batched.hpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/v1/elements/failsafe.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/v1/elements/failsafe.hpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/v1/subgraph_pipeline.hpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/npuw/variable_state.hpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/weights_bank.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/weights_bank.hpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/whisper/prepare_whisper_model.cpp
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
index 33613756294..39219ad72a7 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
@@ -18,11 +18,6 @@
#include "intel_npu/config/options.hpp"
#include "intel_npu/utils/utils.hpp"
#include "npuw/compiled_model.hpp"
-#include "npuw/flux2_compiled_model.hpp"
-#include "npuw/gqa_compiled_model.hpp"
-#include "npuw/llm_compiled_model.hpp"
-#include "npuw/orc/schema_npuw.hpp"
-#include "npuw/serialization.hpp"
#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/runtime/intel_npu/properties.hpp"
@@ -69,45 +64,12 @@ void check_weightless_cache_attribute_occurrence(const std::shared_ptr<const ov:
std::shared_ptr<ov::ICompiledModel> import_model_npuw(std::istream& stream,
ov::AnyMap& properties,
std::shared_ptr<const ov::IPlugin> pluginSO) {
- const auto use_npuw_it = properties.find(ov::intel_npu::use_npuw.name());
- const bool npuw_enabled = use_npuw_it == properties.end() || use_npuw_it->second.as<bool>();
- constexpr const char* npuw_disabled_message =
- "The blob was exported via NPUW, but NPU_USE_NPUW is disabled.";
-
- if (const auto header = ov::npuw::orc::is_orc(stream);
- header.has_value() && header->schema_uuid == ov::npuw::orc::schema_npuw::NPUW_ORC_PARTITIONED_SCHEMA) {
- OPENVINO_ASSERT(npuw_enabled, npuw_disabled_message);
- return ov::npuw::CompiledModel::import_model(stream, pluginSO, properties);
- }
-
- // If was exported via NPUW
- auto stream_start_pos = stream.tellg();
- ov::npuw::s11n::IndicatorType serialization_indicator;
- if (ov::npuw::orc::try_read_bytes(stream, serialization_indicator.data(), serialization_indicator.size()) &&
- serialization_indicator == NPUW_SERIALIZATION_INDICATOR) {
- OPENVINO_ASSERT(npuw_enabled, npuw_disabled_message);
- ov::npuw::s11n::IndicatorType compiled_model_indicator;
- if (ov::npuw::orc::try_read_bytes(stream, compiled_model_indicator.data(), compiled_model_indicator.size())) {
- stream.clear();
- stream.seekg(stream_start_pos);
-
- if (compiled_model_indicator == NPUW_FLUX2_COMPILED_MODEL_INDICATOR) {
- return ov::npuw::Flux2CompiledModel::import_model(stream, pluginSO, properties);
- } else if (compiled_model_indicator == NPUW_GQA_COMPILED_MODEL_INDICATOR) {
- return ov::npuw::GQACompiledModel::import_model(stream, pluginSO, properties);
- } else if (compiled_model_indicator == NPUW_LLM_COMPILED_MODEL_INDICATOR) {
- // Properties are required for ov::weights_path
- return ov::npuw::LLMCompiledModel::import_model(stream, pluginSO, properties);
- } else if (compiled_model_indicator == NPUW_COMPILED_MODEL_INDICATOR) {
- OPENVINO_THROW("Legacy flat NPUW CompiledModel blobs are no longer supported. Re-export the model "
- "with the current ORC serializer.");
- } else {
- OPENVINO_THROW("Couldn't deserialize NPUW blob - fatal error!");
- }
- }
+ if (ov::npuw::ICompiledModel::is_npuw_blob(stream)) {
+ const auto use_npuw_it = properties.find(ov::intel_npu::use_npuw.name());
+ const bool npuw_enabled = use_npuw_it == properties.end() || use_npuw_it->second.as<bool>();
+ OPENVINO_ASSERT(npuw_enabled, "The blob was exported via NPUW, but NPU_USE_NPUW is disabled.");
+ return ov::npuw::ICompiledModel::import_model(stream, pluginSO, properties);
}
- stream.clear();
- stream.seekg(stream_start_pos);
// Drop NPUW properties if there are any
for (auto it = properties.begin(); it != properties.end();) {
diff --git a/src/plugins/intel_npu/tests/unit/CMakeLists.txt b/src/plugins/intel_npu/tests/unit/CMakeLists.txt
index 929086315ad..a440b635880 100644
--- a/src/plugins/intel_npu/tests/unit/CMakeLists.txt
+++ b/src/plugins/intel_npu/tests/unit/CMakeLists.txt
@@ -78,6 +78,7 @@ ov_add_test_target(
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/util.cpp
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/util_xarch.cpp
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/v1/elements/accuracy_checked.cpp
+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/v1/elements/batched.cpp
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/v1/elements/failsafe.cpp
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/lazy_tensor.cpp
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/split_kvcache_into_blocks.cpp
@@ -178,6 +179,7 @@ target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_continuation_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_continued_prefill_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_swa_cache_test.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/npuw/batched_element_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/llm_infer_request_port_names_test.cpp
diff --git a/src/plugins/intel_npu/tests/unit/npuw/batched_element_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/batched_element_test.cpp
new file mode 100644
index 00000000000..833d7844dfc
--- /dev/null
+++ b/src/plugins/intel_npu/tests/unit/npuw/batched_element_test.cpp
@@ -0,0 +1,760 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+// Unit tests for the batched v1 element (ov::npuw::batched), a model-agnostic fan-out
+// decorator that unrolls a batched [N, ...] request into N batch-1 inner inferences,
+// resets inner variable state between rows, and writes the per-row outputs into rows
+// of the [N, ...] public output tensors. The element itself is the unit under test;
+// only the inner compiled model is mocked, which keeps the tests deviceless and lets
+// them observe the per-row infer/reset. It is driven through a synthetic Qwen-style
+// reranker (realistic multi-input, stateful signature), and the mock echoes each
+// row's first token so a test can assert output row r reflects input row r.
+
+#include <gtest/gtest.h>
+
+#include <algorithm>
+#include <cstdint>
+#include <cstring>
+#include <filesystem>
+#include <memory>
+#include <sstream>
+#include <string>
+#include <vector>
+
+#include "llm_test_helpers.hpp"
+#include "openvino/core/model.hpp"
+#include "openvino/core/version.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/convert.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/runtime/core.hpp"
+#include "openvino/runtime/iasync_infer_request.hpp"
+#include "openvino/runtime/icompiled_model.hpp"
+#include "openvino/runtime/isync_infer_request.hpp"
+#include "openvino/runtime/ivariable_state.hpp"
+#include "openvino/runtime/make_tensor.hpp"
+#include "openvino/runtime/properties.hpp"
+#include "serialization.hpp"
+#include "v1/elements/batched.hpp"
+#include "variable_state.hpp"
+
+namespace {
+
+using ov::test::npuw::build_llm_test_model;
+using ov::test::npuw::build_reranker_test_model;
+using ov::test::npuw::NullPlugin;
+
+// Per-output value offset the mock applies so multi-output tests can tell stacked outputs apart.
+constexpr float kOutputChannelOffset = 1000.0f;
+
+// Ordered log of the lifecycle the element drives on the inner: "reset" before each row,
+// "infer" for each row. Mirrors the events-vector pattern in failsafe.cpp / accuracy_checked.cpp.
+struct Recorder {
+ std::vector<std::string> events;
+};
+
+class MockState : public ov::IVariableState {
+public:
+ explicit MockState(std::shared_ptr<Recorder> rec) : ov::IVariableState("mock_state"), m_rec(std::move(rec)) {}
+ void reset() override {
+ m_rec->events.emplace_back("reset");
+ }
+ void set_state(const ov::SoPtr<ov::ITensor>&) override {}
+ ov::SoPtr<ov::ITensor> get_state() const override {
+ return {};
+ }
+
+private:
+ std::shared_ptr<Recorder> m_rec;
+};
+
+ov::Output<const ov::Node> port_named(const std::vector<ov::Output<const ov::Node>>& ports, const std::string& needle) {
+ for (const auto& port : ports) {
+ if (port.get_any_name().find(needle) != std::string::npos) {
+ return port;
+ }
+ }
+ OPENVINO_THROW("port not found: ", needle);
+}
+
+std::string error_message(const ov::Exception& ex) {
+ return ex.what() == nullptr ? std::string{} : std::string(ex.what());
+}
+
+// The fixture drives the element through a synthetic reranker, so the wrap is
+// requested with the rerank tag throughout.
+ov::npuw::batched::ScoringTags rerank_tags() {
+ ov::npuw::batched::ScoringTags tags;
+ tags.text_rerank = true;
+ return tags;
+}
+
+// Minimal two-output model (one input_ids input, two f32 outputs) for the multi-output test. The
+// mock fills the outputs itself, so only the I/O signature matters.
+std::shared_ptr<ov::Model> build_two_output_model() {
+ auto ids = std::make_shared<ov::op::v0::Parameter>(ov::element::i64, ov::PartialShape{-1, -1});
+ ids->set_friendly_name("input_ids");
+ ids->output(0).set_names({"input_ids"});
+
+ auto as_f32 = std::make_shared<ov::op::v0::Convert>(ids, ov::element::f32);
+ auto two = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{}, {2.0f});
+ auto scaled = std::make_shared<ov::op::v1::Multiply>(as_f32, two);
+
+ return std::make_shared<ov::Model>(ov::OutputVector{as_f32, scaled}, ov::ParameterVector{ids}, "two_output");
+}
+
+// Batch-1 inner stand-in: echoes the row's first input_ids token across its (generically
+// shaped) output. Pure in its input, so the same row always yields the same value -- which
+// is what lets callers check that batched scoring equals per-row scoring.
+class MockInnerSync : public ov::ISyncInferRequest {
+public:
+ MockInnerSync(std::shared_ptr<const ov::ICompiledModel> compiled_model, std::shared_ptr<Recorder> rec)
+ : ov::ISyncInferRequest(std::move(compiled_model)),
+ m_rec(std::move(rec)),
+ m_state(std::make_shared<MockState>(m_rec)),
+ m_adapter_state(std::make_shared<ov::npuw::VariableState>(
+ "lora_state.MatMul.A",
+ ov::get_tensor_impl(ov::Tensor(ov::element::f32, ov::Shape{1})))) {
+ // Like a plugin request, own a [1, ...] tensor per input from the start.
+ for (const auto& port : get_inputs()) {
+ ov::Shape shape;
+ for (const auto& dim : port.get_partial_shape()) {
+ shape.push_back(dim.is_static() ? static_cast<std::size_t>(dim.get_length()) : std::size_t{1});
+ }
+ set_tensor(port, ov::get_tensor_impl(ov::Tensor(port.get_element_type(), shape)));
+ }
+ }
+
+ void infer() override {
+ m_rec->events.emplace_back("infer");
+
+ const auto ids = get_tensor(port_named(get_inputs(), "input_ids"));
+ const float token = static_cast<float>(static_cast<const int64_t*>(ids->data())[0]);
+
+ // Echo the row's token across every output; output k is offset by k so multi-output
+ // tests can tell the stacked outputs apart.
+ const auto& ports = get_outputs();
+ for (std::size_t k = 0; k < ports.size(); ++k) {
+ const auto& port = ports[k];
+ ov::Shape shape;
+ for (const auto& dim : port.get_partial_shape()) {
+ shape.push_back(dim.is_static() ? static_cast<std::size_t>(dim.get_length()) : std::size_t{1});
+ }
+ auto out = ov::get_tensor_impl(ov::Tensor(port.get_element_type(), shape));
+ std::fill_n(static_cast<float*>(out->data()),
+ out->get_size(),
+ token + static_cast<float>(k) * kOutputChannelOffset);
+ set_tensor(port, out);
+ }
+ }
+
+ void check_tensors() const override {}
+ // Every mock request also carries a LoRA adapter state, whose reset() throws by
+ // design. Its presence in every test guards the element's skip of adapter states
+ // in the per-row reset; only the recording MockState is expected to be reset.
+ std::vector<ov::SoPtr<ov::IVariableState>> query_state() const override {
+ return {ov::SoPtr<ov::IVariableState>(m_state), ov::SoPtr<ov::IVariableState>(m_adapter_state)};
+ }
+ std::vector<ov::ProfilingInfo> get_profiling_info() const override {
+ return {};
+ }
+
+private:
+ std::shared_ptr<Recorder> m_rec;
+ std::shared_ptr<MockState> m_state;
+ std::shared_ptr<ov::npuw::VariableState> m_adapter_state;
+};
+
+class MockInnerCompiled : public ov::npuw::ICompiledModel {
+public:
+ MockInnerCompiled(const std::shared_ptr<ov::Model>& model,
+ const std::shared_ptr<const ov::IPlugin>& plugin,
+ std::shared_ptr<Recorder> rec)
+ : ov::npuw::ICompiledModel(model, plugin),
+ m_rec(std::move(rec)) {}
+
+ std::shared_ptr<ov::ISyncInferRequest> create_sync_infer_request() const override {
+ auto request = std::make_shared<MockInnerSync>(shared_from_this(), m_rec);
+ m_last_request = request;
+ return request;
+ }
+ void export_model(std::ostream&) const override {}
+ std::shared_ptr<const ov::Model> get_runtime_model() const override {
+ return nullptr;
+ }
+ void set_property(const ov::AnyMap&) override {}
+ ov::Any get_property(const std::string&) const override {
+ return {};
+ }
+
+ // The sync request behind the most recent create_infer_request(), for tests
+ // that compare the element's public tensors with the inner's own.
+ std::shared_ptr<ov::ISyncInferRequest> last_request() const {
+ return m_last_request.lock();
+ }
+
+private:
+ mutable std::weak_ptr<ov::ISyncInferRequest> m_last_request;
+ std::shared_ptr<Recorder> m_rec;
+};
+
+class NPUWBatchedElementTest : public ::testing::Test {
+protected:
+ void SetUp() override {
+ m_plugin = std::make_shared<NullPlugin>();
+ m_model = build_reranker_test_model();
+ m_recorder = std::make_shared<Recorder>();
+ }
+
+ std::shared_ptr<ov::npuw::ICompiledModel> make_inner() {
+ return std::make_shared<MockInnerCompiled>(m_model, m_plugin, m_recorder);
+ }
+
+ std::shared_ptr<ov::npuw::ICompiledModel> wrap() {
+ return std::make_shared<ov::npuw::batched::CompiledModel>(make_inner(), m_plugin, rerank_tags());
+ }
+
+ // Bind a fresh zero-filled tensor of the port's element type to a named input.
+ template <class Req>
+ static ov::SoPtr<ov::ITensor> bind_input(const std::shared_ptr<Req>& req,
+ const std::string& name,
+ const ov::Shape& shape) {
+ const auto port = port_named(req->get_inputs(), name);
+ auto tensor = ov::get_tensor_impl(ov::Tensor(port.get_element_type(), shape));
+ if (tensor->get_byte_size() > 0) {
+ std::memset(tensor->data(), 0, tensor->get_byte_size());
+ }
+ req->set_tensor(port, tensor);
+ return tensor;
+ }
+
+ // Set input_ids to [batch, len] and fill it row-major -- the only input the mock reads.
+ template <class Req>
+ static void set_input_ids(const std::shared_ptr<Req>& req, const std::vector<std::vector<int64_t>>& ids) {
+ const std::size_t batch = ids.size();
+ const std::size_t len = ids.empty() ? 0 : ids.front().size();
+ auto* tokens = static_cast<int64_t*>(bind_input(req, "input_ids", {batch, len})->data());
+ for (std::size_t r = 0; r < batch; ++r) {
+ std::copy(ids[r].begin(), ids[r].end(), tokens + r * len);
+ }
+ }
+
+ // Bind the full reranker input set; the non-input_ids inputs just need a matching batch dim.
+ template <class Req>
+ static void bind_inputs(const std::shared_ptr<Req>& req, const std::vector<std::vector<int64_t>>& ids) {
+ const std::size_t batch = ids.size();
+ const std::size_t len = ids.empty() ? 0 : ids.front().size();
+ set_input_ids(req, ids);
+ bind_input(req, "attention_mask", {batch, len});
+ bind_input(req, "position_ids", {batch, len});
+ bind_input(req, "beam_idx", {batch});
+ }
+
+ // First element of output row r (the echoed token), independent of the output's rank.
+ static float row_value(const ov::SoPtr<ov::ITensor>& out, std::size_t row) {
+ const std::size_t stride = out->get_size() / out->get_shape()[0];
+ return static_cast<const float*>(out->data())[row * stride];
+ }
+
+ std::shared_ptr<ov::IPlugin> m_plugin;
+ std::shared_ptr<ov::Model> m_model;
+ std::shared_ptr<Recorder> m_recorder;
+};
+
+TEST_F(NPUWBatchedElementTest, ScoringTagsFromProperties) {
+ using ov::npuw::batched::scoring_tags;
+ EXPECT_FALSE(scoring_tags({}).text_rerank);
+ EXPECT_FALSE(scoring_tags({}).text_embed);
+ EXPECT_FALSE(scoring_tags({{"NPUW_TEXT_RERANK", false}}).text_rerank);
+ EXPECT_FALSE(scoring_tags({{"NPUW_TEXT_RERANK", "NO"}}).text_rerank);
+ EXPECT_TRUE(scoring_tags({{"NPUW_TEXT_RERANK", true}}).text_rerank);
+ EXPECT_TRUE(scoring_tags({{"NPUW_TEXT_RERANK", "YES"}}).text_rerank);
+ EXPECT_TRUE(scoring_tags({{"NPUW_TEXT_EMBED", true}}).text_embed);
+ EXPECT_FALSE(scoring_tags({{"NPUW_TEXT_EMBED", true}}).text_rerank);
+ EXPECT_TRUE(scoring_tags({{"NPUW_LLM", true}, {"NPUW_TEXT_RERANK", true}}).text_rerank);
+}
+
+// The wrap is part of the blob. export_model() writes the batched header in front
+// of the inner blob, which is what the plugin's import dispatch keys on.
+TEST_F(NPUWBatchedElementTest, ExportWritesBatchedHeader) {
+ const auto wrapped = wrap();
+
+ std::stringstream stream;
+ wrapped->export_model(stream);
+
+ ov::npuw::s11n::IndicatorType serialization_indicator{};
+ stream.read(reinterpret_cast<char*>(serialization_indicator.data()), serialization_indicator.size());
+ EXPECT_EQ(serialization_indicator, NPUW_SERIALIZATION_INDICATOR);
+
+ ov::npuw::s11n::IndicatorType batched_indicator{};
+ stream.read(reinterpret_cast<char*>(batched_indicator.data()), batched_indicator.size());
+ EXPECT_EQ(batched_indicator, NPUW_BATCHED_COMPILED_MODEL_INDICATOR);
+
+ int vmajor = 0, vminor = 0, vpatch = 0;
+ std::string s11n_version;
+ ov::npuw::s11n::read(stream, vmajor);
+ ov::npuw::s11n::read(stream, vminor);
+ ov::npuw::s11n::read(stream, vpatch);
+ ov::npuw::s11n::read(stream, s11n_version);
+ EXPECT_EQ(vmajor, OPENVINO_VERSION_MAJOR);
+ EXPECT_EQ(vminor, OPENVINO_VERSION_MINOR);
+ EXPECT_EQ(vpatch, OPENVINO_VERSION_PATCH);
+ EXPECT_EQ(s11n_version, std::string(NPUW_SERIALIZATION_VERSION));
+
+ // The scoring tags follow the version fields, so import restores them from
+ // the header alone.
+ bool text_rerank = false;
+ bool text_embed = true;
+ ov::npuw::s11n::read(stream, text_rerank);
+ ov::npuw::s11n::read(stream, text_embed);
+ EXPECT_TRUE(text_rerank);
+ EXPECT_FALSE(text_embed);
+
+ // The mock inner writes nothing, so the header is the whole stream.
+ EXPECT_EQ(stream.peek(), std::char_traits<char>::eof());
+}
+
+// The scoring tags are wrapper state: the inner model never records them, so the
+// wrapper answers them itself and forwards every other property.
+TEST_F(NPUWBatchedElementTest, WrapperReportsScoringTags) {
+ const auto wrapped = wrap();
+ EXPECT_TRUE(wrapped->get_property("NPUW_TEXT_RERANK").as<bool>());
+ EXPECT_FALSE(wrapped->get_property("NPUW_TEXT_EMBED").as<bool>());
+}
+
+TEST_F(NPUWBatchedElementTest, ForwardsInnerIO) {
+ auto inner = make_inner();
+ auto wrapped = std::make_shared<ov::npuw::batched::CompiledModel>(inner, m_plugin, rerank_tags());
+ // The wrapper adds no I/O of its own -- it exposes the inner model's ports.
+ EXPECT_EQ(&wrapped->inputs(), &inner->inputs());
+ EXPECT_EQ(&wrapped->outputs(), &inner->outputs());
+}
+
+TEST_F(NPUWBatchedElementTest, EachRowScoredIndependentlyAndStacked) {
+ auto wrapped = wrap();
+ auto req = wrapped->create_infer_request();
+
+ // Distinct first tokens so a misrouted row would surface as a wrong output value.
+ const std::vector<std::vector<int64_t>> ids = {{11, 2, 3, 4}, {22, 5, 6, 7}, {33, 8, 9, 10}};
+ bind_inputs(req, ids);
+
+ req->infer();
+
+ const auto out = req->get_tensor(wrapped->outputs()[0]);
+ ASSERT_EQ(out->get_shape()[0], ids.size());
+ for (std::size_t r = 0; r < ids.size(); ++r) {
+ EXPECT_FLOAT_EQ(row_value(out, r), static_cast<float>(ids[r].front())) << "output row " << r;
+ }
+
+ // One inner inference per row, each preceded by a state reset, in order.
+ EXPECT_EQ(m_recorder->events, (std::vector<std::string>{"reset", "infer", "reset", "infer", "reset", "infer"}));
+}
+
+// LoRA adapter states carry the adapter weights and their reset() throws, so the
+// element must leave them out of the per-row reset. The mock inner exposes such a
+// state on every request; a multi-row infer completing at all proves the skip, and
+// the event log proves the ordinary state still gets its per-row reset.
+TEST_F(NPUWBatchedElementTest, AdapterStateExcludedFromRowResets) {
+ auto wrapped = wrap();
+ auto req = wrapped->create_infer_request();
+
+ const std::vector<std::vector<int64_t>> ids = {{5, 1, 1, 1}, {6, 2, 2, 2}};
+ bind_inputs(req, ids);
+
+ ASSERT_NO_THROW(req->infer());
+ EXPECT_EQ(m_recorder->events, (std::vector<std::string>{"reset", "infer", "reset", "infer"}));
+}
+
+TEST_F(NPUWBatchedElementTest, SingleRowScored) {
+ auto wrapped = wrap();
+ auto req = wrapped->create_infer_request();
+
+ const std::vector<std::vector<int64_t>> ids = {{42, 8, 9, 10}};
+ bind_inputs(req, ids);
+
+ req->infer();
+
+ const auto out = req->get_tensor(wrapped->outputs()[0]);
+ ASSERT_EQ(out->get_shape()[0], 1u);
+ EXPECT_FLOAT_EQ(row_value(out, 0), static_cast<float>(ids[0].front()));
+ EXPECT_EQ(m_recorder->events, (std::vector<std::string>{"reset", "infer"}));
+}
+
+// A zero-row batch has nothing to score and would publish unpopulated outputs.
+TEST_F(NPUWBatchedElementTest, ZeroBatchIsRejected) {
+ auto wrapped = wrap();
+ auto req = wrapped->create_infer_request();
+
+ bind_inputs(req, {{1, 2, 3, 4}});
+ bind_input(req, "input_ids", {0, 4});
+
+ try {
+ req->infer();
+ FAIL() << "expected a zero-batch rejection";
+ } catch (const ov::Exception& ex) {
+ EXPECT_NE(error_message(ex).find("zero-sized batch dimension"), std::string::npos);
+ }
+ EXPECT_TRUE(m_recorder->events.empty());
+}
+
+// input_ids fixes N=3; an attention_mask with batch 2 (neither N nor 1) cannot be sliced
+// per row and must be rejected rather than fed whole into the batch-1 inner.
+TEST_F(NPUWBatchedElementTest, MismatchedBatchRejected) {
+ auto wrapped = wrap();
+ auto req = wrapped->create_infer_request();
+
+ bind_inputs(req, {{1, 2}, {3, 4}, {5, 6}});
+ bind_input(req, "attention_mask", {2, 2});
+
+ try {
+ req->infer();
+ FAIL() << "expected a batch-mismatch rejection";
+ } catch (const ov::Exception& ex) {
+ EXPECT_NE(error_message(ex).find("neither the inferred batch size"), std::string::npos);
+ }
+ EXPECT_TRUE(m_recorder->events.empty());
+}
+
+// A shared input (batch 1) is fed to every row whole -- only inputs carrying the full
+// batch are sliced, so a [1, L] input is never sliced out of range.
+TEST_F(NPUWBatchedElementTest, SharedInputBoundToEveryRow) {
+ auto wrapped = wrap();
+ auto req = wrapped->create_infer_request();
+
+ const std::vector<std::vector<int64_t>> ids = {{11, 1, 1, 1}, {22, 1, 1, 1}, {33, 1, 1, 1}};
+ bind_inputs(req, ids);
+ bind_input(req, "attention_mask", {1, 4}); // shared across the 3 rows
+
+ req->infer();
+
+ const auto out = req->get_tensor(wrapped->outputs()[0]);
+ ASSERT_EQ(out->get_shape()[0], ids.size());
+ for (std::size_t r = 0; r < ids.size(); ++r) {
+ EXPECT_FLOAT_EQ(row_value(out, r), static_cast<float>(ids[r].front())) << "output row " << r;
+ }
+ EXPECT_EQ(m_recorder->events, (std::vector<std::string>{"reset", "infer", "reset", "infer", "reset", "infer"}));
+}
+
+// Regression: a leading batch-1 input (here input_ids, shared) must not pin the batch to 1
+// when a later input carries the real batch -- a leading dim of 1 means broadcast, and the
+// batch is whatever the batched inputs agree on.
+TEST_F(NPUWBatchedElementTest, BatchSizeFromNonLeadingInput) {
+ auto wrapped = wrap();
+ auto req = wrapped->create_infer_request();
+
+ bind_inputs(req, {{7, 1, 1, 1}}); // input_ids = [1, 4], shared prompt (token 7)
+ bind_input(req, "attention_mask", {3, 4}); // real batch N = 3 on a non-leading input
+
+ req->infer();
+
+ const auto out = req->get_tensor(wrapped->outputs()[0]);
+ ASSERT_EQ(out->get_shape()[0], 3u);
+ for (std::size_t r = 0; r < 3; ++r) {
+ EXPECT_FLOAT_EQ(row_value(out, r), 7.0f) << "output row " << r; // input_ids shared with every row
+ }
+ EXPECT_EQ(m_recorder->events, (std::vector<std::string>{"reset", "infer", "reset", "infer", "reset", "infer"}));
+}
+
+// Each model output is stacked into its own [N, ...] tensor. The mock offsets output k by k, so the
+// two outputs must differ per row.
+TEST_F(NPUWBatchedElementTest, MultipleOutputsStackedIndependently) {
+ auto model = build_two_output_model();
+ auto inner = std::make_shared<MockInnerCompiled>(model, m_plugin, m_recorder);
+ auto wrapped = std::make_shared<ov::npuw::batched::CompiledModel>(inner, m_plugin, rerank_tags());
+ auto req = wrapped->create_infer_request();
+
+ const std::vector<std::vector<int64_t>> ids = {{11, 1}, {22, 1}, {33, 1}};
+ set_input_ids(req, ids); // the two-output model has only input_ids
+
+ req->infer();
+
+ ASSERT_EQ(wrapped->outputs().size(), 2u);
+ const auto score = req->get_tensor(wrapped->outputs()[0]);
+ const auto hidden = req->get_tensor(wrapped->outputs()[1]);
+ ASSERT_EQ(score->get_shape()[0], ids.size());
+ ASSERT_EQ(hidden->get_shape()[0], ids.size());
+ for (std::size_t r = 0; r < ids.size(); ++r) {
+ EXPECT_FLOAT_EQ(row_value(score, r), static_cast<float>(ids[r].front()));
+ EXPECT_FLOAT_EQ(row_value(hidden, r), static_cast<float>(ids[r].front()) + kOutputChannelOffset);
+ }
+ EXPECT_EQ(m_recorder->events, (std::vector<std::string>{"reset", "infer", "reset", "infer", "reset", "infer"}));
+}
+
+// A caller-bound output tensor of the right shape and type is written in place, not replaced.
+TEST_F(NPUWBatchedElementTest, PreBoundOutputTensorReused) {
+ auto model = build_two_output_model();
+ auto inner = std::make_shared<MockInnerCompiled>(model, m_plugin, m_recorder);
+ auto wrapped = std::make_shared<ov::npuw::batched::CompiledModel>(inner, m_plugin, rerank_tags());
+ auto req = wrapped->create_infer_request();
+
+ const std::vector<std::vector<int64_t>> ids = {{11, 1}, {22, 1}, {33, 1}};
+ set_input_ids(req, ids);
+
+ // The mock produces [1, 1] outputs (dynamic dims sized to 1), so the stacked shape is [3, 1].
+ auto bound = ov::get_tensor_impl(ov::Tensor(ov::element::f32, {3, 1}));
+ req->set_tensor(wrapped->outputs()[0], bound);
+
+ req->infer();
+
+ const auto out = req->get_tensor(wrapped->outputs()[0]);
+ EXPECT_EQ(out->data(), bound->data());
+ for (std::size_t r = 0; r < ids.size(); ++r) {
+ EXPECT_FLOAT_EQ(row_value(out, r), static_cast<float>(ids[r].front()));
+ }
+}
+
+// A caller-bound output tensor is never replaced: one of the wrong shape is
+// resized in place via set_shape once the produced shape is known, the way
+// plugins treat dynamic outputs, and the rows land in the caller's tensor.
+TEST_F(NPUWBatchedElementTest, PreBoundOutputResizedInPlace) {
+ auto model = build_two_output_model();
+ auto inner = std::make_shared<MockInnerCompiled>(model, m_plugin, m_recorder);
+ auto wrapped = std::make_shared<ov::npuw::batched::CompiledModel>(inner, m_plugin, rerank_tags());
+ auto req = wrapped->create_infer_request();
+
+ const std::vector<std::vector<int64_t>> ids = {{11, 1}, {22, 1}, {33, 1}};
+ set_input_ids(req, ids);
+
+ // The stacked shape will be [3, 1]; bind an undersized [2, 1] caller tensor.
+ auto bound = ov::get_tensor_impl(ov::Tensor(ov::element::f32, {2, 1}));
+ req->set_tensor(wrapped->outputs()[0], bound);
+
+ req->infer();
+
+ const auto out = req->get_tensor(wrapped->outputs()[0]);
+ EXPECT_EQ(out._ptr, bound._ptr);
+ ASSERT_EQ(out->get_shape(), (ov::Shape{3, 1}));
+ for (std::size_t r = 0; r < ids.size(); ++r) {
+ EXPECT_FLOAT_EQ(row_value(out, r), static_cast<float>(ids[r].front()));
+ }
+}
+
+// The caller's tensor stays bound across batch changes, resized each time,
+// including down to a single row.
+TEST_F(NPUWBatchedElementTest, PreBoundOutputResizedAcrossBatchChanges) {
+ auto model = build_two_output_model();
+ auto inner = std::make_shared<MockInnerCompiled>(model, m_plugin, m_recorder);
+ auto wrapped = std::make_shared<ov::npuw::batched::CompiledModel>(inner, m_plugin, rerank_tags());
+ auto req = wrapped->create_infer_request();
+
+ auto bound = ov::get_tensor_impl(ov::Tensor(ov::element::f32, {3, 1}));
+ req->set_tensor(wrapped->outputs()[0], bound);
+
+ set_input_ids(req, {{11, 1}, {22, 1}, {33, 1}});
+ req->infer();
+ ASSERT_EQ(req->get_tensor(wrapped->outputs()[0])._ptr, bound._ptr);
+
+ set_input_ids(req, {{44, 1}, {55, 1}});
+ req->infer();
+ auto out = req->get_tensor(wrapped->outputs()[0]);
+ EXPECT_EQ(out._ptr, bound._ptr);
+ ASSERT_EQ(out->get_shape(), (ov::Shape{2, 1}));
+ EXPECT_FLOAT_EQ(row_value(out, 0), 44.0f);
+ EXPECT_FLOAT_EQ(row_value(out, 1), 55.0f);
+
+ set_input_ids(req, {{66, 1}});
+ req->infer();
+ out = req->get_tensor(wrapped->outputs()[0]);
+ EXPECT_EQ(out._ptr, bound._ptr);
+ ASSERT_EQ(out->get_shape(), (ov::Shape{1, 1}));
+ EXPECT_FLOAT_EQ(row_value(out, 0), 66.0f);
+}
+
+// A type mismatch cannot be resized away: the base request already rejects the
+// bind itself (the element's own type check only backstops dynamic-typed ports).
+TEST_F(NPUWBatchedElementTest, PreBoundOutputTypeMismatchThrows) {
+ auto model = build_two_output_model();
+ auto inner = std::make_shared<MockInnerCompiled>(model, m_plugin, m_recorder);
+ auto wrapped = std::make_shared<ov::npuw::batched::CompiledModel>(inner, m_plugin, rerank_tags());
+ auto req = wrapped->create_infer_request();
+
+ set_input_ids(req, {{11, 1}, {22, 1}, {33, 1}});
+
+ auto bound = ov::get_tensor_impl(ov::Tensor(ov::element::f16, {3, 1}));
+ EXPECT_THROW(req->set_tensor(wrapped->outputs()[0], bound), ov::Exception);
+}
+
+// A fixed-capacity view over caller memory that cannot hold the result throws
+// from set_shape itself rather than being silently replaced.
+TEST_F(NPUWBatchedElementTest, NonResizablePreBoundOutputThrows) {
+ auto model = build_two_output_model();
+ auto inner = std::make_shared<MockInnerCompiled>(model, m_plugin, m_recorder);
+ auto wrapped = std::make_shared<ov::npuw::batched::CompiledModel>(inner, m_plugin, rerank_tags());
+ auto req = wrapped->create_infer_request();
+
+ set_input_ids(req, {{11, 1}, {22, 1}, {33, 1}});
+
+ float caller_memory[2] = {};
+ auto bound = ov::get_tensor_impl(ov::Tensor(ov::element::f32, ov::Shape{2, 1}, caller_memory));
+ req->set_tensor(wrapped->outputs()[0], bound);
+
+ EXPECT_THROW(req->infer(), ov::Exception);
+}
+
+// With no output bound, the element allocates its own on the first infer, keeps
+// it while the batch holds and gets a fresh one when the batch changes, growing
+// and shrinking; the rows are always right.
+TEST_F(NPUWBatchedElementTest, ElementOutputsFollowBatchChanges) {
+ auto model = build_two_output_model();
+ auto inner = std::make_shared<MockInnerCompiled>(model, m_plugin, m_recorder);
+ auto wrapped = std::make_shared<ov::npuw::batched::CompiledModel>(inner, m_plugin, rerank_tags());
+ auto req = wrapped->create_infer_request();
+
+ set_input_ids(req, {{11, 1}, {22, 1}, {33, 1}});
+ req->infer();
+ const auto first = req->get_tensor(wrapped->outputs()[0]);
+ ASSERT_EQ(first->get_shape()[0], 3u);
+
+ // Same batch: the same tensor is written again.
+ set_input_ids(req, {{12, 1}, {23, 1}, {34, 1}});
+ req->infer();
+ const auto same = req->get_tensor(wrapped->outputs()[0]);
+ EXPECT_EQ(same._ptr, first._ptr);
+ EXPECT_FLOAT_EQ(row_value(same, 2), 34.0f);
+
+ set_input_ids(req, {{44, 1}, {55, 1}});
+ ASSERT_NO_THROW(req->infer());
+ const auto out = req->get_tensor(wrapped->outputs()[0]);
+ ASSERT_EQ(out->get_shape()[0], 2u);
+ EXPECT_FLOAT_EQ(row_value(out, 0), 44.0f);
+ EXPECT_FLOAT_EQ(row_value(out, 1), 55.0f);
+
+ set_input_ids(req, {{66, 1}});
+ ASSERT_NO_THROW(req->infer());
+ const auto single = req->get_tensor(wrapped->outputs()[0]);
+ ASSERT_EQ(single->get_shape()[0], 1u);
+ EXPECT_FLOAT_EQ(row_value(single, 0), 66.0f);
+
+ set_input_ids(req, {{77, 1}, {88, 1}, {99, 1}, {100, 1}});
+ ASSERT_NO_THROW(req->infer());
+ const auto grown = req->get_tensor(wrapped->outputs()[0]);
+ ASSERT_EQ(grown->get_shape()[0], 4u);
+ EXPECT_FLOAT_EQ(row_value(grown, 3), 100.0f);
+}
+
+// Nothing is bound or allocated up front: before the first infer the public
+// tensors are the inner request's own, inputs and outputs alike, and after it
+// the output is the element's stacked copy, never the inner's tensor.
+TEST_F(NPUWBatchedElementTest, UnboundTensorsDefaultToTheInner) {
+ auto model = build_two_output_model();
+ auto inner = std::make_shared<MockInnerCompiled>(model, m_plugin, m_recorder);
+ auto wrapped = std::make_shared<ov::npuw::batched::CompiledModel>(inner, m_plugin, rerank_tags());
+ auto req = wrapped->create_infer_request();
+ auto inner_req = inner->last_request();
+ ASSERT_TRUE(inner_req);
+
+ const auto in_port = wrapped->inputs()[0];
+ const auto out_port = wrapped->outputs()[0];
+ EXPECT_EQ(req->get_tensor(in_port)._ptr, inner_req->get_tensor(in_port)._ptr);
+ EXPECT_EQ(req->get_tensor(out_port)._ptr, inner_req->get_tensor(out_port)._ptr);
+
+ set_input_ids(req, {{42, 1}, {43, 1}});
+ req->infer();
+ const auto out = req->get_tensor(out_port);
+ EXPECT_NE(out._ptr, inner_req->get_tensor(out_port)._ptr);
+ ASSERT_EQ(out->get_shape()[0], 2u);
+ EXPECT_FLOAT_EQ(row_value(out, 1), 43.0f);
+}
+
+// A single row goes through the same path: a caller-bound tensor of the fitting
+// shape is written in place, and the public output is the element's own copy,
+// never the inner's tensor.
+TEST_F(NPUWBatchedElementTest, SingleRowPreBoundOutputWrittenInPlace) {
+ auto model = build_two_output_model();
+ auto inner = std::make_shared<MockInnerCompiled>(model, m_plugin, m_recorder);
+ auto wrapped = std::make_shared<ov::npuw::batched::CompiledModel>(inner, m_plugin, rerank_tags());
+ auto req = wrapped->create_infer_request();
+
+ set_input_ids(req, {{42, 1}});
+
+ auto bound = ov::get_tensor_impl(ov::Tensor(ov::element::f32, {1, 1}));
+ req->set_tensor(wrapped->outputs()[0], bound);
+
+ req->infer();
+
+ const auto out = req->get_tensor(wrapped->outputs()[0]);
+ EXPECT_EQ(out->data(), bound->data());
+ EXPECT_FLOAT_EQ(row_value(out, 0), 42.0f);
+ EXPECT_EQ(m_recorder->events, (std::vector<std::string>{"reset", "infer"}));
+}
+
+// The blob round trip on the real import path: the synthetic LLM is written to
+// disk like a converted model, so its constants carry weights-file offsets and
+// the blob is weightless. Compiled with the rerank tag it exports a batched blob,
+// the import dispatch rebuilds the wrapper from it with only WEIGHTS_PATH
+// supplied, and the imported model stacks a batch row for row like the compiled
+// one scores single prompts.
+TEST(NPUWBatchedElementRoundTrip, ExportImportRebuildsTheWrapAndStacks) {
+ constexpr std::size_t kRows = 3;
+ constexpr std::size_t kLen = 6;
+
+ ov::Core core;
+ const auto tmp = std::filesystem::temp_directory_path() / "npuw_batched_round_trip";
+ std::filesystem::create_directories(tmp);
+ const auto xml = tmp / "model.xml";
+ const auto bin = tmp / "model.bin";
+ ov::serialize(build_llm_test_model(), xml.string(), bin.string());
+ auto model = core.read_model(xml.string());
+ // The online partitioner's repeated-block detection does not cope with the
+ // synthetic model, so the sub-models are compiled whole on CPU.
+ const ov::AnyMap props = {{"NPU_USE_NPUW", "YES"},
+ {"NPUW_LLM", "YES"},
+ {"NPUW_DEVICES", "CPU"},
+ {"NPUW_ONLINE_PIPELINE", "NONE"},
+ {"NPUW_LLM_MAX_PROMPT_LEN", "32"},
+ {"NPUW_LLM_MIN_RESPONSE_LEN", "8"},
+ {"NPUW_TEXT_RERANK", "YES"}};
+ auto compiled = core.compile_model(model, "NPU", props);
+ ASSERT_TRUE(compiled.get_property("NPUW_TEXT_RERANK").as<bool>());
+
+ std::stringstream blob;
+ compiled.export_model(blob);
+ auto import_props = props;
+ import_props[ov::weights_path.name()] = bin.string();
+ auto imported = core.import_model(blob, "NPU", import_props);
+ EXPECT_TRUE(imported.get_property("NPUW_TEXT_RERANK").as<bool>());
+
+ // Row r of a batch carries tokens 1 + first_row + r, so batched row r on the
+ // imported model must equal a single-row infer of the same prompt on the
+ // compiled one.
+ const auto score = [&](ov::CompiledModel& cm, std::size_t rows, std::size_t first_row) {
+ auto req = cm.create_infer_request();
+ ov::Tensor input_ids(ov::element::i64, {rows, kLen});
+ ov::Tensor attention_mask(ov::element::i64, {rows, kLen});
+ ov::Tensor position_ids(ov::element::i64, {rows, kLen});
+ ov::Tensor beam_idx(ov::element::i32, {rows});
+ for (std::size_t r = 0; r < rows; ++r) {
+ for (std::size_t t = 0; t < kLen; ++t) {
+ input_ids.data<int64_t>()[r * kLen + t] = static_cast<int64_t>(1 + first_row + r + t);
+ attention_mask.data<int64_t>()[r * kLen + t] = 1;
+ position_ids.data<int64_t>()[r * kLen + t] = static_cast<int64_t>(t);
+ }
+ beam_idx.data<int32_t>()[r] = 0;
+ }
+ req.set_tensor("input_ids", input_ids);
+ req.set_tensor("attention_mask", attention_mask);
+ req.set_tensor("position_ids", position_ids);
+ req.set_tensor("beam_idx", beam_idx);
+ req.infer();
+ ov::Tensor out(req.get_output_tensor(0).get_element_type(), req.get_output_tensor(0).get_shape());
+ req.get_output_tensor(0).copy_to(out);
+ return out;
+ };
+
+ const auto batched = score(imported, kRows, 0);
+ ASSERT_EQ(batched.get_shape()[0], kRows);
+ const std::size_t row_elems = batched.get_size() / kRows;
+ for (std::size_t r = 0; r < kRows; ++r) {
+ const auto single = score(compiled, 1, r);
+ ASSERT_EQ(single.get_size(), row_elems) << "row " << r;
+ const float* got = batched.data<float>() + r * row_elems;
+ const float* want = single.data<float>();
+ for (std::size_t i = 0; i < row_elems; ++i) {
+ ASSERT_NEAR(got[i], want[i], 1e-5f) << "row " << r << " element " << i;
+ }
+ }
+}
+
+} // namespace
diff --git a/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_factory_options_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_factory_options_test.cpp
index 9e7628456a7..4d7f7d7c5be 100644
--- a/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_factory_options_test.cpp
+++ b/src/plugins/intel_npu/tests/unit/npuw/llm_compiled_model_factory_options_test.cpp
@@ -302,6 +302,21 @@ TEST_F(LLMCompiledModelFactoryOptionsTest, VisibleLlmPropertiesRoundTripThroughC
EXPECT_EQ(compiled->get_property("NPUW_LLM_PREFILL_CHUNK_SIZE").as<uint64_t>(), 0u);
}
+// The rerank tag only gates the batched wrapper at the entry point and must stay
+// out of the submodel configs.
+TEST_F(LLMCompiledModelFactoryOptionsTest, TextRerankTagKeptOutOfStageConfigs) {
+ RecordingFactory recorder;
+ std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;
+
+ ASSERT_NO_THROW(compiled = create_compiled_model(build_llm_model(), {{"NPUW_TEXT_RERANK", "YES"}}, recorder));
+ ASSERT_NE(compiled, nullptr);
+
+ const auto& prefill = require_call(recorder, "_prefill");
+ const auto& generate = require_call_containing(recorder, "_kv");
+ expect_missing_prop(prefill.props, "NPUW_TEXT_RERANK");
+ expect_missing_prop(generate.props, "NPUW_TEXT_RERANK");
+}
+
TEST_F(LLMCompiledModelFactoryOptionsTest, DefaultStageConfigsCarryBaselineNpuwOptions) {
RecordingFactory recorder;
std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;
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 a3d47d05d6e..22b7db64d18 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
@@ -69,8 +69,7 @@ inline std::shared_ptr<ov::Model> build_dynamic_attention_llm_model() {
for (const auto& input : model->inputs()) {
const auto& name = input.get_any_name();
const auto& pshape = input.get_partial_shape();
- if (name.find("input_ids") != std::string::npos ||
- name.find("token_type_ids") != std::string::npos) {
+ if (name.find("input_ids") != std::string::npos || name.find("token_type_ids") != std::string::npos) {
new_shapes[name] = ov::PartialShape{1, kSeq};
} else if (name.find("attention_mask") != std::string::npos) {
new_shapes[name] = ov::PartialShape{1, kSeq + kPast};
@@ -100,6 +99,22 @@ inline std::shared_ptr<ov::Model> build_llm_gqa_test_model() {
return mb.build_llm(make_test_model_config_gqa());
}
+/// Minimal Qwen3-style reranker: a GQA causal decoder with RMSNorm and per-head
+/// Q/K normalization, stateful KV cache and an LM head (logits output). Matches the
+/// I/O signature of Qwen3-Reranker (input_ids/attention_mask/position_ids + beam_idx),
+/// which is what the batched scoring element fans out over.
+inline LLMConfig make_test_model_config_reranker() {
+ auto cfg = make_test_model_config_gqa();
+ cfg.norm = RMSNorm(cfg.hidden_size, cfg.precision);
+ cfg.qk_norm = RMSNorm(cfg.head_dim, cfg.precision);
+ return cfg;
+}
+
+inline std::shared_ptr<ov::Model> build_reranker_test_model() {
+ ModelBuilder mb;
+ return mb.build_llm(make_test_model_config_reranker());
+}
+
inline std::shared_ptr<ov::Model> build_llm_test_model_with_kv_fake_convert(const ov::element::Type fake_convert_type) {
auto model = build_llm_test_model();
auto scale = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{}, {1.0f});
@@ -113,8 +128,7 @@ inline std::shared_ptr<ov::Model> build_llm_test_model_with_kv_fake_convert(cons
auto inject_fake_convert = [&](size_t input_idx, const std::string& suffix) {
auto fake_convert_1 =
std::make_shared<ov::op::v13::FakeConvert>(sdpa->input_value(input_idx), scale, fake_convert_type);
- auto fake_convert_2 =
- std::make_shared<ov::op::v13::FakeConvert>(fake_convert_1, scale, fake_convert_type);
+ auto fake_convert_2 = std::make_shared<ov::op::v13::FakeConvert>(fake_convert_1, scale, fake_convert_type);
fake_convert_1->set_friendly_name(sdpa->get_friendly_name() + "/" + suffix + "_1");
fake_convert_2->set_friendly_name(sdpa->get_friendly_name() + "/" + suffix + "_2");
sdpa->input(input_idx).replace_source_output(fake_convert_2);
@@ -354,8 +368,8 @@ public:
};
struct CompileCall {
- std::string friendly_name;
- ov::AnyMap props;
+ std::string friendly_name;
+ ov::AnyMap props;
std::shared_ptr<ov::Model> model;
};
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 09925f35e4b..26cf60bc9dc 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
@@ -215,4 +215,16 @@ TEST(NPUWConfigOptionsSmokeTest, AttentionHintDefaultsCanDifferPerOption) {
EXPECT_EQ(cfg.getString<::intel_npu::NPUW_LLM_GENERATE_ATTENTION_HINT>(), "STATIC");
}
+// The scoring tags are ordinary exposed options and must parse and survive a
+// config string round trip like any other.
+TEST(NPUWConfigOptionsSmokeTest, ScoringTagsSurviveConfigStringRoundTrip) {
+ const auto cfg = make_config({{"NPUW_TEXT_RERANK", "YES"}, {"NPUW_TEXT_EMBED", "YES"}});
+
+ ::intel_npu::Config restored(make_options_desc());
+ restored.fromString(cfg.toString());
+
+ EXPECT_TRUE(restored.get<::intel_npu::NPUW_TEXT_RERANK>());
+ EXPECT_TRUE(restored.get<::intel_npu::NPUW_TEXT_EMBED>());
+}
+
} // namespace