Skip to content

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

[NPUW] Use shared vocabulary only when the vocabulary is a closure (#40007)

Eugene Smirnov9b48a30867e0
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 bccf9df2e93..11c040afed8 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
@@ -160,6 +160,25 @@ struct NPUDesc {
bool support_flash_attention_tile = false;
};
+// Version of the compiler selected by NPU_COMPILER_TYPE in the config (the default compiler if it is not set).
+int64_t query_compiler_version(const std::shared_ptr<const ov::IPlugin>& plugin, const ov::AnyMap& config) {
+ const auto compiler_type_it = config.find(ov::intel_npu::compiler_type.name());
+ if (compiler_type_it == config.end()) {
+ return plugin->get_property(ov::intel_npu::compiler_version.name(), ov::AnyMap{}).as<int64_t>();
+ }
+ return plugin
+ ->get_property(ov::intel_npu::compiler_version.name(),
+ ov::AnyMap{{ov::intel_npu::compiler_type.name(), compiler_type_it->second.as<std::string>()}})
+ .as<int64_t>();
+}
+
+// Zero point decomposition for weights-as-inputs dequantization, where the zero point and the scale are
+// also model inputs (DynamicDequantize becomes Dequantize). Supported starting from compiler 8.5
+// (EISW-229457).
+bool compiler_supports_dynamic_zp_decomposition(const int64_t compiler_ver) {
+ return compiler_ver >= ONEAPI_MAKE_VERSION(8, 5);
+}
+
std::optional<NPUDesc> extract_npu_descriptor(const std::shared_ptr<const ov::IPlugin>& plugin,
const ov::AnyMap& config) {
if (!plugin->get_core()) {
@@ -188,19 +207,7 @@ std::optional<NPUDesc> extract_npu_descriptor(const std::shared_ptr<const ov::IP
}
// Get compiler version based on NPU_COMPILER_TYPE configuration
- // If NPU_COMPILER_TYPE is not specified in config, use default compiler version
- auto compiler_type_it = config.find(ov::intel_npu::compiler_type.name());
- if (compiler_type_it == config.end()) {
- // NPU_COMPILER_TYPE is not specified in config, use default compiler version
- desc.compiler_ver = plugin->get_property(ov::intel_npu::compiler_version.name(), ov::AnyMap{}).as<int64_t>();
- } else {
- // NPU_COMPILER_TYPE is specified in config, get compiler version for the specified compiler type
- auto target_compiler_type = compiler_type_it->second.as<std::string>();
- desc.compiler_ver = plugin
- ->get_property(ov::intel_npu::compiler_version.name(),
- ov::AnyMap{{ov::intel_npu::compiler_type.name(), target_compiler_type}})
- .as<int64_t>();
- }
+ desc.compiler_ver = query_compiler_version(plugin, config);
LOG_INFO("Compiler version: " << ONEAPI_VERSION_MAJOR(desc.compiler_ver) << "."
<< ONEAPI_VERSION_MINOR(desc.compiler_ver));
@@ -459,6 +466,29 @@ std::map<std::string, std::string> any_copy(const ov::AnyMap& params) {
return result;
}
+// Partitioning turns the Sub128 shifts of a shared vocabulary into one i8 closure only in function
+// subgraphs that go through Partitioner::optimize(): NPUW_FOLD and NPUW_FUNCALL_FOR_ALL, with
+// NPUW_HOST_GATHER on. NPUW_CWAI is not enough: it is used only without NPUW_FOLD, and its pipeline does not
+// run optimize(), so the shifts would stay in the function body. Without a closure the shifts reach the
+// compiler as they are: no memory is saved, and the LM head becomes several times slower.
+// The options are read with the option set of the stage itself, to get the same defaults and values.
+bool vocab_is_closure(const ov::AnyMap& stage_config) {
+ ov::AnyMap selected;
+ for (const auto key : {::intel_npu::NPUW_FOLD::key(),
+ ::intel_npu::NPUW_FUNCALL_FOR_ALL::key(),
+ ::intel_npu::NPUW_HOST_GATHER::key()}) {
+ if (const auto it = stage_config.find(std::string(key)); it != stage_config.end()) {
+ selected.insert(*it);
+ }
+ }
+ auto options_desc = std::make_shared<::intel_npu::OptionsDesc>();
+ ::intel_npu::registerNPUWOptions(*options_desc);
+ ::intel_npu::Config stage_cfg(options_desc);
+ stage_cfg.update(any_copy(selected));
+ return stage_cfg.get<::intel_npu::NPUW_FOLD>() && stage_cfg.get<::intel_npu::NPUW_FUNCALL_FOR_ALL>() &&
+ stage_cfg.get<::intel_npu::NPUW_HOST_GATHER>();
+}
+
// Detect Gemma-4 E2B/E4B by a consumed "per_layer_inputs" input with nonzero PLE dim.
// Gemma4 26B A4B (MoE) also has this input, but dangling (proj_dim==0, unconsumed).
bool has_per_layer_inputs(const std::shared_ptr<ov::Model>& model) {
@@ -884,12 +914,6 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
m_cfg.update({{"NPUW_LLM_SHARED_HEAD", "NO"}});
m_cfg.update({{"NPUW_LLM_PREFILL_CHUNK_SIZE", "0"}});
m_cfg.update({{"NPUW_LLM_CACHE_ROPE", "NO"}});
- // Shared vocabulary handling makes the decoding of INT4 Whisper models several times slower
- // in the default (not folded) configuration, so it is not used for Whisper.
- if (m_cfg.get<::intel_npu::NPUW_LLM_VOCAB_ASYM_SHARED>()) {
- LOG_INFO("NPUW_LLM_VOCAB_ASYM_SHARED is not used for Whisper and is turned off.");
- m_cfg.update({{"NPUW_LLM_VOCAB_ASYM_SHARED", "NO"}});
- }
m_eos_token_id = m_cfg.get<::intel_npu::NPUW_WHISPER_EOS_TOKEN>();
}
@@ -980,17 +1004,11 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
LOG_DEBUG("Creating kvcache model as clone of passed one.");
auto kvcache_model = model->clone();
+ // Sharing is detected on the whole model, before the LM head is cut off. The Sub128 shifts are
+ // inserted later, when the stage configs are known.
+ bool shared_vocab = false;
if (m_cfg.get<::intel_npu::NPUW_LLM_VOCAB_ASYM_SHARED>()) {
- bool shared_vocab = false;
- ov::npuw::DetectVocabSharing detect_vocab_sharing(shared_vocab);
- detect_vocab_sharing.run_on_model(kvcache_model);
- if (shared_vocab) {
- ov::npuw::InsertVocabSub128 pass;
- if (!pass.run_on_model(kvcache_model)) {
- // Sharing was detected, but the shared vocabulary is not u8 asymmetric (e.g. f16 or i4).
- LOG_INFO("Shared vocabulary is not asymmetric u8 - graph Sub128 insertion is skipped.");
- }
- }
+ ov::npuw::DetectVocabSharing(shared_vocab).run_on_model(kvcache_model);
}
auto use_text_embed_key = pop_option(other_props, std::string("NPUW_TEXT_EMBED"));
@@ -1644,6 +1662,53 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
}
}
+ ov::AnyMap lm_head_config;
+ if (lm_head_model) {
+ lm_head_config = get_default_lm_head_config(npudesc);
+ merge_config_with(lm_head_config, other_props);
+ auto lm_head_config_addition_value = lm_head_config_addition.value_or(ov::AnyMap{}).as<ov::AnyMap>();
+ merge_config_with(lm_head_config, lm_head_config_addition_value);
+ apply_weights_bank_name(lm_head_config, weights_bank_name);
+ }
+
+ if (shared_vocab) {
+ // The shared vocabulary makes the LM head dequantize the weights with the zero point and the scale as
+ // inputs. Without the compiler zero point decomposition for this case the LM head becomes several times
+ // slower, so the default is turned off. The compiler is the one selected by the final LM head config,
+ // which can differ from the top-level one. An explicit NPUW_LLM_VOCAB_ASYM_SHARED=YES is kept.
+ const bool set_by_user = npuw_llm_props.count(std::string(::intel_npu::NPUW_LLM_VOCAB_ASYM_SHARED::key())) > 0;
+ const auto head_compiler_ver = lm_head_model && npudesc.has_value() && !set_by_user
+ ? query_compiler_version(plugin, lm_head_config)
+ : int64_t{0};
+ const bool compiler_supports =
+ !npudesc.has_value() || set_by_user || compiler_supports_dynamic_zp_decomposition(head_compiler_ver);
+ const bool vocab_is_closure_in_all_stages = vocab_is_closure(prefill_config) &&
+ vocab_is_closure(generate_config) &&
+ (lm_head_model && vocab_is_closure(lm_head_config));
+ if (!lm_head_model) {
+ // Without a separate LM head model the embedding and the LM head are in one model. If the embedding
+ // matches the quantized host gather (hidden size 2048 or more), the partitioner uses it for the whole
+ // model and does not run ConvertDQVocab, so the Sub128 shifts of the LM head reach the compiler.
+ LOG_INFO("NPUW_LLM_VOCAB_ASYM_SHARED is turned off: it needs NPUW_LLM_SHARED_HEAD.");
+ m_cfg.update({{"NPUW_LLM_VOCAB_ASYM_SHARED", "NO"}});
+ } else if (!compiler_supports) {
+ LOG_INFO("NPUW_LLM_VOCAB_ASYM_SHARED is turned off: it needs NPU compiler 8.5 or newer for the LM head, "
+ "the compiler is "
+ << ONEAPI_VERSION_MAJOR(head_compiler_ver) << "." << ONEAPI_VERSION_MINOR(head_compiler_ver)
+ << ".");
+ m_cfg.update({{"NPUW_LLM_VOCAB_ASYM_SHARED", "NO"}});
+ } else if (!vocab_is_closure_in_all_stages) {
+ LOG_INFO("NPUW_LLM_VOCAB_ASYM_SHARED is turned off: it needs NPUW_FOLD, NPUW_FUNCALL_FOR_ALL and "
+ "NPUW_HOST_GATHER in every stage.");
+ m_cfg.update({{"NPUW_LLM_VOCAB_ASYM_SHARED", "NO"}});
+ } else {
+ if (!ov::npuw::InsertVocabSub128().run_on_model(lm_head_model)) {
+ // Sharing was detected, but the shared vocabulary is not u8 asymmetric (e.g. f16 or i4).
+ LOG_INFO("Shared vocabulary is not asymmetric u8 - graph Sub128 insertion is skipped.");
+ }
+ }
+ }
+
// Compile multiple generate model variants with different sizes
compile_generate_model_variants(generate_model_variants, plugin, generate_config);
@@ -1656,13 +1721,6 @@ ov::npuw::LLMCompiledModel::LLMCompiledModel(const std::shared_ptr<ov::Model>& m
find_other_outputs_with_seqdim(m_prefill_compiled, other_dynamic_outputs, m_prefill_chunk_size);
}
if (lm_head_model) {
- auto lm_head_config = get_default_lm_head_config(npudesc);
- merge_config_with(lm_head_config, other_props);
- auto lm_head_config_addition_value = lm_head_config_addition.value_or(ov::AnyMap{}).as<ov::AnyMap>();
- merge_config_with(lm_head_config, lm_head_config_addition_value);
-
- apply_weights_bank_name(lm_head_config, weights_bank_name);
-
m_lm_head_compiled = m_compiled_model_factory(lm_head_model, plugin, lm_head_config);
NPUW_ASSERT(m_lm_head_compiled);
}
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 dc9884d36a5..549f88db050 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
@@ -7,6 +7,7 @@
#include <algorithm>
#include <array>
#include <limits>
+#include <map>
#include <memory>
#include <sstream>
#include <string>
@@ -68,12 +69,16 @@ bool has_transposed_value_matmul(const std::shared_ptr<ov::Model>& model, std::s
class ArchAwarePlugin final : public NullPlugin {
public:
- ArchAwarePlugin(std::string arch, int64_t max_tiles, int64_t compiler_version = 0)
+ ArchAwarePlugin(std::string arch,
+ int64_t max_tiles,
+ int64_t compiler_version = 0,
+ std::map<std::string, int64_t> compiler_version_by_type = {})
: m_arch(std::move(arch)),
m_max_tiles(max_tiles),
- m_compiler_version(compiler_version) {}
+ m_compiler_version(compiler_version),
+ m_compiler_version_by_type(std::move(compiler_version_by_type)) {}
- ov::Any get_property(const std::string& name, const ov::AnyMap&) const override {
+ ov::Any get_property(const std::string& name, const ov::AnyMap& arguments) const override {
if (name == ov::device::architecture.name()) {
return m_arch;
}
@@ -81,6 +86,13 @@ public:
return m_max_tiles;
}
if (name == ov::intel_npu::compiler_version.name()) {
+ const auto type = arguments.find(ov::intel_npu::compiler_type.name());
+ if (type != arguments.end()) {
+ const auto version = m_compiler_version_by_type.find(type->second.as<std::string>());
+ if (version != m_compiler_version_by_type.end()) {
+ return version->second;
+ }
+ }
return m_compiler_version;
}
if (name == ov::supported_properties.name()) {
@@ -93,6 +105,7 @@ private:
std::string m_arch;
int64_t m_max_tiles;
int64_t m_compiler_version;
+ std::map<std::string, int64_t> m_compiler_version_by_type;
};
std::shared_ptr<ov::MockICore> attach_mock_core_with_npu_device(
@@ -895,10 +908,9 @@ TEST_F(LLMCompiledModelFactoryOptionsTest, ArchAutoDetectSkipsNpuTilesInDefaultS
for (const auto* call : {&prefill, &generate, &head}) {
expect_missing_prop(call->props, "NPU_TILES");
- expect_prop(
- call->props,
- "NPU_COMPILATION_MODE_PARAMS",
- "compute-layers-with-higher-precision=Sqrt,Power,ReduceMean,Add_RMSNorm");
+ expect_prop(call->props,
+ "NPU_COMPILATION_MODE_PARAMS",
+ "compute-layers-with-higher-precision=Sqrt,Power,ReduceMean,Add_RMSNorm");
}
}
@@ -1253,16 +1265,18 @@ TEST_F(LLMCompiledModelFactoryOptionsTest, WhisperInt8DisablesWsStageOptions) {
}
}
-// Makes the embedding and the LM head (proj_out) of the synthetic Whisper decoder read one u8
-// asymmetric vocabulary, as in an INT4 Whisper model with tied weights. As in a real IR, each reader
+// Makes the embedding and the LM head of a synthetic model read one u8 asymmetric vocabulary, as in
+// an INT4 model with tied weights. As in a real IR, each reader
// has its own dequantization over the same constants.
-void share_u8_asym_vocabulary(const std::shared_ptr<ov::Model>& model) {
+void share_u8_asym_vocabulary(const std::shared_ptr<ov::Model>& model,
+ const std::string& embedding_weight_name,
+ const std::string& head_name) {
std::shared_ptr<ov::Node> embedding_weight;
std::shared_ptr<ov::Node> head;
for (const auto& node : model->get_ordered_ops()) {
- if (node->get_friendly_name() == "model.decoder.embed_tokens.weight") {
+ if (node->get_friendly_name() == embedding_weight_name) {
embedding_weight = node;
- } else if (ov::is_type<ov::op::v0::MatMul>(node) && node->get_friendly_name() == "proj_out/MatMul") {
+ } else if (ov::is_type<ov::op::v0::MatMul>(node) && node->get_friendly_name() == head_name + "/MatMul") {
head = node;
}
}
@@ -1275,9 +1289,8 @@ void share_u8_asym_vocabulary(const std::shared_ptr<ov::Model>& model) {
auto weight = ov::op::v0::Constant::create(ov::element::u8,
vocab_shape,
std::vector<uint8_t>(ov::shape_size(vocab_shape), 200));
- auto zero_point = ov::op::v0::Constant::create(ov::element::u8,
- channel_shape,
- std::vector<uint8_t>(vocab_shape[0], 128));
+ auto zero_point =
+ ov::op::v0::Constant::create(ov::element::u8, channel_shape, std::vector<uint8_t>(vocab_shape[0], 128));
auto scale =
ov::op::v0::Constant::create(ov::element::f32, channel_shape, std::vector<float>(vocab_shape[0], 0.01f));
auto dequantize = [&]() -> ov::Output<ov::Node> {
@@ -1301,26 +1314,175 @@ std::size_t count_sub128_shifts(const std::shared_ptr<ov::Model>& model) {
});
}
-TEST_F(LLMCompiledModelFactoryOptionsTest, WhisperDoesNotUseSharedVocabulary) {
- auto model = build_whisper_decoder_model();
- share_u8_asym_vocabulary(model);
- bool shared = false;
- ov::npuw::DetectVocabSharing(shared).run_on_model(model->clone());
- ASSERT_TRUE(shared) << "The test model must have a shared u8 asymmetric vocabulary";
+struct Sub128Shifts {
+ std::size_t prefill = 0;
+ std::size_t generate = 0;
+ std::size_t lm_head = 0;
+};
- RecordingFactory recorder;
- std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;
- ASSERT_NO_THROW(compiled = create_compiled_model(model,
- {{"NPUW_WHISPER", "YES"},
- {"NPUW_WHISPER_EOS_TOKEN", "42"},
- {"NPUW_LLM_VOCAB_ASYM_SHARED", "YES"}},
- recorder));
- ASSERT_NE(compiled, nullptr);
+class LLMCompiledModelSharedVocabularyTest : public LLMCompiledModelFactoryOptionsTest {
+protected:
+ // Compiles the model with a shared u8 asymmetric vocabulary and counts the Sub128 shifts in each stage.
+ Sub128Shifts compile_with_shared_vocabulary(const std::shared_ptr<ov::Model>& model,
+ const std::string& embedding_weight_name,
+ const std::string& head_name,
+ ov::AnyMap props) {
+ share_u8_asym_vocabulary(model, embedding_weight_name, head_name);
+ bool shared = false;
+ ov::npuw::DetectVocabSharing(shared).run_on_model(model->clone());
+ EXPECT_TRUE(shared) << "The test model must have a shared u8 asymmetric vocabulary";
- const auto& prefill = require_call(recorder, "_prefill");
- const auto& generate = require_call_containing(recorder, "_kv");
- EXPECT_EQ(count_sub128_shifts(prefill.model), 0u);
- EXPECT_EQ(count_sub128_shifts(generate.model), 0u);
+ RecordingFactory recorder;
+ std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;
+ EXPECT_NO_THROW(compiled = create_compiled_model(model, props, recorder));
+ EXPECT_NE(compiled, nullptr);
+ Sub128Shifts shifts;
+ for (const auto& call : recorder.calls()) {
+ const auto count = count_sub128_shifts(call.model);
+ const auto& name = call.model->get_friendly_name();
+ if (name.find("_prefill") != std::string::npos) {
+ shifts.prefill += count;
+ } else if (name.find("_kv") != std::string::npos) {
+ shifts.generate += count;
+ } else if (name.find("_lm_head") != std::string::npos) {
+ shifts.lm_head += count;
+ }
+ }
+ return shifts;
+ }
+
+ Sub128Shifts compile_whisper(const ov::AnyMap& extra_props) {
+ ov::AnyMap props = {{"NPUW_WHISPER", "YES"}, {"NPUW_WHISPER_EOS_TOKEN", "42"}};
+ props.insert(extra_props.begin(), extra_props.end());
+ return compile_with_shared_vocabulary(build_whisper_decoder_model(),
+ "model.decoder.embed_tokens.weight",
+ "proj_out",
+ props);
+ }
+
+ Sub128Shifts compile_llm(const ov::AnyMap& extra_props) {
+ ov::AnyMap props = {{"NPUW_LLM_SHARED_HEAD", "YES"}};
+ props.insert(extra_props.begin(), extra_props.end());
+ return compile_with_shared_vocabulary(build_llm_model(), "model.embed_tokens.weight", "lm_head", props);
+ }
+};
+
+// GenAI compiles Whisper on NPU this way by default: the vocabulary is not a closure.
+TEST_F(LLMCompiledModelSharedVocabularyTest, SharedVocabularyIsNotUsedWithoutFunctions) {
+ const auto shifts = compile_whisper({{"NPUW_FOLD", "NO"}, {"NPUW_FUNCALL_FOR_ALL", "NO"}});
+ EXPECT_EQ(shifts.prefill, 0u);
+ EXPECT_EQ(shifts.generate, 0u);
+}
+
+// Whisper has no separate LM head model, so the vocabulary is not shared even with functions.
+TEST_F(LLMCompiledModelSharedVocabularyTest, WhisperDoesNotUseSharedVocabularyWithFunctions) {
+ const auto shifts = compile_whisper({{"NPUW_FOLD", "YES"}, {"NPUW_FUNCALL_FOR_ALL", "YES"}});
+ EXPECT_EQ(shifts.prefill, 0u);
+ EXPECT_EQ(shifts.generate, 0u);
+}
+
+// With the default stage configs the vocabulary is a closure; only the separate LM head model is shifted.
+TEST_F(LLMCompiledModelSharedVocabularyTest, SharedHeadModelIsShiftedWithDefaultConfigs) {
+ const auto shifts = compile_llm({});
+ EXPECT_EQ(shifts.lm_head, 2u);
+ EXPECT_EQ(shifts.prefill, 0u);
+ EXPECT_EQ(shifts.generate, 0u);
+}
+
+// NPUW_CWAI is used only without NPUW_FOLD and does not run Partitioner::optimize(), which resolves the shifts.
+TEST_F(LLMCompiledModelSharedVocabularyTest, SharedVocabularyIsNotUsedWithCwaiInsteadOfFold) {
+ const auto shifts = compile_llm({{"NPUW_FOLD", "NO"}, {"NPUW_CWAI", "YES"}, {"NPUW_FUNCALL_FOR_ALL", "YES"}});
+ EXPECT_EQ(shifts.lm_head, 0u);
+ EXPECT_EQ(shifts.prefill, 0u);
+ EXPECT_EQ(shifts.generate, 0u);
+}
+
+// Without the separate LM head model the embedding and the LM head are in one model, where the quantized
+// host gather can skip ConvertDQVocab. An explicit NPUW_LLM_VOCAB_ASYM_SHARED=YES does not change this.
+TEST_F(LLMCompiledModelSharedVocabularyTest, SharedVocabularyIsNotUsedWithoutSharedHead) {
+ for (const auto* explicit_value : {"", "YES"}) {
+ ov::AnyMap props = {{"NPUW_LLM_SHARED_HEAD", "NO"}};
+ if (*explicit_value) {
+ props["NPUW_LLM_VOCAB_ASYM_SHARED"] = explicit_value;
+ }
+ const auto shifts =
+ compile_with_shared_vocabulary(build_llm_model(), "model.embed_tokens.weight", "lm_head", props);
+ EXPECT_EQ(shifts.lm_head, 0u);
+ EXPECT_EQ(shifts.prefill, 0u);
+ EXPECT_EQ(shifts.generate, 0u);
+ }
+}
+
+TEST_F(LLMCompiledModelSharedVocabularyTest, SharedVocabularyIsNotUsedIfOneStageHasNoFunctions) {
+ const auto shifts = compile_llm({{"++NPUW_LLM_GENERATE_CONFIG", ov::AnyMap{{"NPUW_FUNCALL_FOR_ALL", "NO"}}}});
+ EXPECT_EQ(shifts.lm_head, 0u);
+ EXPECT_EQ(shifts.prefill, 0u);
+ EXPECT_EQ(shifts.generate, 0u);
+}
+
+TEST_F(LLMCompiledModelSharedVocabularyTest, SharedVocabularyIsNotUsedWithoutHostGather) {
+ const auto shifts = compile_llm({{"NPUW_HOST_GATHER", "NO"}});
+ EXPECT_EQ(shifts.lm_head, 0u);
+ EXPECT_EQ(shifts.prefill, 0u);
+ EXPECT_EQ(shifts.generate, 0u);
+}
+
+TEST_F(LLMCompiledModelSharedVocabularyTest, SharedVocabularyIsNotUsedWithOldCompiler) {
+ m_plugin = std::make_shared<ArchAwarePlugin>("5020", 1, ONEAPI_MAKE_VERSION(8, 2));
+ const auto core = attach_mock_core_with_npu_device(m_plugin);
+ const auto shifts = compile_llm({});
+ EXPECT_EQ(shifts.lm_head, 0u);
+ EXPECT_EQ(shifts.prefill, 0u);
+ EXPECT_EQ(shifts.generate, 0u);
+}
+
+TEST_F(LLMCompiledModelSharedVocabularyTest, SharedVocabularyIsUsedWithNewCompiler) {
+ m_plugin = std::make_shared<ArchAwarePlugin>("5020", 1, ONEAPI_MAKE_VERSION(8, 5));
+ const auto core = attach_mock_core_with_npu_device(m_plugin);
+ const auto shifts = compile_llm({});
+ EXPECT_EQ(shifts.lm_head, 2u);
+}
+
+TEST_F(LLMCompiledModelSharedVocabularyTest, ExplicitSharedVocabularyIsUsedWithOldCompiler) {
+ m_plugin = std::make_shared<ArchAwarePlugin>("5020", 1, ONEAPI_MAKE_VERSION(8, 2));
+ const auto core = attach_mock_core_with_npu_device(m_plugin);
+ const auto shifts = compile_llm({{"NPUW_LLM_VOCAB_ASYM_SHARED", "YES"}});
+ EXPECT_EQ(shifts.lm_head, 2u);
+}
+
+// The compiler that matters is the one of the final LM head config, not the top-level one: the plugin
+// compiler is new (8.5), the driver compiler is old (8.2).
+TEST_F(LLMCompiledModelSharedVocabularyTest, SharedVocabularyIsNotUsedIfHeadOverridesCompilerWithOldOne) {
+ m_plugin = std::make_shared<ArchAwarePlugin>(
+ "5020",
+ 1,
+ ONEAPI_MAKE_VERSION(8, 5),
+ std::map<std::string, int64_t>{{"PLUGIN", ONEAPI_MAKE_VERSION(8, 5)}, {"DRIVER", ONEAPI_MAKE_VERSION(8, 2)}});
+ const auto core = attach_mock_core_with_npu_device(m_plugin);
+ const auto shifts = compile_llm({{"NPU_COMPILER_TYPE", "PLUGIN"},
+ {"++NPUW_LLM_SHARED_HEAD_CONFIG", ov::AnyMap{{"NPU_COMPILER_TYPE", "DRIVER"}}}});
+ EXPECT_EQ(shifts.lm_head, 0u);
+ EXPECT_EQ(shifts.prefill, 0u);
+ EXPECT_EQ(shifts.generate, 0u);
+}
+
+TEST_F(LLMCompiledModelSharedVocabularyTest, SharedVocabularyIsUsedIfHeadOverridesCompilerWithNewOne) {
+ m_plugin = std::make_shared<ArchAwarePlugin>(
+ "5020",
+ 1,
+ ONEAPI_MAKE_VERSION(8, 2),
+ std::map<std::string, int64_t>{{"PLUGIN", ONEAPI_MAKE_VERSION(8, 5)}, {"DRIVER", ONEAPI_MAKE_VERSION(8, 2)}});
+ const auto core = attach_mock_core_with_npu_device(m_plugin);
+ const auto shifts = compile_llm({{"NPU_COMPILER_TYPE", "DRIVER"},
+ {"++NPUW_LLM_SHARED_HEAD_CONFIG", ov::AnyMap{{"NPU_COMPILER_TYPE", "PLUGIN"}}}});
+ EXPECT_EQ(shifts.lm_head, 2u);
+}
+
+TEST_F(LLMCompiledModelSharedVocabularyTest, SharedHeadModelIsNotShiftedIfHeadHasNoFunctions) {
+ const auto shifts = compile_llm({{"++NPUW_LLM_SHARED_HEAD_CONFIG", ov::AnyMap{{"NPUW_FUNCALL_FOR_ALL", "NO"}}}});
+ EXPECT_EQ(shifts.lm_head, 0u);
+ EXPECT_EQ(shifts.prefill, 0u);
+ EXPECT_EQ(shifts.generate, 0u);
}
TEST_F(LLMCompiledModelFactoryOptionsTest, WhisperPreparationAddsKvCacheInputsAndPresentOutputs) {