Files
openvino/docs/snippets/ov_multi.py
Anastasia Kuporosova 2bf8d910f6 [Docs][PyOV] update python snippets (#19367)
* [Docs][PyOV] update python snippets

* first snippet

* Fix samples debug

* Fix linter

* part1

* Fix speech sample

* update model state snippet

* add serialize

* add temp dir

* CPU snippets update (#134)

* snippets CPU 1/6

* snippets CPU 2/6

* snippets CPU 3/6

* snippets CPU 4/6

* snippets CPU 5/6

* snippets CPU 6/6

* make  module TODO: REMEMBER ABOUT EXPORTING PYTONPATH ON CIs ETC

* Add static model creation in snippets for CPU

* export_comp_model done

* leftovers

* apply comments

* apply comments -- properties

* small fixes

* rempve debug info

* return IENetwork instead of Function

* apply comments

* revert precision change in common snippets

* update opset

* [PyOV] Edit docs for the rest of plugins (#136)

* modify main.py

* GNA snippets

* GPU snippets

* AUTO snippets

* MULTI snippets

* HETERO snippets

* Added properties

* update gna

* more samples

* Update docs/OV_Runtime_UG/model_state_intro.md

* Update docs/OV_Runtime_UG/model_state_intro.md

* attempt1 fix ci

* new approach to test

* temporary remove some files from run

* revert cmake changes

* fix ci

* fix snippet

* fix py_exclusive snippet

* fix preprocessing snippet

* clean-up main

* remove numpy installation in gha

* check for GPU

* add logger

* iexclude main

* main update

* temp

* Temp2

* Temp2

* temp

* Revert temp

* add property execution devices

* hide output from samples

---------

Co-authored-by: p-wysocki <przemyslaw.wysocki@intel.com>
Co-authored-by: Jan Iwaszkiewicz <jan.iwaszkiewicz@intel.com>
Co-authored-by: Karol Blaszczak <karol.blaszczak@intel.com>
2023-09-13 21:05:24 +02:00

122 lines
3.4 KiB
Python

import sys
import openvino as ov
from utils import get_model
model = get_model()
def MULTI_0():
#! [MULTI_0]
core = ov.Core()
# Option 1
# Pre-configure MULTI globally with explicitly defined devices,
# and compile the model on MULTI using the newly specified default device list.
core.set_property(
device_name="MULTI", properties={ov.properties.device.priorities(): "GPU,CPU"}
)
compiled_model = core.compile_model(model=model, device_name="MULTI")
# Option 2
# Specify the devices to be used by MULTI explicitly at compilation.
# The following lines are equivalent:
compiled_model = core.compile_model(model=model, device_name="MULTI:GPU,CPU")
compiled_model = core.compile_model(
model=model,
device_name="MULTI",
config={ov.properties.device.priorities(): "GPU,CPU"},
)
#! [MULTI_0]
def MULTI_1():
#! [MULTI_1]
core = ov.Core()
core.set_property(
device_name="MULTI", properties={ov.properties.device.priorities(): "CPU,GPU"}
)
# Once the priority list is set, you can alter it on the fly:
# reverse the order of priorities
core.set_property(
device_name="MULTI", properties={ov.properties.device.priorities(): "GPU,CPU"}
)
# exclude some devices (in this case, CPU)
core.set_property(
device_name="MULTI", properties={ov.properties.device.priorities(): "GPU"}
)
# bring back the excluded devices
core.set_property(
device_name="MULTI", properties={ov.properties.device.priorities(): "GPU,CPU"}
)
# You cannot add new devices on the fly!
# Attempting to do so will trigger the following exception:
# [ ERROR ] [NOT_FOUND] You can only change device
# priorities but not add new devices with the model's
# ov::device::priorities. CPU device was not in the original device list!
#! [MULTI_1]
# the following two pieces of code appear not to be used anywhere
# they should be considered for removal
def available_devices_1():
#! [available_devices_1]
all_devices = "MULTI:"
core = ov.Core()
all_devices += ",".join(core.available_devices)
compiled_model = core.compile_model(model=model, device_name=all_devices)
#! [available_devices_1]
def available_devices_2():
#! [available_devices_2]
match_list = []
all_devices = "MULTI:"
dev_match_str = "GPU"
core = ov.Core()
for d in core.available_devices:
if dev_match_str in d:
match_list.append(d)
all_devices += ",".join(match_list)
compiled_model = core.compile_model(model=model, device_name=all_devices)
#! [available_devices_2]
def MULTI_4():
#! [MULTI_4]
core = ov.Core()
cpu_config = {}
gpu_config = {}
# When compiling the model on MULTI, configure CPU and GPU
# (devices, priorities, and device configurations; gpu_config and cpu_config will load during compile_model() ):
compiled_model = core.compile_model(
model=model,
device_name="MULTI:GPU,CPU",
config={"CPU": "NUM_STREAMS 4", "GPU": "NUM_STREAMS 8"},
)
# Optionally, query the optimal number of requests:
nireq = compiled_model.get_property(
ov.properties.optimal_number_of_infer_requests()
)
#! [MULTI_4]
def main():
core = ov.Core()
if "GPU" not in core.available_devices:
return 0
MULTI_0()
MULTI_1()
available_devices_1()
available_devices_2()
MULTI_4()