Skip to content

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

[NPUW] asymmetric vocabulary conversion U8 to I8 (#37683)

Eugene Smirnov1b62bb6f78e2
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 7a999628ffd..8bfec8f005d 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
@@ -85,6 +85,7 @@ INTEL_NPU_NPUW_ANYMAP_OPT(NPUW_LLM_ADDITIONAL_PREFILL_CONFIG, ov::intel_npu::npu
INTEL_NPU_NPUW_ANYMAP_OPT(NPUW_LLM_GENERATE_CONFIG, ov::intel_npu::npuw::llm, generate_config, "NPUW_LLM_GENERATE_CONFIG", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_ANYMAP_OPT(NPUW_LLM_ADDITIONAL_GENERATE_CONFIG, ov::intel_npu::npuw::llm, additional_generate_config, "++NPUW_LLM_GENERATE_CONFIG", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_ANYMAP_OPT(NPUW_LLM_SHARED_LM_HEAD_CONFIG, ov::intel_npu::npuw::llm, shared_lm_head_config, "NPUW_LLM_SHARED_HEAD_CONFIG", LLM, EXPOSED, CACHED, ALL)
+INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_LLM_VOCAB_ASYM_SHARED, bool, false, ov::intel_npu::npuw::llm, vocab_asym_shared, "NPUW_LLM_VOCAB_ASYM_SHARED", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_ANYMAP_OPT(NPUW_LLM_ADDITIONAL_SHARED_LM_HEAD_CONFIG, ov::intel_npu::npuw::llm, additional_shared_lm_head_config, "++NPUW_LLM_SHARED_HEAD_CONFIG", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_WHISPER, bool, false, ov::intel_npu::npuw::whisper, enabled, "NPUW_WHISPER", LLM, EXPOSED, CACHED, ALL)
INTEL_NPU_NPUW_SIMPLE_OPT(NPUW_WHISPER_EOS_TOKEN, uint64_t, 50257, ov::intel_npu::npuw::whisper, whisper_eos_token, "NPUW_WHISPER_EOS_TOKEN", LLM, EXPOSED, UNCACHED, ALL)
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 fc2333f8aba..2c5883ccb26 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
@@ -18,6 +18,7 @@
#include "npuw_transformations/convert_kvcache_to_precision.hpp"
#include "npuw_transformations/detect_causal_mask.hpp"
#include "npuw_transformations/duplicate_shared_kv_concat.hpp"
+#include "npuw_transformations/insert_vocab_sub128.hpp"
#include "npuw_transformations/lora_stateful_to_stateless.hpp"
#include "npuw_transformations/optimize_value_tensors.hpp"
#include "npuw_transformations/patch_sliding_window_mask.hpp"
@@ -880,6 +881,13 @@ 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();
+ if (m_cfg.get<::intel_npu::NPUW_LLM_VOCAB_ASYM_SHARED>()) {
+ ov::npuw::InsertVocabSub128 pass;
+ if (!pass.run_on_model(kvcache_model)) {
+ LOG_INFO("No asymmetric u8 vocab found - graph Sub128 insertion is skipped.");
+ }
+ }
+
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;
diff --git a/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/insert_vocab_sub128.cpp b/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/insert_vocab_sub128.cpp
new file mode 100644
index 00000000000..6690868f91b
--- /dev/null
+++ b/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/insert_vocab_sub128.cpp
@@ -0,0 +1,123 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "insert_vocab_sub128.hpp"
+
+#include <memory>
+
+#include "openvino/core/graph_util.hpp"
+#include "openvino/op/add.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/convert.hpp"
+#include "openvino/op/divide.hpp"
+#include "openvino/op/matmul.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/result.hpp"
+#include "openvino/op/subtract.hpp"
+#include "openvino/op/tanh.hpp"
+#include "openvino/op/transpose.hpp"
+#include "openvino/pass/matcher_pass.hpp"
+#include "openvino/pass/pattern/op/optional.hpp"
+#include "openvino/pass/pattern/op/or.hpp"
+#include "openvino/pass/pattern/op/wrap_type.hpp"
+#include "transformations/rt_info/decompression.hpp"
+
+namespace opp = ov::pass::pattern;
+
+namespace {
+
+// diagnostics warnings on OPENVINO_MATCHER_PASS_RTTI() definition: visibility hidden
+#ifdef __GNUC__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wattributes"
+#endif
+
+class InsertVocabSub128Matcher final : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("ov::npuw::InsertVocabSub128Matcher");
+
+ InsertVocabSub128Matcher() {
+ const auto qweight = opp::wrap_type<ov::op::v0::Constant>();
+ const auto qzerop = opp::wrap_type<ov::op::v0::Constant>();
+ const auto qcoeff = opp::wrap_type<ov::op::v0::Constant>();
+ const auto qweight_convert = opp::wrap_type<ov::op::v0::Convert>({qweight});
+ const auto qzerop_convert = opp::wrap_type<ov::op::v0::Convert>({qzerop});
+ const auto qsub = opp::wrap_type<ov::op::v1::Subtract>({qweight_convert, qzerop_convert});
+ const auto qscale = opp::wrap_type<ov::op::v1::Multiply>({qsub, qcoeff});
+ const auto qconvert = opp::optional<ov::op::v0::Convert>({qscale});
+ const auto hidden = opp::any_input();
+ const auto matmul = opp::wrap_type<ov::op::v0::MatMul>({hidden, qconvert});
+
+ // Keep this terminal pattern aligned with CutLMHead: only vocabulary MatMuls
+ // that form an LM-head result are eligible for Sub128 insertion.
+ const auto matmul_add = opp::wrap_type<ov::op::v1::Add>({matmul, opp::any_input()});
+ const auto matmul_transpose = opp::wrap_type<ov::op::v1::Transpose>({matmul, opp::any_input()});
+ const auto matmul_convert = opp::wrap_type<ov::op::v0::Convert>({matmul});
+ const auto div = opp::wrap_type<ov::op::v1::Multiply, ov::op::v1::Divide>({matmul, opp::any_input()});
+ const auto tanh = opp::wrap_type<ov::op::v0::Tanh>({div});
+ const auto matmul_multiply = opp::wrap_type<ov::op::v1::Multiply>({tanh, opp::any_input()});
+ const auto lm_head_output = std::make_shared<opp::op::Or>(ov::OutputVector{matmul->output(0),
+ matmul_add->output(0),
+ matmul_transpose->output(0),
+ matmul_convert->output(0),
+ matmul_multiply->output(0)});
+ const auto result = opp::wrap_type<ov::op::v0::Result>({lm_head_output->output(0)});
+
+ auto callback = [=](opp::Matcher& matcher) {
+ const auto& values = matcher.get_pattern_value_map();
+ const auto weight = values.at(qweight).get_node_shared_ptr();
+ const auto zerop = values.at(qzerop).get_node_shared_ptr();
+ const auto scale = values.at(qcoeff).get_node_shared_ptr();
+ const auto subtract = values.at(qsub).get_node_shared_ptr();
+ const auto matched_matmul =
+ std::static_pointer_cast<ov::op::v0::MatMul>(values.at(matmul).get_node_shared_ptr());
+ const auto matched_result =
+ std::static_pointer_cast<ov::op::v0::Result>(values.at(result).get_node_shared_ptr());
+
+ if (matched_result->get_rt_info().count("manually_added_output")) {
+ return false;
+ }
+
+ const auto scale_shape = std::static_pointer_cast<ov::op::v0::Constant>(scale)->get_shape();
+ const bool standard_layout = scale_shape.size() == 2 && scale_shape[1] == 1 &&
+ !matched_matmul->get_transpose_a() && matched_matmul->get_transpose_b();
+ const bool pretransposed_layout = scale_shape.size() == 2 && scale_shape[0] == 1 &&
+ !matched_matmul->get_transpose_a() && !matched_matmul->get_transpose_b();
+
+ if (weight->get_element_type() != ov::element::u8 || zerop->get_element_type() != ov::element::u8 ||
+ weight->get_shape().size() != 2 || (!standard_layout && !pretransposed_layout)) {
+ return false;
+ }
+
+ const auto weight_convert = subtract->input_value(0);
+ const auto zerop_convert = subtract->input_value(1);
+ const auto compute_type = weight_convert.get_element_type();
+ const auto shift = ov::op::v0::Constant::create(compute_type, ov::Shape{}, {128});
+ // PPP may not recognize the DQ subgraph after Sub128 insertion. Mark the source
+ // converts as decompression to prevent PPP constant folding from materializing
+ // enormous vocabulary tensors during KV-cache precision conversion.
+ ov::mark_as_decompression(weight_convert.get_node_shared_ptr());
+ ov::mark_as_decompression(zerop_convert.get_node_shared_ptr());
+ const auto shifted_weight = std::make_shared<ov::op::v1::Subtract>(weight_convert, shift);
+ const auto shifted_zerop = std::make_shared<ov::op::v1::Subtract>(zerop_convert, shift);
+ shifted_weight->get_rt_info()[ov::npuw::NPUW_SUB128_SHIFT_RT_INFO] = true;
+ shifted_zerop->get_rt_info()[ov::npuw::NPUW_SUB128_SHIFT_RT_INFO] = true;
+ subtract->input(0).replace_source_output(shifted_weight);
+ subtract->input(1).replace_source_output(shifted_zerop);
+ return true;
+ };
+
+ register_matcher(std::make_shared<opp::Matcher>(result, "InsertVocabSub128"), std::move(callback));
+ }
+};
+
+#ifdef __GNUC__
+# pragma GCC diagnostic pop
+#endif
+
+} // namespace
+
+ov::npuw::InsertVocabSub128::InsertVocabSub128() {
+ add_matcher<InsertVocabSub128Matcher>();
+}
diff --git a/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/insert_vocab_sub128.hpp b/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/insert_vocab_sub128.hpp
new file mode 100644
index 00000000000..a61e79d88d1
--- /dev/null
+++ b/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/insert_vocab_sub128.hpp
@@ -0,0 +1,21 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <memory>
+
+#include "openvino/pass/graph_rewrite.hpp"
+
+namespace ov::npuw {
+
+inline constexpr const char* NPUW_SUB128_SHIFT_RT_INFO = "npuw_sub128_shift";
+
+class InsertVocabSub128 : public ov::pass::GraphRewrite {
+public:
+ OPENVINO_GRAPH_REWRITE_RTTI("ov::npuw::InsertVocabSub128");
+ InsertVocabSub128();
+};
+
+} // namespace ov::npuw
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp
index 85a1f7596a4..f88ba628781 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp
@@ -1422,7 +1422,7 @@ void Partitioner::saveTinyConstants(const std::string& func_name) {
LOG_DEBUG("[KEEP] " << node->get_friendly_name() << "/" << shape
<< ": It is safe to keep this bank in function");
func_group.consts_to_keep.insert(std::static_pointer_cast<CT>(node));
- } else {
+ } else if (ov::op::util::is_constant(node)) {
LOG_DEBUG("[CUT ] " << node->get_friendly_name() << "/" << shape
<< ": This const op will be cut-off from the function");
}
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.cpp
index d39851ddd58..ea61ce79fbd 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.cpp
@@ -5,6 +5,7 @@
#include "opt.hpp"
#include "../../logging.hpp"
+#include "../../npuw_transformations/insert_vocab_sub128.hpp"
#include "../../util.hpp"
#include "openvino/op/ops.hpp"
#include "openvino/op/util/op_types.hpp"
@@ -18,6 +19,15 @@ namespace npuw {
namespace patterns {
namespace opt {
+namespace {
+
+bool is_subtract_128(const std::shared_ptr<ov::Node>& node) {
+ const auto subtract = ov::as_type_ptr<ov::op::v1::Subtract>(node);
+ return subtract != nullptr && subtract->get_rt_info().count(ov::npuw::NPUW_SUB128_SHIFT_RT_INFO) > 0;
+}
+
+} // namespace
+
void Context::permute(const PPtr& orig_param, const Context::Axes& order) {
closures_to_permute[orig_param] = order;
@@ -1079,7 +1089,9 @@ DQLiftGatherAsymCW::DQLiftGatherAsymCW() {
auto qcoeff = opp::wrap_type<ov::op::v0::Constant>();
auto qcvtw = opp::wrap_type<ov::op::v0::Convert>({qweight});
auto qcvtz = opp::wrap_type<ov::op::v0::Convert>({qzerop});
- auto qsubz = opp::wrap_type<ov::op::v1::Subtract>({qcvtw, qcvtz});
+ auto qshiftw = opp::optional<ov::op::v1::Subtract>({qcvtw->output(0), opp::any_input()});
+ auto qshiftz = opp::optional<ov::op::v1::Subtract>({qcvtz->output(0), opp::any_input()});
+ auto qsubz = opp::wrap_type<ov::op::v1::Subtract>({qshiftw, qshiftz});
auto qmuls = opp::wrap_type<ov::op::v1::Multiply>({qsubz, qcoeff});
auto qcvtm = opp::wrap_type<ov::op::v0::Convert>({qmuls});
@@ -1098,6 +1110,14 @@ DQLiftGatherAsymCW::DQLiftGatherAsymCW() {
auto matched_out_ids = uat::_(node_to_output).at_or_at(cvtids, pids);
const auto& matched_out_gather = node_to_output.at(gather);
+ if (node_to_output.count(qshiftw) != node_to_output.count(qshiftz)) {
+ return false;
+ }
+ if (node_to_output.count(qshiftw) && (!is_subtract_128(node_to_output.at(qshiftw).get_node_shared_ptr()) ||
+ !is_subtract_128(node_to_output.at(qshiftz).get_node_shared_ptr()))) {
+ return false;
+ }
+
// Replicate the compute part
auto gather_c = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, 0);
auto new_g_w = std::make_shared<ov::op::v8::Gather>(matched_out_w, matched_out_ids, gather_c);
@@ -1380,7 +1400,9 @@ HostGatherQuantAsymm<WType>::HostGatherQuantAsymm(Context::Ref ctx, bool verify_
auto qcvtw = opp::wrap_type<ov::op::v0::Convert>({qgthrw});
auto qcvtz = opp::wrap_type<ov::op::v0::Convert>({qgthrz});
- auto qsubz = opp::wrap_type<ov::op::v1::Subtract>({qcvtw, qcvtz});
+ auto qshiftw = opp::optional<ov::op::v1::Subtract>({qcvtw->output(0), opp::any_input()});
+ auto qshiftz = opp::optional<ov::op::v1::Subtract>({qcvtz->output(0), opp::any_input()});
+ auto qsubz = opp::wrap_type<ov::op::v1::Subtract>({qshiftw, qshiftz});
auto qmuls = opp::wrap_type<ov::op::v1::Multiply>({qsubz, qgthrs});
auto qcvtm = opp::wrap_type<ov::op::v0::Convert>({qmuls});
@@ -1390,6 +1412,17 @@ HostGatherQuantAsymm<WType>::HostGatherQuantAsymm(Context::Ref ctx, bool verify_
const auto& matched_out_mul = node_to_output.at(qmuls);
auto out_shape = matched_out_mul.get_shape();
+ if (node_to_output.count(qshiftw) != node_to_output.count(qshiftz)) {
+ return false;
+ }
+ // The paired shifts mark u8 tensors adapted for an i8 DQ graph. The current
+ // host path replaces that graph with direct u8 dequantization, where the
+ // equal shifts cancel: (W - 128) - (Z - 128) == W - Z.
+ if (node_to_output.count(qshiftw) && (!is_subtract_128(node_to_output.at(qshiftw).get_node_shared_ptr()) ||
+ !is_subtract_128(node_to_output.at(qshiftz).get_node_shared_ptr()))) {
+ return false;
+ }
+
if (out_shape.size() != 3 && out_shape.size() != 4) {
return false;
}
@@ -1933,7 +1966,9 @@ PreserveConstDictMatMulAsymm::PreserveConstDictMatMulAsymm(Context::Ref ctx,
auto qzerop = opp::wrap_type<ov::op::v0::Constant>();
auto qcvtw = opp::wrap_type<ov::op::v0::Convert>({qweight});
auto qcvtz = opp::wrap_type<ov::op::v0::Convert>({qzerop});
- auto qsub = opp::wrap_type<ov::op::v1::Subtract>({qcvtw, qcvtz});
+ auto qshiftw = opp::optional<ov::op::v1::Subtract>({qcvtw->output(0), opp::any_input()});
+ auto qshiftz = opp::optional<ov::op::v1::Subtract>({qcvtz->output(0), opp::any_input()});
+ auto qsub = opp::wrap_type<ov::op::v1::Subtract>({qshiftw, qshiftz});
auto qmuls = opp::wrap_type<ov::op::v1::Multiply>({qsub, qcoeff});
// The Convert between Multiply and MatMul is optional (some models omit it when Multiply is already f32)
auto qcvtm = opp::optional<ov::op::v0::Convert>({qmuls});
@@ -1971,6 +2006,14 @@ PreserveConstDictMatMulAsymm::PreserveConstDictMatMulAsymm(Context::Ref ctx,
auto qcoeff_shape = matched_qcoeff->output(0).get_shape();
+ if (node_to_output.count(qshiftw) != node_to_output.count(qshiftz)) {
+ return false;
+ }
+ if (node_to_output.count(qshiftw) && (!is_subtract_128(node_to_output.at(qshiftw).get_node_shared_ptr()) ||
+ !is_subtract_128(node_to_output.at(qshiftz).get_node_shared_ptr()))) {
+ return false;
+ }
+
// Standard layout: weight [OC, IC], scale [OC, 1], transpose_b=true
const bool standard_layout = qcoeff_shape.size() == 2 && qcoeff_shape[1] == 1 &&
!matched_matmul->get_transpose_a() && matched_matmul->get_transpose_b();
diff --git a/src/plugins/intel_npu/src/plugin/sources.cmake b/src/plugins/intel_npu/src/plugin/sources.cmake
index 1c4068eaa82..686f6c334a6 100644
--- a/src/plugins/intel_npu/src/plugin/sources.cmake
+++ b/src/plugins/intel_npu/src/plugin/sources.cmake
@@ -118,6 +118,8 @@ set(NPUW_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/npuw/npuw_transformations/collapse_unqdq.hpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/npuw_transformations/convert_kvcache_to_precision.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/npuw_transformations/convert_kvcache_to_precision.hpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/npuw/npuw_transformations/insert_vocab_sub128.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/npuw/npuw_transformations/insert_vocab_sub128.hpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/npuw_transformations/conv_to_matmul.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/npuw_transformations/conv_to_matmul.hpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/npuw_transformations/detect_causal_mask.cpp
diff --git a/src/plugins/intel_npu/tests/unit/CMakeLists.txt b/src/plugins/intel_npu/tests/unit/CMakeLists.txt
index e5d6130c239..6bd20669cb3 100644
--- a/src/plugins/intel_npu/tests/unit/CMakeLists.txt
+++ b/src/plugins/intel_npu/tests/unit/CMakeLists.txt
@@ -80,6 +80,7 @@ ov_add_test_target(
${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
+ ${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/insert_vocab_sub128.cpp
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/duplicate_shared_kv_concat.cpp
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/kv_cache_block_manager.cpp
${OpenVINO_SOURCE_DIR}/src/plugins/intel_npu/src/plugin/npuw/attention.cpp
@@ -162,6 +163,7 @@ target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_compiled_model_graph_options_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/flux2_compiled_model_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/gqa_compiled_model_test.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/npuw/gather_sub128_matcher_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_continuation_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_continued_prefill_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/stored_tokens_state_test.cpp
diff --git a/src/plugins/intel_npu/tests/unit/npuw/gather_sub128_matcher_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/gather_sub128_matcher_test.cpp
new file mode 100644
index 00000000000..39c8791bf62
--- /dev/null
+++ b/src/plugins/intel_npu/tests/unit/npuw/gather_sub128_matcher_test.cpp
@@ -0,0 +1,344 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <gtest/gtest.h>
+
+#include <cstdint>
+#include <memory>
+#include <algorithm>
+#include <optional>
+#include <string>
+#include <tuple>
+#include <vector>
+
+#include "npuw_transformations/insert_vocab_sub128.hpp"
+#include "openvino/core/preprocess/pre_post_process.hpp"
+#include "openvino/opsets/opset10.hpp"
+#include "openvino/pass/graph_rewrite.hpp"
+#include "partitioning/patterns/opt.hpp"
+#include "transformations/rt_info/decompression.hpp"
+
+namespace {
+
+std::shared_ptr<ov::Model> make_gather_model(float shift_value) {
+ auto ids = std::make_shared<ov::opset10::Parameter>(ov::element::i32, ov::Shape{1});
+ auto weights = ov::opset10::Constant::create(ov::element::u8, ov::Shape{4, 2}, std::vector<uint8_t>(8, 200));
+ auto zero_point = ov::opset10::Constant::create(ov::element::u8, ov::Shape{4, 1}, std::vector<uint8_t>(4, 128));
+ auto scale = ov::opset10::Constant::create(ov::element::f16, ov::Shape{4, 1}, std::vector<float>(4, 1.0f));
+ auto axis = ov::opset10::Constant::create(ov::element::i32, ov::Shape{}, {0});
+
+ auto weight_convert = std::make_shared<ov::opset10::Convert>(weights, ov::element::f16);
+ auto zero_point_convert = std::make_shared<ov::opset10::Convert>(zero_point, ov::element::f16);
+ auto shift = ov::opset10::Constant::create(ov::element::f16, ov::Shape{}, {shift_value});
+ auto shifted_weight = std::make_shared<ov::opset10::Subtract>(weight_convert, shift);
+ auto shifted_zero_point = std::make_shared<ov::opset10::Subtract>(zero_point_convert, shift);
+ if (shift_value == 128.0f) {
+ shifted_weight->get_rt_info()[ov::npuw::NPUW_SUB128_SHIFT_RT_INFO] = true;
+ shifted_zero_point->get_rt_info()[ov::npuw::NPUW_SUB128_SHIFT_RT_INFO] = true;
+ }
+
+ auto dequantized = std::make_shared<ov::opset10::Subtract>(shifted_weight, shifted_zero_point);
+ auto scaled = std::make_shared<ov::opset10::Multiply>(dequantized, scale);
+ auto converted = std::make_shared<ov::opset10::Convert>(scaled, ov::element::f32);
+ auto gathered = std::make_shared<ov::opset10::Gather>(converted, ids, axis);
+ auto result = std::make_shared<ov::opset10::Result>(gathered);
+ return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{ids});
+}
+
+std::size_t count_gathers(const std::shared_ptr<ov::Model>& model) {
+ std::size_t count = 0;
+ for (const auto& node : model->get_ordered_ops()) {
+ if (ov::is_type<ov::opset10::Gather>(node)) {
+ ++count;
+ }
+ }
+ return count;
+}
+
+bool run_lift(const std::shared_ptr<ov::Model>& model) {
+ ov::pass::GraphRewrite rewrite;
+ rewrite.add_matcher<ov::npuw::patterns::opt::DQLiftGatherAsymCW>();
+ return rewrite.run_on_model(model);
+}
+
+std::shared_ptr<ov::Model> make_parameter_gather_model(std::optional<float> weight_shift,
+ std::optional<float> zero_point_shift) {
+ constexpr std::size_t vocab_size = 4096;
+ constexpr std::size_t hidden_size = 2048;
+ auto ids = std::make_shared<ov::opset10::Parameter>(ov::element::i32, ov::Shape{1, 1});
+ auto weights = std::make_shared<ov::opset10::Parameter>(ov::element::u8, ov::Shape{vocab_size, hidden_size});
+ auto zero_point = std::make_shared<ov::opset10::Parameter>(ov::element::u8, ov::Shape{vocab_size, hidden_size});
+ auto scale = std::make_shared<ov::opset10::Parameter>(ov::element::f16, ov::Shape{vocab_size, hidden_size});
+ auto axis = ov::opset10::Constant::create(ov::element::i32, ov::Shape{}, {0});
+
+ auto gathered_weights = std::make_shared<ov::opset10::Gather>(weights, ids, axis);
+ auto gathered_zero_point = std::make_shared<ov::opset10::Gather>(zero_point, ids, axis);
+ auto gathered_scale = std::make_shared<ov::opset10::Gather>(scale, ids, axis);
+ auto weight_convert = std::make_shared<ov::opset10::Convert>(gathered_weights, ov::element::f16);
+ auto zero_point_convert = std::make_shared<ov::opset10::Convert>(gathered_zero_point, ov::element::f16);
+ ov::Output<ov::Node> dequantized_weight = weight_convert;
+ ov::Output<ov::Node> dequantized_zero_point = zero_point_convert;
+ if (weight_shift.has_value()) {
+ auto shift = ov::opset10::Constant::create(ov::element::f16, ov::Shape{}, {weight_shift.value()});
+ dequantized_weight = std::make_shared<ov::opset10::Subtract>(weight_convert, shift);
+ if (weight_shift.value() == 128.0f) {
+ dequantized_weight.get_node_shared_ptr()->get_rt_info()[ov::npuw::NPUW_SUB128_SHIFT_RT_INFO] = true;
+ }
+ }
+ if (zero_point_shift.has_value()) {
+ auto shift = ov::opset10::Constant::create(ov::element::f16, ov::Shape{}, {zero_point_shift.value()});
+ dequantized_zero_point = std::make_shared<ov::opset10::Subtract>(zero_point_convert, shift);
+ if (zero_point_shift.value() == 128.0f) {
+ dequantized_zero_point.get_node_shared_ptr()->get_rt_info()[ov::npuw::NPUW_SUB128_SHIFT_RT_INFO] = true;
+ }
+ }
+
+ auto dequantized = std::make_shared<ov::opset10::Subtract>(dequantized_weight, dequantized_zero_point);
+ auto scaled = std::make_shared<ov::opset10::Multiply>(dequantized, gathered_scale);
+ auto converted = std::make_shared<ov::opset10::Convert>(scaled, ov::element::f16);
+ auto result = std::make_shared<ov::opset10::Result>(converted);
+ return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{ids, weights, zero_point, scale});
+}
+
+std::shared_ptr<ov::Model> make_parameter_gather_model(float shift_value) {
+ return make_parameter_gather_model(shift_value, shift_value);
+}
+
+bool run_host_gather(const std::shared_ptr<ov::Model>& model, ov::npuw::patterns::opt::Context& context) {
+ ov::pass::GraphRewrite rewrite;
+ rewrite.add_matcher<ov::npuw::patterns::opt::HostGatherQuantAsymm<>>(std::ref(context));
+ return rewrite.run_on_model(model);
+}
+
+enum class VocabMatMulTerminal { Add, Transpose, Convert, Gated };
+
+std::shared_ptr<ov::Model> make_vocab_matmul_model(bool convert_before_matmul,
+ std::optional<VocabMatMulTerminal> terminal = std::nullopt) {
+ auto hidden = std::make_shared<ov::opset10::Parameter>(ov::element::f32, ov::Shape{1, 2});
+ auto weights = ov::opset10::Constant::create(ov::element::u8, ov::Shape{4, 2}, std::vector<uint8_t>(8, 200));
+ auto zero_point =
+ ov::opset10::Constant::create(ov::element::u8, ov::Shape{4, 1}, std::vector<uint8_t>(4, 128));
+ const auto scale_type = convert_before_matmul ? ov::element::f16 : ov::element::f32;
+ auto scale = ov::opset10::Constant::create(scale_type, ov::Shape{4, 1}, std::vector<float>(4, 1.0f));
+ auto weight_convert = std::make_shared<ov::opset10::Convert>(weights, scale_type);
+ weight_convert->set_friendly_name("vocab_weight_convert");
+ auto zero_point_convert = std::make_shared<ov::opset10::Convert>(zero_point, scale_type);
+ zero_point_convert->set_friendly_name("vocab_zero_point_convert");
+ auto dequantized = std::make_shared<ov::opset10::Subtract>(weight_convert, zero_point_convert);
+ auto scaled = std::make_shared<ov::opset10::Multiply>(dequantized, scale);
+ ov::Output<ov::Node> matmul_weights = scaled;
+ if (convert_before_matmul) {
+ matmul_weights = std::make_shared<ov::opset10::Convert>(scaled, ov::element::f32);
+ }
+ auto matmul = std::make_shared<ov::opset10::MatMul>(hidden, matmul_weights, false, true);
+ ov::Output<ov::Node> output = matmul;
+ if (terminal == VocabMatMulTerminal::Add) {
+ auto bias = ov::opset10::Constant::create(ov::element::f32, ov::Shape{1, 4}, std::vector<float>(4, 1.0f));
+ output = std::make_shared<ov::opset10::Add>(matmul, bias);
+ } else if (terminal == VocabMatMulTerminal::Transpose) {
+ auto order = ov::opset10::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0});
+ output = std::make_shared<ov::opset10::Transpose>(matmul, order);
+ } else if (terminal == VocabMatMulTerminal::Convert) {
+ output = std::make_shared<ov::opset10::Convert>(matmul, ov::element::f32);
+ } else if (terminal == VocabMatMulTerminal::Gated) {
+ auto divisor = ov::opset10::Constant::create(ov::element::f32, ov::Shape{}, {2.0f});
+ auto div = std::make_shared<ov::opset10::Divide>(matmul, divisor);
+ auto tanh = std::make_shared<ov::opset10::Tanh>(div);
+ auto multiplier = ov::opset10::Constant::create(ov::element::f32, ov::Shape{}, {2.0f});
+ output = std::make_shared<ov::opset10::Multiply>(tanh, multiplier);
+ }
+ return std::make_shared<ov::Model>(ov::OutputVector{output}, ov::ParameterVector{hidden});
+}
+
+std::shared_ptr<ov::Model> make_pretransposed_vocab_matmul_model(bool convert_before_matmul) {
+ auto hidden = std::make_shared<ov::opset10::Parameter>(ov::element::f32, ov::Shape{1, 2});
+ auto weights = ov::opset10::Constant::create(ov::element::u8, ov::Shape{2, 4}, std::vector<uint8_t>(8, 200));
+ auto zero_point =
+ ov::opset10::Constant::create(ov::element::u8, ov::Shape{1, 4}, std::vector<uint8_t>(4, 128));
+ const auto scale_type = convert_before_matmul ? ov::element::f16 : ov::element::f32;
+ auto scale = ov::opset10::Constant::create(scale_type, ov::Shape{1, 4}, std::vector<float>(4, 1.0f));
+ auto weight_convert = std::make_shared<ov::opset10::Convert>(weights, scale_type);
+ weight_convert->set_friendly_name("vocab_weight_convert");
+ auto zero_point_convert = std::make_shared<ov::opset10::Convert>(zero_point, scale_type);
+ zero_point_convert->set_friendly_name("vocab_zero_point_convert");
+ auto dequantized = std::make_shared<ov::opset10::Subtract>(weight_convert, zero_point_convert);
+ auto scaled = std::make_shared<ov::opset10::Multiply>(dequantized, scale);
+ ov::Output<ov::Node> matmul_weights = scaled;
+ if (convert_before_matmul) {
+ matmul_weights = std::make_shared<ov::opset10::Convert>(scaled, ov::element::f32);
+ }
+ auto matmul = std::make_shared<ov::opset10::MatMul>(hidden, matmul_weights, false, false);
+ return std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{hidden});
+}
+
+std::size_t count_subtracts(const std::shared_ptr<ov::Model>& model) {
+ std::size_t count = 0;
+ for (const auto& node : model->get_ordered_ops()) {
+ if (ov::is_type<ov::opset10::Subtract>(node)) {
+ ++count;
+ }
+ }
+ return count;
+}
+
+std::size_t count_sub128_shifts(const std::shared_ptr<ov::Model>& model) {
+ std::size_t count = 0;
+ for (const auto& node : model->get_ordered_ops()) {
+ if (ov::is_type<ov::opset10::Subtract>(node) &&
+ node->get_rt_info().count(ov::npuw::NPUW_SUB128_SHIFT_RT_INFO) > 0) {
+ ++count;
+ }
+ }
+ return count;
+}
+
+void clear_sub128_shift_markers(const std::shared_ptr<ov::Model>& model) {
+ for (const auto& node : model->get_ordered_ops()) {
+ if (ov::is_type<ov::opset10::Subtract>(node)) {
+ node->get_rt_info().erase(ov::npuw::NPUW_SUB128_SHIFT_RT_INFO);
+ }
+ }
+}
+
+bool contains_node(const std::shared_ptr<ov::Model>& model, const std::string& name) {
+ const auto nodes = model->get_ordered_ops();
+ return std::any_of(nodes.begin(), nodes.end(), [&](const auto& node) {
+ return node->get_friendly_name() == name;
+ });
+}
+
+} // namespace
+
+TEST(DQLiftGatherAsymCWTest, LiftsPairedSub128Shifts) {
+ const auto model = make_gather_model(128.0f);
+
+ EXPECT_TRUE(run_lift(model));
+ EXPECT_EQ(count_gathers(model), 3);
+}
+
+TEST(DQLiftGatherAsymCWTest, RejectsNon128Subtractions) {
+ const auto model = make_gather_model(127.0f);
+
+ EXPECT_FALSE(run_lift(model));
+ EXPECT_EQ(count_gathers(model), 1);
+}
+
+TEST(DQLiftGatherAsymCWTest, RejectsUnmarked128Subtractions) {
+ const auto model = make_gather_model(128.0f);
+ clear_sub128_shift_markers(model);
+
+ EXPECT_FALSE(run_lift(model));
+ EXPECT_EQ(count_gathers(model), 1);
+}
+
+TEST(HostGatherQuantAsymmTest, AcceptsPairedSub128Shifts) {
+ ov::npuw::patterns::opt::Context context;
+ EXPECT_TRUE(run_host_gather(make_parameter_gather_model(128.0f), context));
+ ASSERT_TRUE(context.params_to_quant_gather_unpack.has_value());
+ ASSERT_EQ(context.params_to_quant_gather_unpack->params_to_runtime_unpack_gather.size(), 1);
+}
+
+TEST(HostGatherQuantAsymmTest, RejectsNon128Subtractions) {
+ ov::npuw::patterns::opt::Context context;
+ EXPECT_FALSE(run_host_gather(make_parameter_gather_model(127.0f), context));
+}
+
+TEST(HostGatherQuantAsymmTest, RejectsUnmarked128Subtractions) {
+ const auto model = make_parameter_gather_model(128.0f);
+ clear_sub128_shift_markers(model);
+ ov::npuw::patterns::opt::Context context;
+
+ EXPECT_FALSE(run_host_gather(model, context));
+ EXPECT_FALSE(context.params_to_quant_gather_unpack.has_value());
+ EXPECT_EQ(count_subtracts(model), 3);
+}
+
+using VocabSub128TestParams = std::tuple<bool, bool>;
+
+class InsertVocabSub128PrePostProcessingTest : public ::testing::TestWithParam<VocabSub128TestParams> {
+public:
+ static std::string getTestCaseName(const ::testing::TestParamInfo<VocabSub128TestParams>& info) {
+ const auto [pretransposed_layout, convert_before_matmul] = info.param;
+ return std::string(pretransposed_layout ? "Pretransposed" : "Standard") +
+ (convert_before_matmul ? "WithConvert" : "DirectMatMul");
+ }
+};
+
+TEST_P(InsertVocabSub128PrePostProcessingTest, PreservesVocabularyConverts) {
+ const auto [pretransposed_layout, convert_before_matmul] = GetParam();
+ const auto model = pretransposed_layout ? make_pretransposed_vocab_matmul_model(convert_before_matmul) :
+ make_vocab_matmul_model(convert_before_matmul);
+ EXPECT_TRUE(ov::npuw::InsertVocabSub128().run_on_model(model));
+ EXPECT_EQ(count_subtracts(model), 3u);
+ EXPECT_EQ(count_sub128_shifts(model), 2u);
+
+ const auto nodes = model->get_ordered_ops();
+ const auto weight_convert = std::find_if(nodes.begin(), nodes.end(), [](const auto& node) {
+ return node->get_friendly_name() == "vocab_weight_convert";
+ });
+ const auto zero_point_convert = std::find_if(nodes.begin(), nodes.end(), [](const auto& node) {
+ return node->get_friendly_name() == "vocab_zero_point_convert";
+ });
+ ASSERT_NE(weight_convert, nodes.end());
+ ASSERT_NE(zero_point_convert, nodes.end());
+ EXPECT_TRUE(ov::is_decompression(*weight_convert));
+ EXPECT_TRUE(ov::is_decompression(*zero_point_convert));
+
+ ov::preprocess::PrePostProcessor(model).build();
+
+ EXPECT_TRUE(contains_node(model, "vocab_weight_convert"));
+ EXPECT_TRUE(contains_node(model, "vocab_zero_point_convert"));
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ LayoutAndConversion,
+ InsertVocabSub128PrePostProcessingTest,
+ ::testing::Values(std::make_tuple(false, false),
+ std::make_tuple(false, true),
+ std::make_tuple(true, false),
+ std::make_tuple(true, true)),
+ InsertVocabSub128PrePostProcessingTest::getTestCaseName);
+
+class InsertVocabSub128LmHeadTerminalTest : public ::testing::TestWithParam<VocabMatMulTerminal> {
+public:
+ static std::string getTestCaseName(const ::testing::TestParamInfo<VocabMatMulTerminal>& info) {
+ switch (info.param) {
+ case VocabMatMulTerminal::Add:
+ return "Add";
+ case VocabMatMulTerminal::Transpose:
+ return "Transpose";
+ case VocabMatMulTerminal::Convert:
+ return "Convert";
+ case VocabMatMulTerminal::Gated:
+ return "Gated";
+ }
+ return "Unknown";
+ }
+};
+
+TEST_P(InsertVocabSub128LmHeadTerminalTest, InsertsSub128BeforeLmHeadTerminal) {
+ const auto model = make_vocab_matmul_model(false, GetParam());
+
+ EXPECT_TRUE(ov::npuw::InsertVocabSub128().run_on_model(model));
+ EXPECT_EQ(count_subtracts(model), 3u);
+ EXPECT_EQ(count_sub128_shifts(model), 2u);
+}
+
+INSTANTIATE_TEST_SUITE_P(LmHeadTerminal,
+ InsertVocabSub128LmHeadTerminalTest,
+ ::testing::Values(VocabMatMulTerminal::Add,
+ VocabMatMulTerminal::Transpose,
+ VocabMatMulTerminal::Convert,
+ VocabMatMulTerminal::Gated),
+ InsertVocabSub128LmHeadTerminalTest::getTestCaseName);
+
+TEST(InsertVocabSub128LmHeadTerminalTest, SkipsManuallyAddedOutput) {
+ const auto model = make_vocab_matmul_model(false);
+ model->get_results().front()->get_rt_info()["manually_added_output"] = true;
+
+ EXPECT_FALSE(ov::npuw::InsertVocabSub128().run_on_model(model));
+ EXPECT_EQ(count_subtracts(model), 1u);
+ EXPECT_EQ(count_sub128_shifts(model), 0u);
+}
+
diff --git a/src/plugins/intel_npu/tests/unit/npuw/preserve_const_matmul_pattern_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/preserve_const_matmul_pattern_test.cpp
index 6d8956f9990..80138f2d4d5 100644
--- a/src/plugins/intel_npu/tests/unit/npuw/preserve_const_matmul_pattern_test.cpp
+++ b/src/plugins/intel_npu/tests/unit/npuw/preserve_const_matmul_pattern_test.cpp
@@ -6,6 +6,7 @@
#include <algorithm>
#include <memory>
+#include <optional>
#include <vector>
#include "openvino/op/constant.hpp"
@@ -16,6 +17,7 @@
#include "openvino/op/result.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/pass/manager.hpp"
+#include "npuw_transformations/insert_vocab_sub128.hpp"
#include "partitioning/patterns/opt.hpp"
namespace {
@@ -40,7 +42,9 @@ SubgraphNodes build_asymm_matmul_subgraph(const ov::Shape& weight_shape,
const ov::Shape& zerop_shape,
const ov::Shape& scale_shape,
bool transpose_b,
- bool convert_before_matmul = true) {
+ bool convert_before_matmul = true,
+ std::optional<float> weight_shift = std::nullopt,
+ std::optional<float> zerop_shift = std::nullopt) {
auto qweight = std::make_shared<ov::op::v0::Constant>(weight_type, weight_shape, 0);
auto qzerop = std::make_shared<ov::op::v0::Constant>(weight_type, zerop_shape, 0);
// When there is no Convert after Multiply, Multiply must produce f32 directly, which
@@ -57,7 +61,23 @@ SubgraphNodes build_asymm_matmul_subgraph(const ov::Shape& weight_shape,
const auto mid_type = convert_before_matmul ? ov::element::f16 : ov::element::f32;
auto cvtw = std::make_shared<ov::op::v0::Convert>(qweight, mid_type);
auto cvtz = std::make_shared<ov::op::v0::Convert>(qzerop, mid_type);
- auto sub = std::make_shared<ov::op::v1::Subtract>(cvtw, cvtz);
+ ov::Output<ov::Node> shifted_weight = cvtw;
+ ov::Output<ov::Node> shifted_zerop = cvtz;
+ if (weight_shift.has_value()) {
+ auto shift = ov::op::v0::Constant::create(mid_type, ov::Shape{}, {weight_shift.value()});
+ shifted_weight = std::make_shared<ov::op::v1::Subtract>(cvtw, shift);
+ if (weight_shift.value() == 128.0f) {
+ shifted_weight.get_node_shared_ptr()->get_rt_info()[ov::npuw::NPUW_SUB128_SHIFT_RT_INFO] = true;
+ }
+ }
+ if (zerop_shift.has_value()) {
+ auto shift = ov::op::v0::Constant::create(mid_type, ov::Shape{}, {zerop_shift.value()});
+ shifted_zerop = std::make_shared<ov::op::v1::Subtract>(cvtz, shift);
+ if (zerop_shift.value() == 128.0f) {
+ shifted_zerop.get_node_shared_ptr()->get_rt_info()[ov::npuw::NPUW_SUB128_SHIFT_RT_INFO] = true;
+ }
+ }
+ auto sub = std::make_shared<ov::op::v1::Subtract>(shifted_weight, shifted_zerop);
auto mul = std::make_shared<ov::op::v1::Multiply>(sub, qcoeff);
std::shared_ptr<ov::Node> mm_weight_input;
@@ -196,4 +216,85 @@ TEST(OptPatterns, StandardLayout_NoConvert_MatchesAndPreservesConsts) {
EXPECT_TRUE(std::find(to_keep.begin(), to_keep.end(), qcoeff) != to_keep.end());
}
+TEST(OptPatterns, PairedSub128_MatchesAndPreservesConsts) {
+ const ov::Shape weight_shape{32064, 3072};
+ const ov::Shape scale_shape{32064, 1};
+ auto [qweight, qzerop, qcoeff, model] = build_asymm_matmul_subgraph(weight_shape,
+ ov::element::u8,
+ weight_shape,
+ scale_shape,
+ /*transpose_b=*/true,
+ /*convert_before_matmul=*/true,
+ 128.0f,
+ 128.0f);
+
+ ResultNodes to_keep;
+ run_preserve_pattern(model, to_keep);
+
+ ASSERT_EQ(to_keep.size(), 3u);
+ EXPECT_TRUE(std::find(to_keep.begin(), to_keep.end(), qweight) != to_keep.end());
+ EXPECT_TRUE(std::find(to_keep.begin(), to_keep.end(), qzerop) != to_keep.end());
+ EXPECT_TRUE(std::find(to_keep.begin(), to_keep.end(), qcoeff) != to_keep.end());
+}
+
+TEST(OptPatterns, Non128Subtraction_DoesNotPreserveConsts) {
+ const ov::Shape weight_shape{32064, 3072};
+ const ov::Shape scale_shape{32064, 1};
+ auto [qweight, qzerop, qcoeff, model] = build_asymm_matmul_subgraph(weight_shape,
+ ov::element::u8,
+ weight_shape,
+ scale_shape,
+ /*transpose_b=*/true,
+ /*convert_before_matmul=*/true,
+ 127.0f,
+ 127.0f);
+
+ ResultNodes to_keep;
+ run_preserve_pattern(model, to_keep);
+
+ EXPECT_TRUE(to_keep.empty());
+}
+
+TEST(OptPatterns, OneSidedSub128_DoesNotPreserveConsts) {
+ const ov::Shape weight_shape{32064, 3072};
+ const ov::Shape scale_shape{32064, 1};
+ auto [qweight, qzerop, qcoeff, model] = build_asymm_matmul_subgraph(weight_shape,
+ ov::element::u8,
+ weight_shape,
+ scale_shape,
+ /*transpose_b=*/true,
+ /*convert_before_matmul=*/true,
+ 128.0f,
+ std::nullopt);
+
+ ResultNodes to_keep;
+ run_preserve_pattern(model, to_keep);
+
+ EXPECT_TRUE(to_keep.empty());
+}
+
+TEST(OptPatterns, UnmarkedSub128_DoesNotPreserveConsts) {
+ const ov::Shape weight_shape{32064, 3072};
+ const ov::Shape scale_shape{32064, 1};
+ auto [qweight, qzerop, qcoeff, model] = build_asymm_matmul_subgraph(weight_shape,
+ ov::element::u8,
+ weight_shape,
+ scale_shape,
+ /*transpose_b=*/true,
+ /*convert_before_matmul=*/true,
+ 128.0f,
+ 128.0f);
+
+ for (const auto& node : model->get_ordered_ops()) {
+ if (ov::is_type<ov::op::v1::Subtract>(node)) {
+ node->get_rt_info().erase(ov::npuw::NPUW_SUB128_SHIFT_RT_INFO);
+ }
+ }
+
+ ResultNodes to_keep;
+ run_preserve_pattern(model, to_keep);
+
+ EXPECT_TRUE(to_keep.empty());
+}
+
} // namespace