From 8890e2906ab9078d66ad6219c23d9b2a8ea63e1e Mon Sep 17 00:00:00 2001 From: Bartek Szmelczynski Date: Mon, 14 Mar 2022 19:53:09 +0100 Subject: [PATCH] [DOCS] add python snippets for automatic batching (#10918) * add python snippets for automatic branching * add missing bracket] --- docs/OV_Runtime_UG/automatic_batching.md | 2 +- docs/snippets/ov_auto_batching.py | 62 ++++++++++-------------- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/docs/OV_Runtime_UG/automatic_batching.md b/docs/OV_Runtime_UG/automatic_batching.md index c47c9260159..d21fe94b61e 100644 --- a/docs/OV_Runtime_UG/automatic_batching.md +++ b/docs/OV_Runtime_UG/automatic_batching.md @@ -77,7 +77,7 @@ For example, the application processes only 4 video streams, so there is no need .. doxygensnippet:: docs/snippets/ov_auto_batching.py :language: python - :fragment: hint_num_requests] + :fragment: [hint_num_requests] @endsphinxdirective diff --git a/docs/snippets/ov_auto_batching.py b/docs/snippets/ov_auto_batching.py index 1e943b3c8f5..2c8fa6d701c 100644 --- a/docs/snippets/ov_auto_batching.py +++ b/docs/snippets/ov_auto_batching.py @@ -1,41 +1,31 @@ -#include +from openvino.runtime import Core -int main() { - ov::Core core; - auto model = core.read_model("sample.xml"); +core = Core() +model = core.read_model(model="sample.xml") -//! [compile_model] -{ - auto compiled_model = core.compile_model(model, "GPU", ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT)); -} -//! [compile_model] +# [compile_model] +compiled_model = core.compile_model(model, "GPU", {"PERFORMANCE_HINT": "THROUGHPUT"}) +# [compile_model] -//! [compile_model_no_auto_batching] -{ - // disabling the automatic batching - // leaving intact other configurations options that the device selects for the 'throughput' hint - auto compiled_model = core.compile_model(model, "GPU", {ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT), - ov::hint::allow_auto_batching(false)}); -} -//! [compile_model_no_auto_batching] +# [compile_model_no_auto_batching] +# disabling the automatic batching +# leaving intact other configurations options that the device selects for the 'throughput' hint +config = {"PERFORMANCE_HINT": "THROUGHPUT", + "ALLOW_AUTO_BATCHING": "NO"} +compiled_model = core.compile_model(model, "GPU", config) +# [compile_model_no_auto_batching] -//! [query_optimal_num_requests] -{ - // when the batch size is automatically selected by the implementation - // it is important to query/create and run the sufficient #requests - auto compiled_model = core.compile_model(model, "GPU", ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT)); - auto num_requests = compiled_model.get_property(ov::optimal_number_of_infer_requests); -} -//! [query_optimal_num_requests] +# [query_optimal_num_requests] +# when the batch size is automatically selected by the implementation +# it is important to query/create and run the sufficient requests +compiled_model = core.compile_model(model, "GPU", {"PERFORMANCE_HINT": "THROUGHPUT"}) +num_requests = compiled_model.get_property("OPTIMAL_NUMBER_OF_INFER_REQUESTS") +# [query_optimal_num_requests] -//! [hint_num_requests] -{ - // limiting the available parallel slack for the 'throughput' hint via the ov::hint::num_requests - // so that certain parameters (like selected batch size) are automatically accommodated accordingly - auto compiled_model = core.compile_model(model, "GPU", {ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT), - ov::hint::num_requests(4)}); -} -//! [hint_num_requests] - - return 0; -} +# [hint_num_requests] +config = {"PERFORMANCE_HINT": "THROUGHPUT", + "PERFORMANCE_HINT_NUM_REQUESTS": "4"} +# limiting the available parallel slack for the 'throughput' +# so that certain parameters (like selected batch size) are automatically accommodated accordingly +compiled_model = core.compile_model(model, "GPU", config) +# [hint_num_requests]