OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
Revert "[NPUW] Support LFM2 Model for NPU (#33367)" (#33825)
Alexander Kalistratov08aa357021ee
diff --git a/src/core/src/pass/stateful_to_stateless.cpp b/src/core/src/pass/stateful_to_stateless.cppindex 22ab8910fc0..3e7002499e3 100644--- a/src/core/src/pass/stateful_to_stateless.cpp+++ b/src/core/src/pass/stateful_to_stateless.cpp@@ -31,12 +31,8 @@ std::shared_ptr<v0::Parameter> get_parameter_by_tensor_name(const std::shared_ptstruct Variable {struct Context {// to hold compiled once regex for all Variable instances- // Pattern 1: optimum-intel convention (e.g., past_key_values.0.keypresent.0.key)const std::regex naming_convention =std::regex(R"((past_key_values\.(\d+)\.(key|value))(present\.(\d+)\.(key|value)))");- // Pattern 2: LFM2 convention (e.g., cache_params.past.key.0cache_params.present.key.0)- const std::regex lfm2_naming_convention =- std::regex(R"(cache_params\.past\.(key|value|conv)\.(\d+)cache_params\.present\.(key|value|conv)\.(\d+))");};Variable(const Context& context, const std::string& variable_name) : variable_name(variable_name) {@@ -52,24 +48,6 @@ struct Variable {} else {index = -1;}- } else if (std::regex_match(variable_name, match, context.lfm2_naming_convention)) {- // LFM2 pattern: cache_params.past.key.0cache_params.present.key.0- std::string past_type = match[1].str();- std::string past_idx = match[2].str();- std::string present_type = match[3].str();- std::string present_idx = match[4].str();-- input_name = "past_key_values." + past_idx + "." + past_type;- output_name = "present." + present_idx + "." + present_type;-- if (past_idx == present_idx && past_type == present_type &&- past_idx.length() <= std::numeric_limits<int>::digits10) {- // For "conv" type, place them after key/value pairs- int type_offset = (past_type == "key") ? 0 : (past_type == "value") ? 1 : 2;- index = std::stoi(past_idx) * 3 + type_offset; // key=0, value=1, conv=2 within each layer- } else {- index = -1;- }} else {// Variable name doesn't follow the expected naming convention. It doens't prevent forming// a correct stateless model but doesn't give a way to restore all names and inputs/outputs ordering@@ -117,7 +95,6 @@ bool ov::pass::StatefulToStateless::run_on_model(const std::shared_ptr<ov::ModelVariable::Context context;std::unordered_map<std::string, std::shared_ptr<ov::Node>>future_params; // to collect nodes, each with a single output that will be replaced by new parameters- std::unordered_set<std::string> processed_variable_ids; // Track which ReadValues we've processedif (beam_idx) {for (const ov::Input<ov::Node>& input : beam_idx->get_output_target_inputs(0)) {if (auto gather = ov::as_type_ptr<op::util::GatherBase>(input.get_node()->shared_from_this())) {@@ -128,26 +105,13 @@ bool ov::pass::StatefulToStateless::run_on_model(const std::shared_ptr<ov::Modelauto variable_name = read_value->get_variable_id();variables.push_back(Variable(context, variable_name));future_params[variable_name] = gather;- processed_variable_ids.insert(variable_name);}}- model->remove_parameter(beam_idx);} else {OPENVINO_THROW("Stateful models without `beam_idx` input are not supported in StatefulToStateless transformation");}-- // Process ReadValues that are NOT connected via beam_idx (e.g., Conv caches in LFM2)- for (const auto& op : model->get_ops()) {- if (auto read_value = ov::as_type_ptr<op::util::ReadValueBase>(op)) {- auto variable_name = read_value->get_variable_id();- if (processed_variable_ids.find(variable_name) == processed_variable_ids.end()) {- variables.push_back(Variable(context, variable_name));- future_params[variable_name] = read_value;- processed_variable_ids.insert(variable_name);- }- }- }+ model->remove_parameter(beam_idx);typedef std::shared_ptr<op::util::AssignBase> PAssign;std::unordered_map<std::string, PAssign> assigns_by_var_id;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.cppindex 1cf075f6d52..b106d51c7bb 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@@ -918,12 +918,6 @@ void reshape_to_static(std::shared_ptr<ov::Model> model,new_shape = ov::PartialShape({input.get_partial_shape()[0], lora_rank});} else if (ov::npuw::util::matchLoRAMatMulBString(input_name)) {new_shape = ov::PartialShape({input.get_partial_shape()[0], lora_rank});- } else if (input_name.find("cache_params.past.conv") != std::string::npos ||- input_name.find("cache_params.present.conv") != std::string::npos) {- // LFM2 Conv cache: shape is [batch, channels, kernel_size]- const auto& partial_shape = input.get_partial_shape();- new_shape = partial_shape;- new_shape[0] = 1;} else {const auto& partial_shape = input.get_partial_shape();new_shape = partial_shape;diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.cppindex ed1af74888e..1846de287dd 100644--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.cpp@@ -652,7 +652,6 @@ void Snapshot::earlyRegroup() {HNDL(DQMatMulCWi4);HNDL(DQMatMulGQi4);HNDL(DQMatMulConv);- HNDL(DQGroupConv);HNDL(VocabMatMul);HNDL(VariadicSplit);HNDL_FAKE(FakeConvert);diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/utils/utils.hpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/utils/utils.hppindex 5489926ff57..5f15a1bb3e6 100644--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/utils/utils.hpp+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/utils/utils.hpp@@ -90,7 +90,7 @@ std::vector<std::string> getNoFolds(const std::string& nofolds_unparsed);static const std::map<std::string, std::string> ISOL_PRESETS = {{"COMPUTE","P:DQMatMulGQu4/compute,P:DQMatMulCWu4/compute,""P:DQMatMulGQi4/compute,P:DQMatMulCWi4/compute,"- "P:DQMatMulConv/compute,P:DQGroupConv/compute,"+ "P:DQMatMulConv/compute,""P:VocabMatMul/compute,""P:RMSNorm/compute,P:RMSNorm2/compute,""P:RMSNorm3/compute,P:RMSNorm4/compute,"diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/compute.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/compute.cppindex 649c3a54c84..f1692a9e98d 100644--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/compute.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/compute.cpp@@ -326,44 +326,6 @@ DQMatMulConv::DQMatMulConv(const std::shared_ptr<ov::npuw::online::Snapshot>& snregister_matcher(std::make_shared<opp::Matcher>(transpose_out, "TagDQMatMulConv"), std::move(callback));}-// Pattern:-// Param/Const --> Convert(f32) --> Multiply -> GroupConvolution ->-// Param/Const -> (Convert(f32)) ->--DQGroupConv::DQGroupConv(const std::shared_ptr<ov::npuw::online::Snapshot>& snapshot, const std::string& isol_tag) {- auto param = opp::any_input();- auto convert = opp::wrap_type<ov::op::v0::Convert>({param->output(0)});- auto param2 = opp::any_input();- auto convert2 = opp::optional<ov::op::v0::Convert>({param2->output(0)});- auto multiply = opp::wrap_type<ov::op::v1::Multiply>({convert, convert2});- auto group_conv = opp::wrap_type<ov::op::v1::GroupConvolution>({opp::any_input(), multiply});-- auto node_to_gptr = snapshot->getNodeToGroupMap();-- // 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_node_param = node_to_output.at(param);- const auto& matched_node_param2 = node_to_output.at(param2);-- auto matched_node_multiply = node_to_output.at(multiply).get_node_shared_ptr();- auto matched_node_group_conv = node_to_output.at(group_conv).get_node_shared_ptr();-- if ((matched_node_param.get_element_type() == ov::element::i4 ||- matched_node_param.get_element_type() == ov::element::i8) &&- (matched_node_param2.get_element_type() == ov::element::f32 ||- matched_node_param2.get_element_type() == ov::element::f16)) {- // Partitioning ignores Param/Const -> Convert nodes- node_to_gptr->at(matched_node_multiply)->isolate(isol_tag);- node_to_gptr->at(matched_node_group_conv)->isolate(isol_tag);- }-- return false; // root hasn't changed- };- register_matcher(std::make_shared<opp::Matcher>(group_conv, "TagDQGroupConv"), std::move(callback));-}-// This is a case for Raw (f16/f32) MatMul connected directly to the Result.//// The following combinations are covered:diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/compute.hpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/compute.hppindex b8be0f26bb3..08c3d34dc63 100644--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/compute.hpp+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/compute.hpp@@ -51,12 +51,6 @@ public:DQMatMulConv(const std::shared_ptr<ov::npuw::online::Snapshot>& snapshot, const std::string& isol_tag);};-class DQGroupConv : public ov::pass::MatcherPass {-public:- OPENVINO_MATCHER_PASS_RTTI("npuw::patterns::compute::DQGroupConv");- DQGroupConv(const std::shared_ptr<ov::npuw::online::Snapshot>& snapshot, const std::string& isol_tag);-};-class VocabMatMul : public ov::pass::MatcherPass {public:OPENVINO_MATCHER_PASS_RTTI("npuw::patterns::compute::VocabMatMul");