Skip to content

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

[NPUW] Introduce quantized vocab handling (#30553)

Alexey Smirnov18f1571243ca
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/config/npuw.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/config/npuw.hpp
index 82dfaceb12d..5dd340b70fe 100644
--- a/src/plugins/intel_npu/src/al/include/intel_npu/config/npuw.hpp
+++ b/src/plugins/intel_npu/src/al/include/intel_npu/config/npuw.hpp
@@ -82,6 +82,7 @@ DEFINE_OPT(NPUW_DQ_FULL, bool, true, npuw::partitioning::dyn_quant_full, RunTime
DEFINE_OPT(NPUW_PMM, std::string, "2", npuw::partitioning::par_matmul_merge_dims, RunTime);
DEFINE_OPT(NPUW_SLICE_OUT, bool, false, npuw::partitioning::slice_out, RunTime);
DEFINE_OPT(NPUW_HOST_GATHER, bool, true, npuw::partitioning::host_gather, RunTime);
+DEFINE_OPT(NPUW_HOST_GATHER_QUANT, bool, false, npuw::partitioning::gather_quant, RunTime);
DEFINE_OPT(NPUW_SPATIAL, bool, false, npuw::partitioning::spatial, RunTime);
DEFINE_OPT(NPUW_F16IC, bool, true, npuw::partitioning::f16_interconnect, RunTime);
DEFINE_OPT(NPUW_SPATIAL_NWAY, std::size_t, 128, npuw::partitioning::spatial_nway, RunTime);
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/npuw_private_properties.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/npuw_private_properties.hpp
index afdd28a46c5..aa11eeaf0c7 100644
--- a/src/plugins/intel_npu/src/al/include/intel_npu/npuw_private_properties.hpp
+++ b/src/plugins/intel_npu/src/al/include/intel_npu/npuw_private_properties.hpp
@@ -250,6 +250,14 @@ static constexpr ov::Property<bool> f16_interconnect{"NPUW_F16IC"};
*/
static constexpr ov::Property<bool> host_gather{"NPUW_HOST_GATHER"};
+/**
+ * @brief
+ * Type: boolean
+ * When applicable, do embedding gather on host but leave it quantized.
+ * Default value: false.
+ */
+static constexpr ov::Property<bool> gather_quant{"NPUW_HOST_GATHER_QUANT"};
+
/**
* @brief
* Type: std::string.
diff --git a/src/plugins/intel_npu/src/al/src/config/npuw.cpp b/src/plugins/intel_npu/src/al/src/config/npuw.cpp
index 76a28acc801..4cbff551987 100644
--- a/src/plugins/intel_npu/src/al/src/config/npuw.cpp
+++ b/src/plugins/intel_npu/src/al/src/config/npuw.cpp
@@ -34,6 +34,7 @@ void intel_npu::registerNPUWOptions(OptionsDesc& desc) {
desc.add<NPUW_SPATIAL_NWAY>();
desc.add<NPUW_SPATIAL_DYN>();
desc.add<NPUW_HOST_GATHER>();
+ desc.add<NPUW_HOST_GATHER_QUANT>();
desc.add<NPUW_F16IC>();
desc.add<NPUW_DCOFF_TYPE>();
desc.add<NPUW_DCOFF_SCALE>();
diff --git a/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp b/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp
index c6fc0d6dd56..3e67dac6fcf 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp
@@ -465,12 +465,78 @@ void ov::npuw::IBaseInferRequest::bind_global_params(std::size_t idx, RqPtr requ
const auto& vocab = comp_model_desc.closure[comp_model_desc.host_gather.src_idx - comp_model_desc.param_base];
const auto& lport = comp_model_desc.compiled_model->inputs()[comp_model_desc.host_gather.idx_idx];
const auto lookup = request->get_tensor(lport);
+
ov::npuw::util::gather(ov::get_tensor_impl(vocab), lookup, gather);
}
+ // Run host-side quantized gather, if required
+ handle_quant_host_gather(idx, request);
+
LOG_DEBUG("Done");
}
+void ov::npuw::IBaseInferRequest::handle_quant_host_gather(std::size_t idx, RqPtr request) {
+ auto& comp_model_desc = m_npuw_model->m_compiled_submodels[idx];
+
+ if (comp_model_desc.quant_unpack_gather.dst_idx != -1) {
+ NPUW_ASSERT(comp_model_desc.quant_unpack_gather.idx_idx != -1 &&
+ comp_model_desc.quant_unpack_gather.src_w_idx != -1);
+
+ const auto& lport = comp_model_desc.compiled_model->inputs()[comp_model_desc.quant_unpack_gather.idx_idx];
+ const auto& lookup = request->get_tensor(lport);
+
+ const auto& gport = comp_model_desc.compiled_model->inputs()[comp_model_desc.quant_unpack_gather.dst_idx];
+ const auto& gather = request->get_tensor(gport);
+
+ const auto& wport = comp_model_desc.compiled_model->inputs()[comp_model_desc.quant_unpack_gather.src_w_idx];
+ const auto& vocabw = request->get_tensor(wport);
+
+ auto ids_shape = lookup->get_shape();
+
+ auto get_gathered_shape = [&ids_shape](const ov::Shape& shape) {
+ return ov::Shape{1, ids_shape[1], shape.size() == 3 ? shape[1] * shape[2] : shape[1]};
+ };
+
+ ov::Tensor gatherw(vocabw->get_element_type(), get_gathered_shape(vocabw->get_shape()));
+ // Gather weight
+ ov::npuw::util::gather(vocabw, lookup, ov::get_tensor_impl(gatherw));
+
+ if (comp_model_desc.quant_unpack_gather.src_z_idx != -1 &&
+ comp_model_desc.quant_unpack_gather.src_s_idx != -1) {
+ const auto& zport = comp_model_desc.compiled_model->inputs()[comp_model_desc.quant_unpack_gather.src_z_idx];
+ const auto& vocabz = request->get_tensor(zport);
+
+ const auto& sport = comp_model_desc.compiled_model->inputs()[comp_model_desc.quant_unpack_gather.src_s_idx];
+ const auto& vocabs = request->get_tensor(sport);
+
+ ov::Tensor gatherz(vocabz->get_element_type(), get_gathered_shape(vocabz->get_shape()));
+ ov::Tensor gathers(vocabs->get_element_type(), get_gathered_shape(vocabs->get_shape()));
+ // Gather first
+ ov::npuw::util::gather(vocabz, lookup, ov::get_tensor_impl(gatherz));
+ ov::npuw::util::gather(vocabs, lookup, ov::get_tensor_impl(gathers));
+
+ // Then unpack
+ ov::npuw::util::unpack(ov::get_tensor_impl(gatherw),
+ ov::get_tensor_impl(gatherz),
+ ov::get_tensor_impl(gathers),
+ gather);
+ } else if (comp_model_desc.quant_unpack_gather.src_s_idx != -1) {
+ const auto& sport = comp_model_desc.compiled_model->inputs()[comp_model_desc.quant_unpack_gather.src_s_idx];
+ const auto& vocabs = request->get_tensor(sport);
+
+ ov::Tensor gathers(vocabs->get_element_type(), get_gathered_shape(vocabs->get_shape()));
+ // Gather first
+ ov::npuw::util::gather(vocabs, lookup, ov::get_tensor_impl(gathers));
+
+ // Then unpack
+ ov::npuw::util::unpack(ov::get_tensor_impl(gatherw), ov::get_tensor_impl(gathers), gather);
+ } else {
+ // Already gathered above - just unpack
+ ov::npuw::util::unpack(ov::get_tensor_impl(gatherw), gather);
+ }
+ }
+}
+
void ov::npuw::IBaseInferRequest::bind_global_results(std::size_t idx, RqPtr request) {
LOG_DEBUG("Binding results for Subgraph[" << idx << "]");
LOG_BLOCK();
diff --git a/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.hpp b/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.hpp
index 576810cc9b2..a23dddcbf5d 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.hpp
@@ -149,6 +149,7 @@ protected:
void unpack_closure(std::size_t idx, RqPtr request);
virtual void bind_global_params(std::size_t idx, RqPtr request);
virtual void bind_global_results(std::size_t idx, RqPtr request);
+ void handle_quant_host_gather(std::size_t idx, RqPtr request);
void dump_input_tensors(std::size_t idx);
void dump_output_tensors(std::size_t idx);
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 3d8ded4191d..32d86e68336 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
@@ -367,6 +367,7 @@ ov::npuw::CompiledModel::CompiledModel(const std::shared_ptr<ov::Model>& model,
LOG_INFO("Subgraph[" << id << "] is a function call to [" << compiled_fcn_iter->second << "]");
}
m_compiled_submodels[id].host_gather = subgraph._host_gather;
+ m_compiled_submodels[id].quant_unpack_gather = subgraph._quant_unpack_gather;
m_compiled_submodels[id].param_base = fcn_template._param_offset;
m_compiled_submodels[id].closure = subgraph._closure;
m_compiled_submodels[id].lazy_closure = subgraph._lazy_closure;
@@ -541,6 +542,12 @@ void ov::npuw::CompiledModel::CompiledModelDesc::serialize(std::ostream& stream,
write(stream, host_gather.src_idx);
write(stream, host_gather.idx_idx);
+ write(stream, quant_unpack_gather.dst_idx);
+ write(stream, quant_unpack_gather.src_w_idx);
+ write(stream, quant_unpack_gather.src_z_idx);
+ write(stream, quant_unpack_gather.src_s_idx);
+ write(stream, quant_unpack_gather.idx_idx);
+
write(stream, spatial);
write(stream, is_remote);
@@ -609,6 +616,12 @@ void ov::npuw::CompiledModel::CompiledModelDesc::deserialize(std::istream& strea
read(stream, host_gather.src_idx);
read(stream, host_gather.idx_idx);
+ read(stream, quant_unpack_gather.dst_idx);
+ read(stream, quant_unpack_gather.src_w_idx);
+ read(stream, quant_unpack_gather.src_z_idx);
+ read(stream, quant_unpack_gather.src_s_idx);
+ read(stream, quant_unpack_gather.idx_idx);
+
read(stream, spatial);
read(stream, is_remote);
@@ -1699,6 +1712,7 @@ void ov::npuw::CompiledModel::implement_properties() {
BIND(npuw::partitioning::spatial_nway, NPUW_SPATIAL_NWAY),
BIND(npuw::partitioning::spatial_dyn, NPUW_SPATIAL_DYN),
BIND(npuw::partitioning::host_gather, NPUW_HOST_GATHER),
+ BIND(npuw::partitioning::gather_quant, NPUW_HOST_GATHER_QUANT),
BIND(npuw::partitioning::funcall_for_all, NPUW_FUNCALL_FOR_ALL),
BIND(npuw::partitioning::f16_interconnect, NPUW_F16IC),
BIND(npuw::partitioning::dcoff_type, NPUW_DCOFF_TYPE),
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 79524f38180..1f57c050843 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.hpp
@@ -152,6 +152,7 @@ private:
std::optional<std::size_t> replaced_by;
Subgraph::Gather host_gather;
+ Subgraph::QuantUnpackGather quant_unpack_gather;
std::optional<ov::npuw::compiled::Spatial> spatial;
// FIXME: This is a 1:1 copy of the ov::npuw::Subgraph structure
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 b6597f5d4d0..f7a0a82f873 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp
@@ -322,6 +322,7 @@ public:
void saveTinyConstants(const std::string& func_name);
void saveScaleFactors(const std::string& func_name);
void saveRepeatedConstants(const std::string& func_name);
+ void saveTailDictConstants(const std::string& func_name);
void matchParameters(const std::string& func_name);
void matchResults(const std::string& func_name);
void createFunction(const std::string& func_name);
@@ -1430,6 +1431,42 @@ void Partitioner::saveRepeatedConstants(const std::string& func_name) {
}
}
+void Partitioner::saveTailDictConstants(const std::string& func_name) {
+ if (!cfg.get<::intel_npu::NPUW_HOST_GATHER_QUANT>()) {
+ // No need to preserve as constants
+ return;
+ }
+
+ // Depending on the config we might want to save vocab in the tail subgraph as a Constant.
+ auto& func_group = all_functions.at(func_name);
+ auto& subgr_group = func_group.refs;
+
+ if (subgr_group.size() > 1) {
+ // Skip the repeated block
+ return;
+ }
+
+ LOG_VERB("Trying to preserve some (tail) constants for " << func_name << " in model " << model->get_friendly_name()
+ << "...");
+ LOG_BLOCK();
+
+ auto& model_group = func_group.mdls;
+
+ using CPtr = std::shared_ptr<ov::op::v0::Constant>;
+ std::vector<CPtr> to_keep;
+
+ ov::pass::GraphRewrite rewr;
+ rewr.add_matcher<ov::npuw::patterns::opt::PreserveConstDictMatMulCWu>(std::ref(to_keep));
+ rewr.add_matcher<ov::npuw::patterns::opt::PreserveConstDictMatMulCWf8>(std::ref(to_keep));
+ rewr.run_on_model(model_group.front());
+
+ for (auto&& const_to_keep : to_keep) {
+ LOG_DEBUG("[KEEP] " << const_to_keep);
+ func_group.consts_to_keep.insert(const_to_keep);
+ }
+ LOG_VERB("Done");
+}
+
void Partitioner::matchParameters(const std::string& func_name) {
LOG_VERB("Matching parameters for function " << func_name << " in model " << model->get_friendly_name() << "...");
LOG_BLOCK();
@@ -1874,12 +1911,20 @@ void Partitioner::optimize(const std::string& func_name) {
ctx.is_spatial = f._spatial.has_value();
ctx.pmm_dims = cfg.get<::intel_npu::NPUW_PMM>();
+ if (cfg.get<::intel_npu::NPUW_HOST_GATHER_QUANT>() && cfg.get<::intel_npu::NPUW_HOST_GATHER>()) {
+ NPUW_ASSERT(false && "Conflicting configuration: NPUW_HOST_GATHER and NPUW_HOST_GATHER_QUANT should not be "
+ "enabled together!");
+ }
+
// Run Head/Tail passes
ov::pass::GraphRewrite rewr;
- rewr.add_matcher<ov::npuw::patterns::opt::DQUnpackDictGatheru>(std::ref(ctx));
- rewr.add_matcher<ov::npuw::patterns::opt::DQUnpackDictGatherGQi>(std::ref(ctx));
- rewr.add_matcher<ov::npuw::patterns::opt::DQUnpackDictMatMulCWu>(std::ref(ctx));
- rewr.add_matcher<ov::npuw::patterns::opt::DQUnpackDictMatMulCWf8>(std::ref(ctx));
+ if (!cfg.get<::intel_npu::NPUW_HOST_GATHER_QUANT>()) {
+ rewr.add_matcher<ov::npuw::patterns::opt::DQUnpackDictGatheru>(std::ref(ctx));
+ rewr.add_matcher<ov::npuw::patterns::opt::DQUnpackDictGatherGQi>(std::ref(ctx));
+ rewr.add_matcher<ov::npuw::patterns::opt::DQUnpackDictMatMulCWu>(std::ref(ctx));
+ rewr.add_matcher<ov::npuw::patterns::opt::DQUnpackDictMatMulCWf8>(std::ref(ctx));
+ }
+
// NB: This pass is disabled for reason! It doesn't make things better
// rewr.add_matcher<ov::npuw::patterns::opt::DQUnpackDictMatMulGQi>(std::ref(ctx));
rewr.add_matcher<ov::npuw::patterns::opt::CompressDictMatMulf32>(std::ref(ctx));
@@ -1888,6 +1933,29 @@ void Partitioner::optimize(const std::string& func_name) {
rewr.add_matcher<ov::npuw::patterns::opt::ConvToMatmul>(std::ref(ctx));
rewr.run_on_model(f._model);
+ // Quantized Gather + Unpack on host in the runtime
+ if (cfg.get<::intel_npu::NPUW_HOST_GATHER_QUANT>()) {
+ // FIXME: since we are running it after lifted Gather,
+ // we need to first try to match Asymm or Symm patterns.
+ // Otherwise smaller HostGatherQuant might be matched first and break
+ // the quantization logic.
+ {
+ ov::pass::GraphRewrite rewr2;
+ rewr2.add_matcher<ov::npuw::patterns::opt::HostGatherQuantAsymm>(std::ref(ctx));
+ rewr2.run_on_model(f._model);
+ }
+ {
+ ov::pass::GraphRewrite rewr2;
+ rewr2.add_matcher<ov::npuw::patterns::opt::HostGatherQuantSymm>(std::ref(ctx));
+ rewr2.run_on_model(f._model);
+ }
+ {
+ ov::pass::GraphRewrite rewr2;
+ rewr2.add_matcher<ov::npuw::patterns::opt::HostGatherQuant>(std::ref(ctx));
+ rewr2.run_on_model(f._model);
+ }
+ }
+
// Move Gather to host, if required
if (cfg.get<::intel_npu::NPUW_HOST_GATHER>()) {
ov::pass::GraphRewrite rewr2;
@@ -1992,6 +2060,30 @@ void Partitioner::optimize(const std::string& func_name) {
}
}
+ // Host-side quantized gather, pt 1. Add new parameters first
+ if (ctx.params_to_quant_gather_unpack) {
+ auto& params_to_quant_gather_unpack = *ctx.params_to_quant_gather_unpack;
+ for (const auto& param_new_and_unpack : params_to_quant_gather_unpack.params_to_runtime_unpack_gather) {
+ // New input in the graph
+ new_params.push_back(param_new_and_unpack.first);
+ // Note: don't remove w, z and s params here to keep them shared with the quant vocab in tail
+ for (auto&& funcall : func_group.refs) {
+ auto new_elem_type = param_new_and_unpack.first->get_element_type();
+ const auto& new_shape = param_new_and_unpack.first->get_shape();
+ // Note: no allocation needed for this tensor - set to _closure and dummy in _lazy_closure
+ // FIXME: It turns out this tensor will be completely unused.
+ // It will just sit in the memory to do nothing.
+ // Most likely it may stay empty since we need a 1:1 matching between
+ // closure tensors and parameters (minus base).
+ // Based on our logic (when tensors get transferred from lazy tensors via bank
+ // to the closure), this tensor should be non-empty to avoid this process.
+ funcall.get()._closure.push_back(ov::Tensor(new_elem_type, new_shape));
+ funcall.get()._lazy_closure.push_back(LazyTensor());
+ funcall.get()._is_lazy_unpack.push_back(false);
+ }
+ }
+ }
+
// Add all new parameters introduced by this change
f._model->add_parameters(new_params);
@@ -2031,6 +2123,29 @@ void Partitioner::optimize(const std::string& func_name) {
}
}
+ // Host-side quantized gather, pt. 2: Write the gather mappings to funcall
+ if (ctx.params_to_quant_gather_unpack) {
+ auto& params_to_quant_gather_unpack = *ctx.params_to_quant_gather_unpack;
+ for (const auto& param_new_and_unpack_gather :
+ params_to_quant_gather_unpack.params_to_runtime_unpack_gather) {
+ // New param in the graph
+ auto gather_dst_id = f._model->get_parameter_index(param_new_and_unpack_gather.first);
+ // Orig params to gather from
+ auto gather_w_id = f._model->get_parameter_index(param_new_and_unpack_gather.second.w);
+ auto gather_z_id = f._model->get_parameter_index(param_new_and_unpack_gather.second.z);
+ auto gather_s_id = f._model->get_parameter_index(param_new_and_unpack_gather.second.s);
+ // Original pids
+ auto gather_idx_id = f._model->get_parameter_index(params_to_quant_gather_unpack.pids);
+ for (auto&& funcall : func_group.refs) {
+ funcall.get()._quant_unpack_gather = ov::npuw::Subgraph::QuantUnpackGather{gather_dst_id,
+ gather_w_id,
+ gather_z_id,
+ gather_s_id,
+ gather_idx_id};
+ }
+ }
+ }
+
// FIXME: workaround
// Set lazy unpack indexes not to be unpacked in DCOFF
for (auto&& fref : func_group.refs) {
@@ -2344,6 +2459,7 @@ ov::npuw::Partitioning ov::npuw::getPartitioning(const std::shared_ptr<ov::Model
p.propagateConvertsOut(func_group);
p.sanityCheck(func_group);
p.saveRepeatedConstants(func_group);
+ p.saveTailDictConstants(func_group);
p.matchParameters(func_group);
p.matchResults(func_group);
p.matchRepeatedSubgraphs(func_group);
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.hpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.hpp
index b4b97df1a96..d1ded00c0be 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.hpp
@@ -59,6 +59,17 @@ struct Subgraph {
};
Gather _host_gather;
+ struct QuantUnpackGather {
+ int64_t dst_idx = -1;
+
+ int64_t src_w_idx = -1;
+ int64_t src_z_idx = -1;
+ int64_t src_s_idx = -1;
+
+ int64_t idx_idx = -1;
+ };
+ QuantUnpackGather _quant_unpack_gather;
+
using Ref = std::reference_wrapper<Subgraph>;
};
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/dcoff.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/dcoff.cpp
index b51ca838891..05d3d2b0227 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/dcoff.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/dcoff.cpp
@@ -195,6 +195,24 @@ void finalize_remap(Function& fbody, Subgraph& fsg, const ClosureRemap& m) {
params[fsg._host_gather.dst_idx]};
}
+ struct QuantUnpackGatherParams {
+ PPtr pdst; // Parameter @ function body - gathered and unpacked ids
+
+ PPtr psrcw; // Parameter @ function body - vocab tensor
+ PPtr psrcz; // Parameter @ function body - vocab tensor zeropoint
+ PPtr psrcs; // Parameter @ function body - vocab tensor scale
+
+ PPtr pidx; // Parameter @ function body - input_ids
+ };
+ QuantUnpackGatherParams quant_unpack_gather_params;
+ if (fsg._quant_unpack_gather.dst_idx != -1) {
+ quant_unpack_gather_params = QuantUnpackGatherParams{params[fsg._quant_unpack_gather.dst_idx],
+ params[fsg._quant_unpack_gather.src_w_idx],
+ params[fsg._quant_unpack_gather.src_z_idx],
+ params[fsg._quant_unpack_gather.src_s_idx],
+ params[fsg._quant_unpack_gather.idx_idx]};
+ }
+
for (auto&& p : m.params_to_remove) {
LOG_DEBUG("Removing parameter " << p);
LOG_BLOCK();
@@ -208,7 +226,19 @@ void finalize_remap(Function& fbody, Subgraph& fsg, const ClosureRemap& m) {
fsg._host_gather.dst_idx = fbody._model->get_parameter_index(gather_params.pdst);
}
+ if (fsg._quant_unpack_gather.dst_idx != -1) {
+ // Update indices for gather
+ fsg._quant_unpack_gather.idx_idx = fbody._model->get_parameter_index(quant_unpack_gather_params.pidx);
+
+ fsg._quant_unpack_gather.src_w_idx = fbody._model->get_parameter_index(quant_unpack_gather_params.psrcw);
+ fsg._quant_unpack_gather.src_z_idx = fbody._model->get_parameter_index(quant_unpack_gather_params.psrcz);
+ fsg._quant_unpack_gather.src_s_idx = fbody._model->get_parameter_index(quant_unpack_gather_params.psrcs);
+
+ fsg._quant_unpack_gather.dst_idx = fbody._model->get_parameter_index(quant_unpack_gather_params.pdst);
+ }
+
fbody._model->validate_nodes_and_infer_types();
+
LOG_DEBUG("DONE");
}
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 804a46dd851..021a8b43605 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
@@ -123,6 +123,50 @@ Context::PPtr Context::host_gather(const Context::PPtr& w, const Context::PPtr&
return new_param;
}
+Context::PPtr Context::host_gather_unpack_quant(Context::PPtr ids,
+ Context::PPtr w,
+ Context::PPtr z,
+ Context::PPtr s,
+ ov::element::Type type) {
+ const auto& w_shape = w->get_shape();
+ const auto& ids_shape = ids->get_shape();
+
+ NPUW_ASSERT(ids_shape.size() == 2);
+ NPUW_ASSERT(ids_shape[0] == 1);
+
+ Context::PPtr new_param;
+
+ if (s) {
+ const auto& s_shape = s->get_shape();
+ if (w_shape.size() == 3 && s_shape.size() == 3) {
+ ov::Shape new_shape = {1, ids_shape[1], w_shape[1] * w_shape[2]};
+ new_param = std::make_shared<ov::op::v0::Parameter>(type, new_shape);
+ } else if (w_shape.size() == 2 && s_shape.size() == 2) {
+ ov::Shape new_shape = {1, ids_shape[1], w_shape[1]};
+ new_param = std::make_shared<ov::op::v0::Parameter>(type, new_shape);
+ } else {
+ NPUW_ASSERT(false && "Yet unsupported combination");
+ }
+ } else {
+ // No scale, no zerop
+ if (w_shape.size() == 3) {
+ ov::Shape new_shape = {1, ids_shape[1], w_shape[1] * w_shape[2]};
+ new_param = std::make_shared<ov::op::v0::Parameter>(type, new_shape);
+ } else if (w_shape.size() == 2) {
+ ov::Shape new_shape = {1, ids_shape[1], w_shape[1]};
+ new_param = std::make_shared<ov::op::v0::Parameter>(type, new_shape);
+ } else {
+ NPUW_ASSERT(false && "Yet unsupported combination");
+ }
+ }
+
+ NPUW_ASSERT(new_param);
+ params_to_quant_gather_unpack = QuantizedGather{};
+ params_to_quant_gather_unpack->params_to_runtime_unpack_gather[new_param] = {w, z, s};
+ params_to_quant_gather_unpack->pids = ids;
+ return new_param;
+}
+
namespace opp = ov::pass::pattern;
namespace uat = ov::npuw::util::at;
@@ -1284,6 +1328,210 @@ DQUnpackDictGatherGQi::DQUnpackDictGatherGQi(Context::Ref ctx) {
register_matcher(std::make_shared<opp::Matcher>(qcvtm, "DQDictGatherGQu"), std::move(callback));
}
+// This is a companion to DQLiftGatherAsymCW step. This pass runs if
+// the respective block (mainly, a head) was turned a function
+// (e.g. with FUNCALL_FOR_ALL) As in this case the HostGatherQuant
+// compile-time converts asymmetric MM to fp16, do the same thing here
+// Overall it's a combination of DQUnpackDictGather and HostGather
+// but we do unpack and gather in the runtime.
+HostGatherQuantAsymm::HostGatherQuantAsymm(Context::Ref ctx) {
+ auto pids = opp::wrap_type<ov::op::v0::Parameter>();
+ auto cvtids = opp::optional<ov::op::v0::Convert>({pids->output(0)});
+
+ auto qweight = opp::wrap_type<ov::op::v0::Parameter>();
+ auto qzerop = opp::wrap_type<ov::op::v0::Parameter>();
+ auto qcoeff = opp::wrap_type<ov::op::v0::Parameter>();
+ auto qgthrw = opp::wrap_type<ov::op::v8::Gather>({qweight, cvtids, opp::any_input()});
+ auto qgthrz = opp::wrap_type<ov::op::v8::Gather>({qzerop, cvtids, opp::any_input()});
+ auto qgthrs = opp::wrap_type<ov::op::v8::Gather>({qcoeff, cvtids, opp::any_input()});
+
+ 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 qmuls = opp::wrap_type<ov::op::v1::Multiply>({qsubz, qgthrs});
+ auto qcvtm = opp::wrap_type<ov::op::v0::Convert>({qmuls});
+
+ // Note: Use [=] to make sure the above objects stay alive in the callback
+ auto callback = [=](ov::pass::pattern::Matcher& m) {
+ auto& node_to_output = m.get_pattern_value_map();
+ const auto& matched_out_mul = node_to_output.at(qmuls);
+ auto out_shape = matched_out_mul.get_shape();
+
+ if (out_shape.size() != 3 && out_shape.size() != 4) {
+ return false;
+ }
+
+ // shape=3 == CW model, 1 x N x Hs
+ // shape=4 == GQ model, 1 x G x(N/G) x Hs
+ // were Hs = hidden size, G is # of groups, N is the prompt size.
+ auto out_len = out_shape.size() == 3 ? out_shape[2] : out_shape[2] * out_shape[3];
+
+ auto sole_reader = [](ov::Output<ov::Node> out) {
+ const auto readers = out.get_target_inputs();
+ NPUW_ASSERT(readers.size() >= 1);
+ return readers.begin()->get_node();
+ };
+
+ if (out_len >= 2048 && (matched_out_mul.get_target_inputs().size() > 1 ||
+ ov::is_type<ov::op::v0::Convert>(sole_reader(matched_out_mul)))) {
+ auto matched_node_qweight = node_to_output.at(qweight).get_node_shared_ptr();
+ auto matched_node_qzerop = node_to_output.at(qzerop).get_node_shared_ptr();
+ auto matched_node_qcoeff = node_to_output.at(qcoeff).get_node_shared_ptr();
+ auto matched_node_ids = node_to_output.at(pids).get_node_shared_ptr();
+ auto matched_node_cvt = node_to_output.at(qcvtm).get_node_shared_ptr();
+
+ auto matched_qweight = std::static_pointer_cast<ov::op::v0::Parameter>(matched_node_qweight);
+ auto matched_qzerop = std::static_pointer_cast<ov::op::v0::Parameter>(matched_node_qzerop);
+ auto matched_qcoeff = std::static_pointer_cast<ov::op::v0::Parameter>(matched_node_qcoeff);
+ auto matched_ids = std::static_pointer_cast<ov::op::v0::Parameter>(matched_node_ids);
+
+ // Strip down the DQ subgraph, replace the original Q-ed closure tensor with future- unpacked and gathered
+ // fp16
+ auto new_wi = ctx.get().host_gather_unpack_quant(matched_ids,
+ matched_qweight,
+ matched_qzerop,
+ matched_qcoeff,
+ ov::element::f16);
+ matched_node_cvt->input(0).replace_source_output(new_wi);
+
+ matched_node_cvt->validate_and_infer_types();
+
+ return true; // root has changed
+ }
+ return false; // root hasn't changed
+ };
+ register_matcher(std::make_shared<opp::Matcher>(qcvtm, "HostGatherQuantAsymm"), std::move(callback));
+}
+
+// This is a follow-up to DQLiftGatherSymGQ step, which happens if the respective
+// block (mainly, a head) was turned a function (e.g. with FUNCALL_FOR_ALL)
+// Overall it's a combination of DQUnpackDictGatherGQi and HostGatherDQ
+// but we do unpack and gather in the runtime.
+HostGatherQuantSymm::HostGatherQuantSymm(Context::Ref ctx) {
+ auto pids = opp::wrap_type<ov::op::v0::Parameter>();
+ auto cvtids = opp::optional<ov::op::v0::Convert>({pids->output(0)});
+
+ auto qweight = opp::wrap_type<ov::op::v0::Parameter>();
+ auto qcoeff = opp::wrap_type<ov::op::v0::Parameter>();
+ auto qgthrw = opp::wrap_type<ov::op::v8::Gather>({qweight, cvtids, opp::any_input()});
+ auto qgthrs = opp::wrap_type<ov::op::v8::Gather>({qcoeff, cvtids, opp::any_input()});
+
+ auto qcvtw = opp::wrap_type<ov::op::v0::Convert>({qgthrw});
+ auto qmuls = opp::wrap_type<ov::op::v1::Multiply>({qcvtw, qgthrs});
+ auto qrshp = opp::wrap_type<ov::op::v1::Reshape>({qmuls, opp::any_input()});
+ auto qcvtm = opp::wrap_type<ov::op::v0::Convert>({qrshp});
+
+ // Note: Use [=] to make sure the above objects stay alive in the callback
+ auto callback = [=](ov::pass::pattern::Matcher& m) {
+ auto& node_to_output = m.get_pattern_value_map();
+ const auto& matched_out_mul = node_to_output.at(qmuls);
+ auto out_shape = matched_out_mul.get_shape();
+
+ if (out_shape.size() != 3 && out_shape.size() != 4) {
+ return false;
+ }
+
+ // shape=3 == CW model, 1 x N x Hs
+ // shape=4 == GQ model, 1 x G x(N/G) x Hs
+ // were Hs = hidden size, G is # of groups, N is the prompt size.
+ auto out_len = out_shape.size() == 3 ? out_shape[2] : out_shape[2] * out_shape[3];
+
+ const auto& matched_out_qweight = node_to_output.at(qweight);
+ const auto& matched_out_reshape = node_to_output.at(qweight);
+ auto qweight_type = matched_out_qweight.get_element_type();
+
+ auto sole_reader = [](ov::Output<ov::Node> out) {
+ const auto readers = out.get_target_inputs();
+ NPUW_ASSERT(readers.size() >= 1);
+ return readers.begin()->get_node();
+ };
+
+ if (out_len >= 2048 &&
+ (qweight_type == ov::element::i4 || qweight_type == ov::element::i8 ||
+ qweight_type == ov::element::f8e4m3 || qweight_type == ov::element::f8e5m2 ||
+ qweight_type == ov::element::f8e8m0) &&
+ (matched_out_reshape.get_target_inputs().size() > 1 ||
+ ov::is_type<ov::op::v0::Convert>(sole_reader(matched_out_reshape)))) {
+ auto matched_node_qweight = node_to_output.at(qweight).get_node_shared_ptr();
+ auto matched_node_qcoeff = node_to_output.at(qcoeff).get_node_shared_ptr();
+ auto matched_node_ids = node_to_output.at(pids).get_node_shared_ptr();
+ auto matched_node_cvt = node_to_output.at(qcvtm).get_node_shared_ptr();
+
+ auto matched_qweight = std::static_pointer_cast<ov::op::v0::Parameter>(matched_node_qweight);
+ auto matched_qcoeff = std::static_pointer_cast<ov::op::v0::Parameter>(matched_node_qcoeff);
+ auto matched_ids = std::static_pointer_cast<ov::op::v0::Parameter>(matched_node_ids);
+
+ // Strip down the DQ subgraph, replace the original Q-ed closure tensor with unpacked fp16
+ auto new_wi = ctx.get().host_gather_unpack_quant(matched_ids,
+ matched_qweight,
+ matched_qcoeff,
+ nullptr,
+ ov::element::f16);
+ matched_node_cvt->input(0).replace_source_output(new_wi);
+
+ matched_node_cvt->validate_and_infer_types();
+
+ return true; // root has changed
+ }
+ return false; // root hasn't changed
+ };
+ register_matcher(std::make_shared<opp::Matcher>(qcvtm, "HostGatherQuantSymm"), std::move(callback));
+}
+
+// Overall it's a combination of DQUnpackDictGather and HostGather
+// but we do unpack and gather in the runtime.
+HostGatherQuant::HostGatherQuant(Context::Ref ctx) {
+ auto pids = opp::wrap_type<ov::op::v0::Parameter>();
+ auto cvtids = opp::optional<ov::op::v0::Convert>({pids->output(0)});
+
+ auto qweight = opp::wrap_type<ov::op::v0::Parameter>();
+ auto qgthrw = opp::wrap_type<ov::op::v8::Gather>({qweight, cvtids, opp::any_input()});
+
+ auto callback = [=](ov::pass::pattern::Matcher& m) {
+ auto& node_to_output = m.get_pattern_value_map();
+ auto out_shape = node_to_output.at(qgthrw).get_shape();
+ auto& matched_out_qweight = node_to_output.at(qweight);
+ auto qweight_type = matched_out_qweight.get_element_type();
+
+ const auto& matched_out_gather = node_to_output.at(qgthrw);
+
+ auto sole_reader = [](ov::Output<ov::Node> out) {
+ const auto readers = out.get_target_inputs();
+ NPUW_ASSERT(readers.size() >= 1);
+ return readers.begin()->get_node();
+ };
+
+ if (out_shape.back() >= 2048 && (matched_out_gather.get_target_inputs().size() > 1 ||
+ ov::is_type<ov::op::v0::Convert>(sole_reader(matched_out_gather)))) {
+ auto matched_node_qweight = node_to_output.at(qweight).get_node_shared_ptr();
+ auto matched_node_ids = node_to_output.at(pids).get_node_shared_ptr();
+ const auto& matched_out_gthr = node_to_output.at(qgthrw);
+ auto matched_qweight = std::static_pointer_cast<ov::op::v0::Parameter>(matched_node_qweight);
+ auto matched_ids = std::static_pointer_cast<ov::op::v0::Parameter>(matched_node_ids);
+
+ if (qweight_type == ov::element::f32) {
+ ctx.get().to_f16(matched_qweight);
+ }
+
+ auto new_param =
+ ctx.get().host_gather_unpack_quant(matched_ids, matched_qweight, nullptr, nullptr, ov::element::f16);
+ std::shared_ptr<ov::Node> new_cvt;
+ if (qweight_type == ov::element::f16) {
+ new_cvt = new_param;
+ } else {
+ new_cvt = std::make_shared<ov::op::v0::Convert>(new_param, ov::element::f32);
+ }
+ NPUW_ASSERT(new_cvt);
+ for (auto&& r : matched_out_gthr.get_target_inputs()) {
+ r.replace_source_output(new_cvt);
+ }
+ return true; // root has changed
+ }
+ return false; // root hasn't changed
+ };
+ register_matcher(std::make_shared<opp::Matcher>(qgthrw, "HostGatherQuant"), std::move(callback));
+}
+
// Identify the case* where the FP16/32 vocab tensor is gathered with
// input_ids and the embedding size is high. In this case, substitute
// gather with a host-side op. Lower vocab tensor to f16.
@@ -1618,6 +1866,99 @@ CompressDictMatMulf32::CompressDictMatMulf32(Context::Ref ctx) {
register_matcher(std::make_shared<opp::Matcher>(res, "OptCompressDictMatMulf32"), std::move(callback));
}
+// Const(W) -> to(f16) ->
+// Const(Z) -> to(f16) -> Subtract
+// Const(S) ---------------------> Multiply -> to(f32) -> MatMul -> Result
+// ???(Act) -------------------------------------------->
+
+PreserveConstDictMatMulCWu::PreserveConstDictMatMulCWu(PreserveConstDictMatMulCWu::Results to_keep) {
+ auto qweight = opp::wrap_type<ov::op::v0::Constant>();
+ auto qcoeff = opp::wrap_type<ov::op::v0::Constant>();
+ 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 qmuls = opp::wrap_type<ov::op::v1::Multiply>({qsub, qcoeff});
+ auto qcvtm = opp::wrap_type<ov::op::v0::Convert>({qmuls});
+ auto qmmi = opp::any_input();
+ auto qmm = opp::wrap_type<ov::op::v0::MatMul>({qmmi, qcvtm});
+ auto qres = opp::wrap_type<ov::op::v0::Result>({qmm});
+
+ // Note: Use [=] to make sure the above objects stay alive in the callback
+ auto callback = [=](ov::pass::pattern::Matcher& m) {
+ auto& node_to_output = m.get_pattern_value_map();
+
+ auto matched_node_qweight = node_to_output.at(qweight).get_node_shared_ptr();
+ auto matched_node_qzerop = node_to_output.at(qzerop).get_node_shared_ptr();
+ auto matched_node_cvtz = node_to_output.at(qcvtz).get_node_shared_ptr();
+ auto matched_node_cvtw = node_to_output.at(qcvtw).get_node_shared_ptr();
+ auto matched_node_qcoeff = node_to_output.at(qcoeff).get_node_shared_ptr();
+ auto matched_node_qmuls = node_to_output.at(qmuls).get_node_shared_ptr();
+ auto matched_node_matmul = node_to_output.at(qmm).get_node_shared_ptr();
+
+ auto matched_qweight = std::static_pointer_cast<ov::op::v0::Constant>(matched_node_qweight);
+ auto matched_qzerop = std::static_pointer_cast<ov::op::v0::Constant>(matched_node_qzerop);
+ auto matched_qcoeff = std::static_pointer_cast<ov::op::v0::Constant>(matched_node_qcoeff);
+ auto matched_matmul = std::static_pointer_cast<ov::op::v0::MatMul>(matched_node_matmul);
+
+ auto qcoeff_shape = matched_qcoeff->output(0).get_shape();
+
+ if (ov::element::u8 == matched_qweight->get_element_type() && qcoeff_shape[1] == 1 &&
+ !matched_matmul->get_transpose_a() && matched_matmul->get_transpose_b()) {
+ to_keep.get().push_back(matched_qweight);
+ to_keep.get().push_back(matched_qzerop);
+ to_keep.get().push_back(matched_qcoeff);
+
+ return false; // root hasn't changed
+ }
+ return false; // root hasn't changed
+ };
+ register_matcher(std::make_shared<opp::Matcher>(qres, "OptPreserveConstDictMatMulCWu"), std::move(callback));
+}
+
+// Const(W) ---> to(f16) --->
+// Const(S) ----------------> Multiply -> MatMul -> Result
+// ???(Act) ---------------------------->
+
+PreserveConstDictMatMulCWf8::PreserveConstDictMatMulCWf8(PreserveConstDictMatMulCWf8::Results to_keep) {
+ auto qweight = opp::wrap_type<ov::op::v0::Constant>();
+ auto qcoeff = opp::wrap_type<ov::op::v0::Constant>();
+ auto qcvtw = opp::wrap_type<ov::op::v0::Convert>({qweight});
+ auto qmuls = opp::wrap_type<ov::op::v1::Multiply>({qcvtw, qcoeff});
+ auto qmmi = opp::any_input();
+ auto qmm = opp::wrap_type<ov::op::v0::MatMul>({qmmi, qmuls});
+ auto qres = opp::wrap_type<ov::op::v0::Result>({qmm});
+
+ // Note: Use [=] to make sure the above objects stay alive in the callback
+ auto callback = [=](ov::pass::pattern::Matcher& m) {
+ auto& node_to_output = m.get_pattern_value_map();
+
+ auto matched_node_qweight = node_to_output.at(qweight).get_node_shared_ptr();
+ auto matched_node_cvtw = node_to_output.at(qcvtw).get_node_shared_ptr();
+ auto matched_node_qcoeff = node_to_output.at(qcoeff).get_node_shared_ptr();
+ auto matched_node_matmul = node_to_output.at(qmm).get_node_shared_ptr();
+ auto matched_node_qmuls = node_to_output.at(qmuls).get_node_shared_ptr();
+
+ auto matched_qweight = std::static_pointer_cast<ov::op::v0::Constant>(matched_node_qweight);
+ auto matched_qcoeff = std::static_pointer_cast<ov::op::v0::Constant>(matched_node_qcoeff);
+ auto matched_matmul = std::static_pointer_cast<ov::op::v0::MatMul>(matched_node_matmul);
+
+ auto qcoeff_shape = matched_qcoeff->output(0).get_shape();
+
+ if ((ov::element::f8e4m3 == matched_qweight->get_element_type() ||
+ ov::element::f8e5m2 == matched_qweight->get_element_type() ||
+ ov::element::f8e8m0 == matched_qweight->get_element_type()) &&
+ qcoeff_shape[1] == 1 && !matched_matmul->get_transpose_a() && matched_matmul->get_transpose_b()) {
+ to_keep.get().push_back(matched_qweight);
+ to_keep.get().push_back(matched_qcoeff);
+
+ return false; // root hasn't changed
+ }
+ return false; // root hasn't changed
+ };
+ register_matcher(std::make_shared<opp::Matcher>(qres, "OptPreserveConstDictMatMulCWf8"), std::move(callback));
+}
+
SliceLastMatmul::SliceLastMatmul() {
auto matmul = opp::wrap_type<ov::op::v0::MatMul>({opp::any_input(), opp::any_input()});
auto convert = opp::optional<ov::op::v0::Convert>({matmul->output(0)});
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.hpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.hpp
index 77578e890bb..7456b2e7dfc 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.hpp
@@ -26,6 +26,7 @@ struct Context {
using PPtr = std::shared_ptr<ov::op::v0::Parameter>;
using NPtr = std::shared_ptr<ov::Node>;
+ using CPtr = std::shared_ptr<ov::op::v0::Constant>;
using Axes = std::vector<std::size_t>;
std::map<PPtr, Axes> closures_to_permute;
@@ -59,6 +60,14 @@ struct Context {
std::optional<Gather> params_to_gather;
PPtr host_gather(const PPtr& w, const PPtr& ids);
+ struct QuantizedGather {
+ // New param -> orig params
+ std::map<PPtr, DQUnpack> params_to_runtime_unpack_gather;
+ PPtr pids;
+ };
+ std::optional<QuantizedGather> params_to_quant_gather_unpack;
+ PPtr host_gather_unpack_quant(PPtr ids, PPtr w, PPtr z, PPtr s, ov::element::Type type);
+
using Ref = std::reference_wrapper<Context>;
};
@@ -146,6 +155,24 @@ public:
DQUnpackDictGatherGQi(Context::Ref ctx);
};
+class HostGatherQuantAsymm : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("npuw::patterns::opt::HostGatherQuantAsymm");
+ HostGatherQuantAsymm(Context::Ref ctx);
+};
+
+class HostGatherQuantSymm : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("npuw::patterns::opt::HostGatherQuantSymm");
+ HostGatherQuantSymm(Context::Ref ctx);
+};
+
+class HostGatherQuant : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("npuw::patterns::opt::HostGatherQuant");
+ HostGatherQuant(Context::Ref ctx);
+};
+
class HostGather : public ov::pass::MatcherPass {
public:
OPENVINO_MATCHER_PASS_RTTI("npuw::patterns::opt::HostGather");
@@ -184,6 +211,27 @@ public:
CompressDictMatMulf32(Context::Ref ctx);
};
+// Tail vocab transformations
+class PreserveConstDictMatMulCWu : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("npuw::patterns::opt::PreserveConstDictMatMulCWu");
+
+ using CPtr = std::shared_ptr<ov::op::v0::Constant>;
+ using Results = std::reference_wrapper<std::vector<CPtr>>;
+
+ PreserveConstDictMatMulCWu(Results to_keep);
+};
+
+class PreserveConstDictMatMulCWf8 : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("npuw::patterns::opt::PreserveConstDictMatMulCWf8");
+
+ using CPtr = std::shared_ptr<ov::op::v0::Constant>;
+ using Results = std::reference_wrapper<std::vector<CPtr>>;
+
+ PreserveConstDictMatMulCWf8(Results to_keep);
+};
+
// Slice last Matmul
class SliceLastMatmul : public ov::pass::MatcherPass {
public:
diff --git a/src/plugins/intel_npu/src/plugin/npuw/serialization.hpp b/src/plugins/intel_npu/src/plugin/npuw/serialization.hpp
index aaf82095aa0..340f12f135f 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/serialization.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/serialization.hpp
@@ -34,7 +34,7 @@ const constexpr ov::npuw::s11n::IndicatorType NPUW_COMPILED_MODEL_INDICATOR =
const constexpr ov::npuw::s11n::IndicatorType NPUW_LLM_COMPILED_MODEL_INDICATOR =
{char{0x4c}, char{0x4c}, char{0x4d}, char{0x43}, char{0x4d}, char{0x4f}};
-const constexpr char* NPUW_SERIALIZATION_VERSION = "0.3";
+const constexpr char* NPUW_SERIALIZATION_VERSION = "0.4";
// Forward declaration
namespace intel_npu {
diff --git a/src/plugins/intel_npu/src/plugin/npuw/util.cpp b/src/plugins/intel_npu/src/plugin/npuw/util.cpp
index 0ca6f4382cb..bc4075f4009 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/util.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/util.cpp
@@ -339,6 +339,22 @@ void ov::npuw::util::unpack(const ov::SoPtr<ov::ITensor>& from,
scale->data(),
ov::Strides{scale_strides[0], scale_strides[2]});
+ ov::npuw::util::XARCH::unpack_u8f16(ov::get_tensor_impl(wraped_from),
+ ov::get_tensor_impl(wraped_zerop),
+ ov::get_tensor_impl(wraped_scale),
+ to,
+ unpack_options);
+ } else if (scale_shape.size() == 3 && scale_shape[0] == 1 && scale_shape[2] == 1) {
+ // Special case for broadcasting vocab by 2 dimensions
+ // FIXME: all this logic probably should be in some specific unpack or another util function
+ ov::Tensor wraped_from(from->get_element_type(), ov::Shape{from_shape[1], from_shape[2]}, from->data());
+ ov::Tensor wraped_zerop(zerop->get_element_type(),
+ ov::Shape{zerop_shape[1], zerop_shape[2]},
+ zerop->data());
+ ov::Tensor wraped_scale(scale->get_element_type(),
+ ov::Shape{scale_shape[1], scale_shape[2]},
+ scale->data());
+
ov::npuw::util::XARCH::unpack_u8f16(ov::get_tensor_impl(wraped_from),
ov::get_tensor_impl(wraped_zerop),
ov::get_tensor_impl(wraped_scale),
@@ -358,7 +374,9 @@ void ov::npuw::util::gather(const ov::SoPtr<ov::ITensor>& src,
const auto src_type = src->get_element_type();
const auto dst_type = dst->get_element_type();
NPUW_ASSERT(idx->get_element_type() == ov::element::i64);
- NPUW_ASSERT(src_type == ov::element::f16 || src_type == ov::element::f32);
+ NPUW_ASSERT(src_type == ov::element::f16 || src_type == ov::element::f32 || src_type == ov::element::f8e4m3 ||
+ src_type == ov::element::f8e5m2 || src_type == ov::element::f8e8m0 || src_type == ov::element::i8 ||
+ src_type == ov::element::u8);
NPUW_ASSERT(src_type == dst_type);
const auto& idx_shape = idx->get_shape();