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
Added I4/U4 precision parsers for compile_tool (#29460)
AndreiFilip00ed0fe8ee6c
diff --git a/samples/cpp/common/utils/src/args_helper.cpp b/samples/cpp/common/utils/src/args_helper.cppindex 21d935667de..2e36cce087f 100644--- a/samples/cpp/common/utils/src/args_helper.cpp+++ b/samples/cpp/common/utils/src/args_helper.cpp@@ -156,14 +156,16 @@ ov::element::Type getType(std::string value, const supported_type_t& supported_p}ov::element::Type getType(const std::string& value) {static const supported_type_t supported_types = {- {"FP32", ov::element::f32}, {"f32", ov::element::f32}, {"FP16", ov::element::f16},- {"f16", ov::element::f16}, {"BF16", ov::element::bf16}, {"bf16", ov::element::bf16},- {"U64", ov::element::u64}, {"u64", ov::element::u64}, {"I64", ov::element::i64},- {"i64", ov::element::i64}, {"U32", ov::element::u32}, {"u32", ov::element::u32},- {"I32", ov::element::i32}, {"i32", ov::element::i32}, {"U16", ov::element::u16},- {"u16", ov::element::u16}, {"I16", ov::element::i16}, {"i16", ov::element::i16},- {"U8", ov::element::u8}, {"u8", ov::element::u8}, {"I8", ov::element::i8},- {"i8", ov::element::i8}, {"BOOL", ov::element::boolean}, {"boolean", ov::element::boolean},+ {"FP32", ov::element::f32}, {"f32", ov::element::f32}, {"FP16", ov::element::f16},+ {"f16", ov::element::f16}, {"BF16", ov::element::bf16}, {"bf16", ov::element::bf16},+ {"U64", ov::element::u64}, {"u64", ov::element::u64}, {"I64", ov::element::i64},+ {"i64", ov::element::i64}, {"U32", ov::element::u32}, {"u32", ov::element::u32},+ {"I32", ov::element::i32}, {"i32", ov::element::i32}, {"U16", ov::element::u16},+ {"u16", ov::element::u16}, {"I16", ov::element::i16}, {"i16", ov::element::i16},+ {"U8", ov::element::u8}, {"u8", ov::element::u8}, {"I8", ov::element::i8},+ {"i8", ov::element::i8}, {"U4", ov::element::u4}, {"u4", ov::element::u4},+ {"I4", ov::element::i4}, {"i4", ov::element::i4}, {"BOOL", ov::element::boolean},+ {"boolean", ov::element::boolean},};return getType(value, supported_types);@@ -358,6 +360,8 @@ ov::element::Type getPrecision2(const std::string& value) {{"I16", ov::element::i16},{"U8", ov::element::u8},{"I8", ov::element::i8},+ {"U4", ov::element::u4},+ {"I4", ov::element::i4},{"BOOL", ov::element::boolean},};diff --git a/src/plugins/intel_npu/tools/compile_tool/main.cpp b/src/plugins/intel_npu/tools/compile_tool/main.cppindex 36554c0dbe8..191b3b96cd9 100644--- a/src/plugins/intel_npu/tools/compile_tool/main.cpp+++ b/src/plugins/intel_npu/tools/compile_tool/main.cpp@@ -2,36 +2,34 @@// SPDX-License-Identifier: Apache-2.0//+#include <gflags/gflags.h>+#include <algorithm>#include <chrono>#include <cstdlib>#include <fstream>#include <iostream>#include <map>+#include <openvino/core/partial_shape.hpp>+#include <openvino/openvino.hpp>#include <string>#include <unordered_map>#include <vector>-#include <gflags/gflags.h>--#include <openvino/core/partial_shape.hpp>-#include <openvino/openvino.hpp>-#include "tools_helpers.hpp"-static constexpr char help_message[] = "Optional. Print the usage message.";static constexpr char model_message[] = "Required. Path to the XML model.";static constexpr char targetDeviceMessage[] =- "Required. Specify a target device for which executable network will be compiled.\n"- " Use \"-d HETERO:<comma-separated_devices_list>\" format to "- "specify HETERO plugin.\n"- " Use \"-d MULTI:<comma-separated_devices_list>\" format to "- "specify MULTI plugin.\n"- " The application looks for a suitable plugin for the specified "- "device.";+ "Required. Specify a target device for which executable network will be compiled.\n"+ " Use \"-d HETERO:<comma-separated_devices_list>\" format to "+ "specify HETERO plugin.\n"+ " Use \"-d MULTI:<comma-separated_devices_list>\" format to "+ "specify MULTI plugin.\n"+ " The application looks for a suitable plugin for the specified "+ "device.";static constexpr char output_message[] = "Optional. Path to the output file. Default value: \"<model_xml_file>.blob\".";@@ -44,42 +42,42 @@ static constexpr char perf_count_message[] = "Optional. Set PERF_COUNT config prstatic constexpr char inputs_precision_message[] = "Optional. Specifies precision for all input layers of the network.";static constexpr char outputs_precision_message[] =- "Optional. Specifies precision for all output layers of the network.";+ "Optional. Specifies precision for all output layers of the network.";static constexpr char iop_message[] =- "Optional. Specifies precision for input and output layers by name.\n"- " Example: -iop \"input:FP16, output:FP16\".\n"- " Notice that quotes are required.\n"- " Overwrites precision from ip and op options for specified "- "layers.";+ "Optional. Specifies precision for input and output layers by name.\n"+ " Example: -iop \"input:FP16, output:FP16\".\n"+ " Notice that quotes are required.\n"+ " Overwrites precision from ip and op options for specified "+ "layers.";static constexpr char inputs_layout_message[] = "Optional. Specifies layout for all input layers of the network.";static constexpr char outputs_layout_message[] = "Optional. Specifies layout for all output layers of the network.";static constexpr char iol_message[] =- "Optional. Specifies layout for input and output layers by name.\n"- " Example: -iol \"input:NCHW, output:NHWC\".\n"- " Notice that quotes are required.\n"- " Overwrites layout from il and ol options for specified layers.";+ "Optional. Specifies layout for input and output layers by name.\n"+ " Example: -iol \"input:NCHW, output:NHWC\".\n"+ " Notice that quotes are required.\n"+ " Overwrites layout from il and ol options for specified layers.";static constexpr char inputs_model_layout_message[] =- "Optional. Specifies model layout for all input layers of the network.";+ "Optional. Specifies model layout for all input layers of the network.";static constexpr char outputs_model_layout_message[] =- "Optional. Specifies model layout for all output layers of the network.";+ "Optional. Specifies model layout for all output layers of the network.";static constexpr char ioml_message[] =- "Optional. Specifies model layout for input and output tensors by name.\n"- " Example: -ioml \"input:NCHW, output:NHWC\".\n"- " Notice that quotes are required.\n"- " Overwrites layout from il and ol options for specified layers.";+ "Optional. Specifies model layout for input and output tensors by name.\n"+ " Example: -ioml \"input:NCHW, output:NHWC\".\n"+ " Notice that quotes are required.\n"+ " Overwrites layout from il and ol options for specified layers.";static const char shape_message[] =- " Set shape for model input. For example, \"input1[1,3,224,224],input2[1,4]\" or \"[1,3,224,224]\""- " in case of one input size. This parameter affect model input shape and can be dynamic."- " For dynamic dimensions use symbol `?` or '-1'. Ex. [?,3,?,?]."- " For bounded dimensions specify range 'min..max'. Ex. [1..10,3,?,?].";+ " Set shape for model input. For example, \"input1[1,3,224,224],input2[1,4]\" or \"[1,3,224,224]\""+ " in case of one input size. This parameter affect model input shape and can be dynamic."+ " For dynamic dimensions use symbol `?` or '-1'. Ex. [?,3,?,?]."+ " For bounded dimensions specify range 'min..max'. Ex. [1..10,3,?,?].";static constexpr char override_model_batch_size_message[] = "Enforce a model to be compiled for batch size";@@ -155,14 +153,16 @@ ov::element::Type getType(std::string value, const supported_type_t& supported_p}ov::element::Type getType(const std::string& value) {static const supported_type_t supported_types = {- {"FP32", ov::element::f32}, {"f32", ov::element::f32}, {"FP16", ov::element::f16},- {"f16", ov::element::f16}, {"BF16", ov::element::bf16}, {"bf16", ov::element::bf16},- {"U64", ov::element::u64}, {"u64", ov::element::u64}, {"I64", ov::element::i64},- {"i64", ov::element::i64}, {"U32", ov::element::u32}, {"u32", ov::element::u32},- {"I32", ov::element::i32}, {"i32", ov::element::i32}, {"U16", ov::element::u16},- {"u16", ov::element::u16}, {"I16", ov::element::i16}, {"i16", ov::element::i16},- {"U8", ov::element::u8}, {"u8", ov::element::u8}, {"I8", ov::element::i8},- {"i8", ov::element::i8}, {"BOOL", ov::element::boolean}, {"boolean", ov::element::boolean},+ {"FP32", ov::element::f32}, {"f32", ov::element::f32}, {"FP16", ov::element::f16},+ {"f16", ov::element::f16}, {"BF16", ov::element::bf16}, {"bf16", ov::element::bf16},+ {"U64", ov::element::u64}, {"u64", ov::element::u64}, {"I64", ov::element::i64},+ {"i64", ov::element::i64}, {"U32", ov::element::u32}, {"u32", ov::element::u32},+ {"I32", ov::element::i32}, {"i32", ov::element::i32}, {"U16", ov::element::u16},+ {"u16", ov::element::u16}, {"I16", ov::element::i16}, {"i16", ov::element::i16},+ {"U8", ov::element::u8}, {"u8", ov::element::u8}, {"I8", ov::element::i8},+ {"i8", ov::element::i8}, {"U4", ov::element::u4}, {"u4", ov::element::u4},+ {"I4", ov::element::i4}, {"i4", ov::element::i4}, {"BOOL", ov::element::boolean},+ {"boolean", ov::element::boolean},};return getType(value, supported_types);@@ -172,9 +172,15 @@ bool isFP32(const ov::element::Type& type) {return type == ov::element::f32;}-void configurePrePostProcessing(std::shared_ptr<ov::Model>& model, const std::string& ip, const std::string& op,- const std::string& iop, const std::string& il, const std::string& ol,- const std::string& iol, const std::string& iml, const std::string& oml,+void configurePrePostProcessing(std::shared_ptr<ov::Model>& model,+ const std::string& ip,+ const std::string& op,+ const std::string& iop,+ const std::string& il,+ const std::string& ol,+ const std::string& iol,+ const std::string& iml,+ const std::string& oml,const std::string& ioml) {auto preprocessor = ov::preprocess::PrePostProcessor(model);const auto inputs = model->inputs();@@ -370,17 +376,19 @@ static std::map<std::string, std::string> parseConfigFile(char comment = '#') {continue;}size_t spacePos = option.find_first_of(" \t\n\r");- OPENVINO_ASSERT(spacePos != std::string::npos, "Failed to find a space separator in "- "provided plugin config option: " +- option);+ OPENVINO_ASSERT(spacePos != std::string::npos,+ "Failed to find a space separator in "+ "provided plugin config option: " ++ option);std::string key = option.substr(0, spacePos);std::string value{};size_t valueStart = option.find_first_not_of(" \t\n\r", spacePos);- OPENVINO_ASSERT(valueStart != std::string::npos, "An invalid config parameter value detected, "- "it mustn't be empty: " +- option);+ OPENVINO_ASSERT(valueStart != std::string::npos,+ "An invalid config parameter value detected, "+ "it mustn't be empty: " ++ option);size_t valueEnd = option.find_last_not_of(" \t\n\r");value = option.substr(valueStart, valueEnd - valueStart + 1);@@ -406,7 +414,6 @@ std::string getFileNameFromPath(const std::string& path,using TimeDiff = std::chrono::milliseconds;-int main(int argc, char* argv[]) {try {TimeDiff loadNetworkTimeElapsed{0};@@ -442,8 +449,16 @@ int main(int argc, char* argv[]) {reshape(std::move(inputs_info), info_map, model, FLAGS_shape, FLAGS_override_model_batch_size, FLAGS_d);std::cout << "Configuring model pre & post processing" << std::endl;- configurePrePostProcessing(model, FLAGS_ip, FLAGS_op, FLAGS_iop, FLAGS_il, FLAGS_ol, FLAGS_iol, FLAGS_iml,- FLAGS_oml, FLAGS_ioml);+ configurePrePostProcessing(model,+ FLAGS_ip,+ FLAGS_op,+ FLAGS_iop,+ FLAGS_il,+ FLAGS_ol,+ FLAGS_iol,+ FLAGS_iml,+ FLAGS_oml,+ FLAGS_ioml);if (FLAGS_shape.empty()) {setModelBatch(model, FLAGS_override_model_batch_size);}@@ -459,7 +474,7 @@ int main(int argc, char* argv[]) {std::cout << "Compiling model" << std::endl;auto compiledModel = core.compile_model(model, FLAGS_d, {configs.begin(), configs.end()});loadNetworkTimeElapsed =- std::chrono::duration_cast<TimeDiff>(std::chrono::steady_clock::now() - timeBeforeLoadNetwork);+ std::chrono::duration_cast<TimeDiff>(std::chrono::steady_clock::now() - timeBeforeLoadNetwork);std::string outputName = FLAGS_o;if (outputName.empty()) {outputName = getFileNameFromPath(fileNameNoExt(FLAGS_m)) + ".blob";