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
NPUW: Fix cases when FOLDing is not enabled (#28255)
Dmitry Matveevdd6a128c6681
diff --git a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cppindex aa02ca8681e..de9588d01f3 100644--- a/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp@@ -86,6 +86,42 @@ ov::npuw::DeviceProperties get_properties_per_device(const std::shared_ptr<const} // namespace npuw} // namespace ov+namespace {+template <typename T>+auto cfg_get(const ov::AnyMap& properties) -> typename T::ValueType {+ const auto& opt_name = std::string(T::key());+ if (properties.count(opt_name)) {+ return properties.at(opt_name).as<typename T::ValueType>();+ }+ return T::defaultValue();+}++void pre_load_transform(const std::shared_ptr<ov::Model>& model, const ov::AnyMap& props) {+ ov::pass::ConvertPrecision(ov::element::bf16, ov::element::f16).run_on_model(model);++ if (cfg_get<::intel_npu::NPUW_FOLD>(props) && cfg_get<::intel_npu::NPUW_FUNCALL_FOR_ALL>(props)) {+ // If there's folding enabled AND non-repeating graphs are forced to be+ // functions, do extra lifting for gather (if any)+ ov::pass::GraphRewrite rewr;+ rewr.add_matcher<ov::npuw::patterns::opt::DQLiftGatherAsymCW>();+ rewr.add_matcher<ov::npuw::patterns::opt::DQLiftGatherSymCW>();+ rewr.add_matcher<ov::npuw::patterns::opt::DQLiftGatherSymGQ>();+ rewr.run_on_model(model);+ }++ if (cfg_get<::intel_npu::NPUW_SLICE_OUT>(props)) {+ // Add Slice before last MatMul for the prefill model+ ov::pass::GraphRewrite rewr;+ rewr.add_matcher<ov::npuw::patterns::opt::SliceLastMatmul>();+ rewr.add_matcher<ov::npuw::patterns::opt::SliceLastMatmulAdd>();+ rewr.add_matcher<ov::npuw::patterns::opt::SliceLastMatmulTranspose>();+ rewr.add_matcher<ov::npuw::patterns::opt::SliceLastMatmulMultiply>();+ rewr.run_on_model(model);+ }+ model->validate_nodes_and_infer_types();+}+} // anonymous namespace+std::shared_ptr<ov::npuw::ICompiledModel> ov::npuw::ICompiledModel::create(const std::shared_ptr<ov::Model>& model,const std::shared_ptr<const ov::IPlugin>& plugin,@@ -99,6 +135,7 @@ std::shared_ptr<ov::npuw::ICompiledModel> ov::npuw::ICompiledModel::create(compiled_model = std::make_shared<ov::npuw::LLMCompiledModel>(model, plugin, properties);} else {LOG_INFO("ov::npuw::CompiledModel will be created.");+ pre_load_transform(model, properties);compiled_model = std::make_shared<ov::npuw::CompiledModel>(model, plugin, properties);}LOG_INFO("Done");@@ -159,29 +196,6 @@ ov::npuw::CompiledModel::CompiledModel(const std::shared_ptr<ov::Model>& model,}}- // FIXME: Find a better place to call this transformation- ov::pass::ConvertPrecision(ov::element::bf16, ov::element::f16).run_on_model(model);-- if (m_cfg.get<::intel_npu::NPUW_FOLD>() && m_cfg.get<::intel_npu::NPUW_FUNCALL_FOR_ALL>()) {- // If there's folding enabled AND non-repeating graphs are forced to be- // functions, do extra lifting for gather (if any)- ov::pass::GraphRewrite rewr;- rewr.add_matcher<ov::npuw::patterns::opt::DQLiftGatherAsymCW>();- rewr.add_matcher<ov::npuw::patterns::opt::DQLiftGatherSymCW>();- rewr.add_matcher<ov::npuw::patterns::opt::DQLiftGatherSymGQ>();- rewr.run_on_model(model);- }-- if (m_cfg.get<::intel_npu::NPUW_SLICE_OUT>()) {- // Add Slice before last MatMul for the prefill model- ov::pass::GraphRewrite rewr;- rewr.add_matcher<ov::npuw::patterns::opt::SliceLastMatmul>();- rewr.add_matcher<ov::npuw::patterns::opt::SliceLastMatmulAdd>();- rewr.add_matcher<ov::npuw::patterns::opt::SliceLastMatmulTranspose>();- rewr.add_matcher<ov::npuw::patterns::opt::SliceLastMatmulMultiply>();- rewr.run_on_model(model);- }-auto partitioning = getPartitioning(model, m_cfg);m_total_stat.gflops = partitioning.total_gflops;m_total_stat.ops = partitioning.total_ops;diff --git a/src/plugins/intel_npu/src/plugin/npuw/unfold_sync_infer_request.cpp b/src/plugins/intel_npu/src/plugin/npuw/unfold_sync_infer_request.cppindex 90eb62dcc0a..5b82ff7c827 100644--- a/src/plugins/intel_npu/src/plugin/npuw/unfold_sync_infer_request.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/unfold_sync_infer_request.cpp@@ -73,7 +73,9 @@ ov::npuw::UnfoldInferRequest::UnfoldInferRequest(const std::shared_ptr<ov::npuw:if (!comp_model_desc.compiled_model && !comp_model_desc.replaced_by) {continue; // Optimized out}- unpack_closure(i, m_subrequests[i]);+ if (comp_model_desc.replaced_by) {+ unpack_closure(i, m_subrequests[i]);+ }LOG_VERB("Done");}}