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
[intel-npu] Adding private NPU_BATCH_COMPILER_MODE_SETTINGS property (#29152)
Sergey Ivanov4c10f506cc7e
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/config/compiler.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/config/compiler.hppindex 128973e2e2c..56326b78969 100644--- a/src/plugins/intel_npu/src/al/include/intel_npu/config/compiler.hpp+++ b/src/plugins/intel_npu/src/al/include/intel_npu/config/compiler.hpp@@ -401,4 +401,25 @@ struct QDQ_OPTIMIZATION final : OptionBase<QDQ_OPTIMIZATION, bool> {}};+//+// BATCH_COMPILER_MODE_SETTINGS+//++struct BATCH_COMPILER_MODE_SETTINGS final : OptionBase<BATCH_COMPILER_MODE_SETTINGS, std::string> {+ static std::string_view key() {+ return ov::intel_npu::batch_compiler_mode_settings.name();+ }++ static std::string defaultValue() {+ return {};+ }++ static OptionMode mode() {+ return OptionMode::CompileTime;+ }++ static bool isPublic() {+ return false;+ }+};} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hppindex b396dd832cb..878042925ca 100644--- a/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp+++ b/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp@@ -298,6 +298,40 @@ static constexpr ov::Property<ProfilingType> profiling_type{"NPU_PROFILING_TYPE"*/static constexpr ov::Property<BatchMode> batch_mode{"NPU_BATCH_MODE"};+/**+ * @brief [Only for NPU Plugin]+ * Type: String. Default is "".+ * This option is added for providing a fine-grained batched model compilation control, otherwise batching compilation+ * params will be determined automatically. Should be specified only when a model compilation is failed due to incorrect+ * detection of batch dimension presence including false-positive and false-negative cases. NPU compiler supports two+ * batch compile options by now: "unroll" and "debatch" - either can be activated using by setting+ * "batch-compile-method" into the desired value. Leveragind the compile method "debatch" allows the additional param+ * "debatcher-settings" being configured, which introduces the declared fine-grained compilation control suboptions. The+ * suboption "debatcher-input-coefficients-partitions" determines how to split or debatch input tensors of an original+ * model.+ *+ * Let's look at the following example:+ * "batch-compile-method=debatch debatcher-settings={debatcher-input-coefficients-partitions=[0-1],[13-4],[1-1]}".+ *+ * These mean that we want to "debatch" inputs of a batched network providing that:+ * - a batch dimension N of a first intput is on the 0-position (of its layout abbreviation);+ * - the N dimension of a second input is on 13th-position of its layout;+ * - and the N dimension of a third input is on 1-position of its layout accordingly.+ * Thus the first digit of a pair of values enclosed by symbols'[' and ']' determines N dimension position in a layout+ * of a corresponding input. A second value of the pair represents a "native" value of N-dimension of a tensor in+ * assumption that having this value, the tensor becomes "non-batched" or a plain tensor. In the example above:+ * - the non-batched tensor of the first input is assumed to have 1 in N-dimension (on the 0 position);+ * - the second tensor assumed non-batched when it got 4 as a valua of N-dimension on the 13th-position+ * - the third tensor is a plain tensor when it has 1 in N-dimension on the 1-position of its layout+ *+ * The given "debatcher-input-coefficients-partitions" provides the NPU compiler with sufficient information in order to+ * compile a complicatied batched model, which might not be auto recognized by intrinsic heuristics+ *+ * Possible values: "", "batch-compile-method=unroll batch-unroll-settings={skip-unroll-batch=false}",+ * "batch-compile-method=debatch debatcher-settings={debatcher-input-coefficients-partitions=[0-1],[0-1],[0-1]}".+ */+static constexpr ov::Property<std::string> batch_compiler_mode_settings{"NPU_BATCH_COMPILER_MODE_SETTINGS"};+/*** @brief [Only for NPU Plugin]* Type: integer, default is 1diff --git a/src/plugins/intel_npu/src/al/src/config/compiler.cpp b/src/plugins/intel_npu/src/al/src/config/compiler.cppindex f7d767781d0..1f55d752bbf 100644--- a/src/plugins/intel_npu/src/al/src/config/compiler.cpp+++ b/src/plugins/intel_npu/src/al/src/config/compiler.cpp@@ -26,6 +26,7 @@ void intel_npu::registerCompilerOptions(OptionsDesc& desc) {desc.add<EXECUTION_MODE_HINT>();desc.add<COMPILER_DYNAMIC_QUANTIZATION>();desc.add<QDQ_OPTIMIZATION>();+ desc.add<BATCH_COMPILER_MODE_SETTINGS>();}//diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cppindex ccd8c330488..045e1adc5a2 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp@@ -562,6 +562,16 @@ std::string DriverCompilerAdapter::serializeConfig(const Config& config,content = std::regex_replace(content, std::regex(qdqstr.str()), "");}+ // BATCH_COMPILER_MODE_SETTINGS is not supported in versions < 7.4 - need to remove it+ if ((compilerVersion.major < 7) || (compilerVersion.major == 7 && compilerVersion.minor < 4)) {+ std::ostringstream dqstr;+ dqstr << ov::intel_npu::batch_compiler_mode_settings.name() << KEY_VALUE_SEPARATOR << VALUE_DELIMITER << "\\S+"+ << VALUE_DELIMITER;+ logger.warning("BATCH_COMPILER_MODE_SETTINGS property is not supported by this compiler version. Removing from "+ "parameters");+ content = std::regex_replace(content, std::regex(dqstr.str()), "");+ }+// NPU_DEFER_WEIGHTS_LOAD is needed at runtime only{std::ostringstream batchstr;diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cppindex 5bcb091a309..340209c9061 100644--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp@@ -577,9 +577,16 @@ Plugin::Plugin()[](const Config& config) {return config.getString<BATCH_MODE>();}}},- {ov::intel_npu::disable_version_check.name(), {false, ov::PropertyMutability::RW, [](const Config& config) {- return config.getString<DISABLE_VERSION_CHECK>();- }}}};+ {ov::intel_npu::disable_version_check.name(),+ {false,+ ov::PropertyMutability::RW,+ [](const Config& config) {+ return config.getString<DISABLE_VERSION_CHECK>();+ }}},+ {ov::intel_npu::batch_compiler_mode_settings.name(),+ {false, ov::PropertyMutability::RW, [](const Config& config) {+ return config.get<BATCH_COMPILER_MODE_SETTINGS>();+ }}}};}void Plugin::reset_supported_properties() const {@@ -615,6 +622,7 @@ void Plugin::reset_compiler_dependent_properties() const {std::get<0>(_properties[ov::intel_npu::compiler_dynamic_quantization.name()]) = false; // mark unsupported}}+// NPU_QDQ_OPTIMIZATION// unpublish if compiler version requirement is not metif (_properties.find(ov::intel_npu::qdq_optimization.name()) != _properties.end()) {