Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/snippets/gna/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
17 changes: 10 additions & 7 deletions docs/snippets/gna/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
# SPDX-License-Identifier: Apache-2.0

#! [import]
from openvino.runtime import Core
import openvino as ov
#! [import]

model_path = "model.xml"
from snippets import get_model

model = get_model()

# TODO: no GNA properties to replace strings
#! [ov_gna_exec_mode_hw_with_sw_fback]
core = ov.Core()
compiled_model = core.compile_model(
model, device_name="GNA", config={"GNA_DEVICE_MODE": "GNA_HW_WITH_SW_FBACK"}
)
#! [ov_gna_exec_mode_hw_with_sw_fback]
core = Core()
model = core.read_model(model=model_path)
compiled_model = core.compile_model(model, device_name="GNA",
config={ 'GNA_DEVICE_MODE' : 'GNA_HW_WITH_SW_FBACK'})
#! [ov_gna_exec_mode_hw_with_sw_fback]
15 changes: 8 additions & 7 deletions docs/snippets/gna/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
# SPDX-License-Identifier: Apache-2.0

#! [import]
from openvino.runtime import Core
import openvino as ov
from io import BytesIO
#! [import]

model_path = "model.xml"
from snippets import get_model

model = get_model()
blob_path = "compiled_model.blob"
akuporos marked this conversation as resolved.
Show resolved Hide resolved

core = Core()
model = core.read_model(model=model_path)
core = ov.Core()
compiled_model = core.compile_model(model, device_name="GNA")

#! [ov_gna_export]
user_stream = compiled_model.export_model()
with open(blob_path, 'wb') as f:
with open(blob_path, "wb") as f:
f.write(user_stream)
#! [ov_gna_export]

# [ov_gna_import]
with open(blob_path, 'rb') as f:
with open(blob_path, "rb") as f:
buf = BytesIO(f.read())
compiled_model = core.import_model(buf, device_name="GNA")
# [ov_gna_import]
# [ov_gna_import]
18 changes: 10 additions & 8 deletions docs/snippets/gna/set_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@
# SPDX-License-Identifier: Apache-2.0

#! [import]
from openvino.runtime import Core, set_batch
from openvino.preprocess import PrePostProcessor
import openvino as ov
#! [import]

model_path = "model.xml"
batch_size = 8

# TODO: model is only available as function from snippets
#! [ov_gna_read_model]
core = Core()
model = core.read_model(model=model_path)
core = ov.Core()

from snippets import get_model

model = get_model(input_shape=[1, 32])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this line be moved out of code snippet?

#! [ov_gna_read_model]

#! [ov_gna_set_nc_layout]
ppp = PrePostProcessor(model)
ppp = ov.preprocess.PrePostProcessor(model)
for i in range(len(model.inputs)):
input_name = model.input(i).get_any_name()
ppp.input(i).model().set_layout("N?")
model = ppp.build()
#! [ov_gna_set_nc_layout]

#! [ov_gna_set_batch_size]
set_batch(model, batch_size)
#! [ov_gna_set_batch_size]
ov.set_batch(model, batch_size)
#! [ov_gna_set_batch_size]
2 changes: 2 additions & 0 deletions docs/snippets/gpu/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
31 changes: 17 additions & 14 deletions docs/snippets/gpu/compile_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,43 @@
# SPDX-License-Identifier: Apache-2.0


from openvino.runtime import Core
import openvino as ov
from snippets import get_model

model = get_model()

#! [compile_model_default_gpu]
core = Core()
model = core.read_model("model.xml")
core = ov.Core()
compiled_model = core.compile_model(model, "GPU")
#! [compile_model_default_gpu]

#! [compile_model_gpu_with_id]
core = Core()
model = core.read_model("model.xml")
core = ov.Core()
compiled_model = core.compile_model(model, "GPU.1")
#! [compile_model_gpu_with_id]

#! [compile_model_gpu_with_id_and_tile]
core = Core()
model = core.read_model("model.xml")
core = ov.Core()
compiled_model = core.compile_model(model, "GPU.1.0")
#! [compile_model_gpu_with_id_and_tile]

#! [compile_model_multi]
core = Core()
model = core.read_model("model.xml")
core = ov.Core()
compiled_model = core.compile_model(model, "MULTI:GPU.1,GPU.0")
#! [compile_model_multi]

#! [compile_model_batch_plugin]
core = Core()
model = core.read_model("model.xml")
core = ov.Core()
compiled_model = core.compile_model(model, "BATCH:GPU")
#! [compile_model_batch_plugin]

#! [compile_model_auto_batch]
core = Core()
model = core.read_model("model.xml")
compiled_model = core.compile_model(model, "GPU", {"PERFORMANCE_HINT": "THROUGHPUT"})
core = ov.Core()
compiled_model = core.compile_model(
model,
"GPU",
{
ov.properties.hint.performance_mode(): ov.properties.hint.PerformanceMode.THROUGHPUT,
},
)
#! [compile_model_auto_batch]
6 changes: 3 additions & 3 deletions docs/snippets/gpu/custom_kernels_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import openvino as ov

from openvino.runtime import Core

# TODO: missing property to replace string
#! [part0]
core = Core()
core = ov.Core()
core.set_property("GPU", {"CONFIG_FILE": "<path_to_the_xml_file>"})
#! [part0]
11 changes: 8 additions & 3 deletions docs/snippets/gpu/dynamic_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
# SPDX-License-Identifier: Apache-2.0


import openvino.runtime as ov
import openvino as ov
from snippets import get_model

model = get_model()

#! [dynamic_batch]
core = ov.Core()
Expand All @@ -11,7 +14,6 @@
H = 224
W = 224

model = core.read_model("model.xml")
model.reshape([(1, 10), C, H, W])

# compile model and create infer request
Expand All @@ -23,6 +25,9 @@

# ...

infer_request.infer([input_tensor])
results = infer_request.infer([input_tensor])

#! [dynamic_batch]

assert list(results.keys())[0].partial_shape == ov.PartialShape([(1, 10), 3, 224, 224])
assert list(results.values())[0].shape == tuple(ov.Shape([2, 3, 224, 224]))
17 changes: 10 additions & 7 deletions docs/snippets/gpu/preprocessing_nv12_two_planes.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from snippets import get_model

model = get_model()

#! [init_preproc]
from openvino.runtime import Core, Type, Layout
import openvino as ov
from openvino.preprocess import PrePostProcessor, ColorFormat

core = Core()
model = core.read_model("model.xml")
core = ov.Core()

p = PrePostProcessor(model)
p.input().tensor().set_element_type(Type.u8) \
.set_color_format(ColorFormat.NV12_TWO_PLANES, ["y", "uv"]) \
.set_memory_type("GPU_SURFACE")
p.input().tensor().set_element_type(ov.Type.u8).set_color_format(
ColorFormat.NV12_TWO_PLANES, ["y", "uv"]
).set_memory_type("GPU_SURFACE")
p.input().preprocess().convert_color(ColorFormat.BGR)
p.input().model().set_layout(Layout("NCHW"))
p.input().model().set_layout(ov.Layout("NCHW"))
model_with_preproc = p.build()
#! [init_preproc]
Loading