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
Add -no_warmup option to benchmark_app (#31480)
Olena Onyshchenkod89d98158729
diff --git a/docs/articles_en/get-started/learn-openvino/openvino-samples/benchmark-tool.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples/benchmark-tool.rstindex e5299309701..5ee19ebcf01 100644--- a/docs/articles_en/get-started/learn-openvino/openvino-samples/benchmark-tool.rst+++ b/docs/articles_en/get-started/learn-openvino/openvino-samples/benchmark-tool.rst@@ -562,6 +562,8 @@ available options and parameters:-nstreams <integer> Optional. Number of streams to use for inference on the CPU or GPU devices (for HETERO and MULTI device cases use format <dev1>:<nstreams1>, <dev2>:<nstreams2> or just <nstreams>). Default value is determined automatically for a device.Please note that although the automatic selection usually provides a reasonable performance, it still may be non - optimal for some cases, especially for very small models. See sample's README for more details. Also, using nstreams>1 is inherently throughput-oriented option, while for the best-latency estimations the number of streams should be set to 1.-inference_only Optional. Measure only inference stage. Default option for static models. Dynamic models are measured in full mode which includes inputs setup stage, inference only mode available for them with single input data shape only. To enable full mode for static models pass "false" value to this argument: ex. "-inference_only=false".-infer_precision Optional. Specifies the inference precision. Example #1: '-infer_precision bf16'. Example #2: '-infer_precision CPU:bf16,GPU:f32'+ -no_warmup Optional. Skip warmup inference. Useful for benchmarking purposes in simulated environments. Otherwise, not recommended.+Preprocessing options:-ip <value> Optional. Specifies precision for all input layers of the model.diff --git a/samples/cpp/benchmark_app/benchmark_app.hpp b/samples/cpp/benchmark_app/benchmark_app.hppindex bfe84b846d5..5c0f0341417 100644--- a/samples/cpp/benchmark_app/benchmark_app.hpp+++ b/samples/cpp/benchmark_app/benchmark_app.hpp@@ -249,6 +249,10 @@ static const char load_config_message[] =" }\n"" }";+static const char no_warmup_message[] =+ "Optional. Skip warmup inference. Useful for benchmarking purposes in simulated environments.\n"+ "Otherwise, not recommended.";+/// @brief Define flag for showing help message <br>DEFINE_bool(h, false, help_message);@@ -380,6 +384,9 @@ DEFINE_string(load_config, "", load_config_message);/// @brief Define flag for dumping configuration file <br>DEFINE_string(dump_config, "", dump_config_message);+/// @brief Skips warmup inference and measures only the first inference+DEFINE_bool(no_warmup, false, no_warmup_message);+/*** @brief This function show a help message*/@@ -413,6 +420,7 @@ static void show_usage() {std::cout << " -nstreams <integer> " << infer_num_streams_message << std::endl;std::cout << " -inference_only " << inference_only_message << std::endl;std::cout << " -infer_precision " << inference_precision_message << std::endl;+ std::cout << " -no_warmup " << no_warmup_message << std::endl;std::cout << std::endl;std::cout << "Preprocessing options:" << std::endl;std::cout << " -ip <value> " << inputs_precision_message << std::endl;diff --git a/samples/cpp/benchmark_app/main.cpp b/samples/cpp/benchmark_app/main.cppindex 0caec2d93fc..3ae50e13d74 100644--- a/samples/cpp/benchmark_app/main.cpp+++ b/samples/cpp/benchmark_app/main.cpp@@ -1175,47 +1175,53 @@ int main(int argc, char* argv[]) {}}- // warming up - out of scope- auto inferRequest = inferRequestsQueue.get_idle_request();- if (!inferRequest) {- OPENVINO_THROW("No idle Infer Requests!");- }-- if (!inferenceOnly) {- auto inputs = app_inputs_info[0];+ std::shared_ptr<InferReqWrap> inferRequest;- for (auto& item : inputs) {- auto inputName = item.first;- const auto& data = inputsData.at(inputName)[0];- inferRequest->set_tensor(inputName, data);+ // conditional warmup based on FLAGS_no_warmup+ if (!FLAGS_no_warmup) {+ // warming up - out of scope+ inferRequest = inferRequestsQueue.get_idle_request();+ if (!inferRequest) {+ OPENVINO_THROW("No idle Infer Requests!");}+ if (!inferenceOnly) {+ auto inputs = app_inputs_info[0];- if (useGpuMem) {- auto outputTensors =- ::gpu::get_remote_output_tensors(compiledModel, inferRequest->get_output_cl_buffer());- for (auto& output : compiledModel.outputs()) {- inferRequest->set_tensor(output.get_any_name(), outputTensors[output.get_any_name()]);+ for (auto& item : inputs) {+ auto inputName = item.first;+ const auto& data = inputsData.at(inputName)[0];+ inferRequest->set_tensor(inputName, data);+ }++ if (useGpuMem) {+ auto outputTensors =+ ::gpu::get_remote_output_tensors(compiledModel, inferRequest->get_output_cl_buffer());+ for (auto& output : compiledModel.outputs()) {+ inferRequest->set_tensor(output.get_any_name(), outputTensors[output.get_any_name()]);+ }}}- }- if (FLAGS_api == "sync") {- inferRequest->infer();- } else {- inferRequest->start_async();- }+ if (FLAGS_api == "sync") {+ inferRequest->infer();+ } else {+ inferRequest->start_async();+ }- inferRequestsQueue.wait_all();+ inferRequestsQueue.wait_all();- auto duration_ms = inferRequestsQueue.get_latencies()[0];- slog::info << "First inference took " << double_to_string(duration_ms) << " ms" << slog::endl;+ auto duration_ms = inferRequestsQueue.get_latencies()[0];+ slog::info << "First inference took " << double_to_string(duration_ms) << " ms" << slog::endl;- if (statistics) {- statistics->add_parameters(- StatisticsReport::Category::EXECUTION_RESULTS,- {StatisticsVariant("first inference time (ms)", "first_inference_time", duration_ms)});+ if (statistics) {+ statistics->add_parameters(+ StatisticsReport::Category::EXECUTION_RESULTS,+ {StatisticsVariant("first inference time (ms)", "first_inference_time", duration_ms)});+ }+ inferRequestsQueue.reset_times();+ } else {+ slog::info << "Skipping warmup inference due to -no_warmup flag" << slog::endl;}- inferRequestsQueue.reset_times();size_t processedFramesN = 0;auto startTime = Time::now();diff --git a/tests/samples_tests/smoke_tests/test_benchmark_app.py b/tests/samples_tests/smoke_tests/test_benchmark_app.pyindex 4699d6276d0..828aa312b3f 100755--- a/tests/samples_tests/smoke_tests/test_benchmark_app.py+++ b/tests/samples_tests/smoke_tests/test_benchmark_app.py@@ -223,3 +223,64 @@ def test_input_output_tensor_name_collision(sample_language, device, in_node_nam).uniform(0, 256, data_shape).astype(np.int32))verify(sample_language, device, iop=iop, model=model, inp=inp, cache=cache, tmp_path=tmp_path, batch=None, tm='1')+[email protected]('sample_language', ['C++', 'Python'])[email protected]('device', get_devices())+def test_benchmark_app_no_warmup_flag(sample_language, device, cache, tmp_path):+ """Test that -no_warmup flag skips warmup inference and produces correct output"""++ # test with warmup (default behavior)+ output_with_warmup = get_cmd_output(+ get_executable(sample_language),+ *prepend(cache, 'dog-224x224.bmp', 'bvlcalexnet-12.onnx', tmp_path),+ '-d', device,+ '-niter', '1',+ '-nireq', '1'+ )++ # verify default behavior shows warmup message+ assert 'FPS' in output_with_warmup+ assert 'First inference took' in output_with_warmup++ # test without warmup+ output_no_warmup = get_cmd_output(+ get_executable(sample_language),+ *prepend(cache, 'dog-224x224.bmp', 'bvlcalexnet-12.onnx', tmp_path),+ '-d', device,+ '-niter', '1',+ '-nireq', '1',+ '-no_warmup'+ )++ # verify -no_warmup behavior+ assert 'FPS' in output_no_warmup+ assert 'Skipping warmup inference due to -no_warmup flag' in output_no_warmup+ assert 'First inference took' not in output_no_warmup++[email protected]('sample_language', ['C++', 'Python'])+def test_benchmark_app_no_warmup_help(sample_language):+ """Test that -no_warmup option appears in help output"""+ output = get_cmd_output(get_executable(sample_language), '-h')+ assert '-no_warmup' in output+ assert 'Skip warmup inference' in output++[email protected]('sample_language', ['C++', 'Python'])[email protected]('device', get_devices())[email protected]('api', ['sync', 'async'])+def test_benchmark_app_no_warmup_with_api_modes(sample_language, device, api, cache, tmp_path):+ """Test -no_warmup flag works with different API modes"""+ output = get_cmd_output(+ get_executable(sample_language),+ *prepend(cache, 'dog-224x224.bmp', 'bvlcalexnet-12.onnx', tmp_path),+ '-d', device,+ '-niter', '1',+ '-nireq', '1',+ '-api', api,+ '-no_warmup'+ )++ assert 'FPS' in output+ assert 'Skipping warmup inference due to -no_warmup flag' in output+ assert 'First inference took' not in outputdiff --git a/tools/benchmark_tool/openvino/tools/benchmark/main.py b/tools/benchmark_tool/openvino/tools/benchmark/main.pyindex 0e625d26b82..c81c943e2d0 100755--- a/tools/benchmark_tool/openvino/tools/benchmark/main.py+++ b/tools/benchmark_tool/openvino/tools/benchmark/main.py@@ -603,13 +603,17 @@ def main():logger.info("Benchmarking in inference only mode (inputs filling are not included in measurement loop).")else:logger.info("Benchmarking in full mode (inputs filling are included in measurement loop).")- duration_ms = f"{benchmark.first_infer(requests):.2f}"- logger.info(f"First inference took {duration_ms} ms")- if statistics:- statistics.add_parameters(StatisticsReport.Category.EXECUTION_RESULTS,- [- ('first inference time (ms)', duration_ms)- ])+ if not args.no_warmup:+ duration_ms = f"{benchmark.first_infer(requests):.2f}"+ logger.info(f"First inference took {duration_ms} ms")+ if statistics:+ statistics.add_parameters(StatisticsReport.Category.EXECUTION_RESULTS,+ [+ ('first inference time (ms)', duration_ms)+ ])+ else:+ logger.info("Skipping warmup inference due to -no_warmup flag")+pcseq = args.pcseqif static_mode or len(benchmark.latency_groups) == 1:diff --git a/tools/benchmark_tool/openvino/tools/benchmark/parameters.py b/tools/benchmark_tool/openvino/tools/benchmark/parameters.pyindex 146e3516812..9a5050d1f7f 100644--- a/tools/benchmark_tool/openvino/tools/benchmark/parameters.py+++ b/tools/benchmark_tool/openvino/tools/benchmark/parameters.py@@ -125,9 +125,10 @@ def parse_args():advs.add_argument('-inference_only', '--inference_only', type=str2bool, required=False, default=None, nargs='?', const=True,help='Optional. If true inputs filling only once before measurements (default for static models), ''else inputs filling is included into loop measurement (default for dynamic models)', )+ advs.add_argument('-no_warmup', action='store_true', required=False, default=False,+ help='Optional. Skip warmup inference. Useful for benchmarking purposes in simulated environments. Otherwise, not recommended.')advs.add_argument('-infer_precision', type=str, required=False,help='Optional. Specifies the inference precision. Example #1: \'-infer_precision bf16\'. Example #2: \'-infer_precision CPU:bf16,GPU:f32\'')-prpr = parser.add_argument_group('Preprocessing options')prpr.add_argument('-ip', '--input_precision', type=str, required=False, choices=INPUT_OUTPUT_PRECISION_CHOICES,help='Optional. Specifies precision for all input layers of the model.')