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
[Py OV] Add runtime/passes to openvino namespace (#27785)
Alicja Miloszewskad2c9c80cf61b
diff --git a/src/bindings/python/src/openvino/passes/__init__.py b/src/bindings/python/src/openvino/passes/__init__.pynew file mode 100644index 00000000000..037d9774c5b--- /dev/null+++ b/src/bindings/python/src/openvino/passes/__init__.py@@ -0,0 +1,19 @@+# Copyright (C) 2018-2024 Intel Corporation+# SPDX-License-Identifier: Apache-2.0+# type: ignore+# flake8: noqa++from openvino._pyopenvino.passes import ModelPass, Matcher, MatcherPass, PassBase, WrapType, Or, AnyInput, Optional+from openvino._pyopenvino.passes import (+ consumers_count,+ has_static_dim,+ has_static_dims,+ has_static_shape,+ has_static_rank,+ rank_equals,+ type_matches,+ type_matches_any,+)+from openvino._pyopenvino.passes import Serialize, ConstantFolding, VisualizeTree, MakeStateful, LowLatency2, ConvertFP32ToFP16, Version+from openvino.passes.manager import Manager+from openvino.passes.graph_rewrite import GraphRewrite, BackwardGraphRewritediff --git a/src/bindings/python/src/openvino/runtime/passes/graph_rewrite.py b/src/bindings/python/src/openvino/passes/graph_rewrite.pysimilarity index 100%rename from src/bindings/python/src/openvino/runtime/passes/graph_rewrite.pyrename to src/bindings/python/src/openvino/passes/graph_rewrite.pydiff --git a/src/bindings/python/src/openvino/runtime/passes/manager.py b/src/bindings/python/src/openvino/passes/manager.pysimilarity index 100%rename from src/bindings/python/src/openvino/runtime/passes/manager.pyrename to src/bindings/python/src/openvino/passes/manager.pydiff --git a/src/bindings/python/src/openvino/runtime/passes/__init__.py b/src/bindings/python/src/openvino/runtime/passes/__init__.pyindex 19a28c7576d..a74f91fdcfa 100644--- a/src/bindings/python/src/openvino/runtime/passes/__init__.py+++ b/src/bindings/python/src/openvino/runtime/passes/__init__.py@@ -3,8 +3,8 @@# type: ignore# flake8: noqa-from openvino._pyopenvino.passes import ModelPass, Matcher, MatcherPass, PassBase, WrapType, Or, AnyInput, Optional-from openvino._pyopenvino.passes import (+from openvino.passes import ModelPass, Matcher, MatcherPass, PassBase, WrapType, Or, AnyInput, Optional+from openvino.passes import (consumers_count,has_static_dim,has_static_dims,@@ -14,6 +14,6 @@ from openvino._pyopenvino.passes import (type_matches,type_matches_any,)-from openvino._pyopenvino.passes import Serialize, ConstantFolding, VisualizeTree, MakeStateful, LowLatency2, ConvertFP32ToFP16, Version-from openvino.runtime.passes.manager import Manager-from openvino.runtime.passes.graph_rewrite import GraphRewrite, BackwardGraphRewrite+from openvino.passes import Serialize, ConstantFolding, VisualizeTree, MakeStateful, LowLatency2, ConvertFP32ToFP16, Version+from openvino.passes.manager import Manager+from openvino.passes.graph_rewrite import GraphRewrite, BackwardGraphRewritediff --git a/src/bindings/python/src/openvino/runtime/passes/graph_rewrite/__init__.py b/src/bindings/python/src/openvino/runtime/passes/graph_rewrite/__init__.pynew file mode 100644index 00000000000..a9690e891ff--- /dev/null+++ b/src/bindings/python/src/openvino/runtime/passes/graph_rewrite/__init__.py@@ -0,0 +1,5 @@+# -*- coding: utf-8 -*-+# Copyright (C) 2018-2024 Intel Corporation+# SPDX-License-Identifier: Apache-2.0+# type: ignore+from openvino.passes.graph_rewrite import GraphRewrite, BackwardGraphRewritediff --git a/src/bindings/python/src/openvino/runtime/passes/manager/__init__.py b/src/bindings/python/src/openvino/runtime/passes/manager/__init__.pynew file mode 100644index 00000000000..1a2674dd03c--- /dev/null+++ b/src/bindings/python/src/openvino/runtime/passes/manager/__init__.py@@ -0,0 +1,5 @@+# -*- coding: utf-8 -*-+# Copyright (C) 2018-2024 Intel Corporation+# SPDX-License-Identifier: Apache-2.0+# type: ignore+from openvino.passes.manager import Managerdiff --git a/src/bindings/python/tests/test_graph/test_manager.py b/src/bindings/python/tests/test_graph/test_manager.pyindex ff72ef43158..5101414228c 100644--- a/src/bindings/python/tests/test_graph/test_manager.py+++ b/src/bindings/python/tests/test_graph/test_manager.py@@ -9,7 +9,7 @@ import pytestimport openvino.runtime.opset10 as opsfrom openvino import Core, Model-from openvino.runtime.passes import Manager, Serialize, ConstantFolding, Version+from openvino.passes import Manager, Serialize, ConstantFolding, Versionfrom tests.test_graph.util import count_ops_of_typefrom tests.utils.helpers import create_filenames_for_ir, compare_models@@ -48,6 +48,23 @@ def test_constant_folding():assert np.allclose(values_out, values_expected)+def test_runtime_passes_manager():+ import openvino.runtime.passes as rt+ node_constant = ops.constant(np.array([[0.0, 0.1, -0.1], [-2.5, 2.5, 3.0]], dtype=np.float32))+ node_ceil = ops.ceiling(node_constant)+ model = Model(node_ceil, [], "TestModel")++ assert count_ops_of_type(model, node_ceil) == 1+ assert count_ops_of_type(model, node_constant) == 1++ pass_manager = rt.Manager()+ pass_manager.register_pass(rt.ConstantFolding())+ pass_manager.run_passes(model)++ assert count_ops_of_type(model, node_ceil) == 0+ assert count_ops_of_type(model, node_constant) == 1++# request - https://docs.pytest.org/en/7.1.x/reference/reference.html#request@pytest.fixturedef prepare_ir_paths(request, tmp_path):diff --git a/src/bindings/python/tests/test_transformations/test_graph_rewrite.py b/src/bindings/python/tests/test_transformations/test_graph_rewrite.pyindex 4821dad33df..5f5c100597a 100644--- a/src/bindings/python/tests/test_transformations/test_graph_rewrite.py+++ b/src/bindings/python/tests/test_transformations/test_graph_rewrite.py@@ -2,7 +2,7 @@# Copyright (C) 2018-2024 Intel Corporation# SPDX-License-Identifier: Apache-2.0from openvino.runtime import opset8-from openvino.runtime.passes import Manager, GraphRewrite, MatcherPass, WrapType, Matcher+from openvino.passes import Manager, GraphRewrite, MatcherPass, WrapType, Matcherfrom tests.test_transformations.utils.utils import count_ops, get_relu_model, PatternReplacement@@ -19,6 +19,19 @@ def test_graph_rewrite():assert count_ops(model, "Relu") == [2]+def test_runtime_graph_rewrite():+ import openvino.runtime.passes as rt+ model = get_relu_model()++ manager = rt.Manager()+ # check that register pass returns pass instance+ anchor = manager.register_pass(rt.GraphRewrite())+ anchor.add_matcher(PatternReplacement())+ manager.run_passes(model)++ assert count_ops(model, "Relu") == [2]++def test_register_new_node():class InsertExp(MatcherPass):def __init__(self):diff --git a/src/bindings/python/tests/test_transformations/test_manager.py b/src/bindings/python/tests/test_transformations/test_manager.pyindex e78c62d8c1a..e8f113f30b3 100644--- a/src/bindings/python/tests/test_transformations/test_manager.py+++ b/src/bindings/python/tests/test_transformations/test_manager.py@@ -1,7 +1,7 @@# -*- coding: utf-8 -*-# Copyright (C) 2018-2024 Intel Corporation# SPDX-License-Identifier: Apache-2.0-from openvino.runtime.passes import Manager, GraphRewrite, BackwardGraphRewrite, Serialize+from openvino.passes import Manager, GraphRewrite, BackwardGraphRewrite, Serializefrom tests.test_transformations.utils.utils import MyModelPass, PatternReplacement, expect_exceptiondiff --git a/src/bindings/python/tests/test_transformations/test_matcher_pass.py b/src/bindings/python/tests/test_transformations/test_matcher_pass.pyindex c32483be316..8127e4b7612 100644--- a/src/bindings/python/tests/test_transformations/test_matcher_pass.py+++ b/src/bindings/python/tests/test_transformations/test_matcher_pass.py@@ -2,7 +2,7 @@# Copyright (C) 2018-2024 Intel Corporation# SPDX-License-Identifier: Apache-2.0from openvino.runtime import opset8-from openvino.runtime.passes import Manager, Matcher, MatcherPass, WrapType+from openvino.passes import Manager, Matcher, MatcherPass, WrapTypefrom openvino.runtime.utils import replace_nodefrom tests.test_transformations.utils.utils import count_ops, get_relu_model, PatternReplacementdiff --git a/src/bindings/python/tests/test_transformations/test_model_pass.py b/src/bindings/python/tests/test_transformations/test_model_pass.pyindex 5df3d0a9024..efc797535d8 100644--- a/src/bindings/python/tests/test_transformations/test_model_pass.py+++ b/src/bindings/python/tests/test_transformations/test_model_pass.py@@ -1,7 +1,7 @@# -*- coding: utf-8 -*-# Copyright (C) 2018-2024 Intel Corporation# SPDX-License-Identifier: Apache-2.0-from openvino.runtime.passes import Manager+from openvino.passes import Managerfrom tests.test_transformations.utils.utils import get_relu_model, MyModelPassdiff --git a/src/bindings/python/tests/test_transformations/test_pattern_ops.py b/src/bindings/python/tests/test_transformations/test_pattern_ops.pyindex 24b28061582..c445c281e47 100644--- a/src/bindings/python/tests/test_transformations/test_pattern_ops.py+++ b/src/bindings/python/tests/test_transformations/test_pattern_ops.py@@ -6,8 +6,8 @@ import pytestfrom openvino import PartialShapefrom openvino.runtime import opset13 as ops-from openvino.runtime.passes import Matcher, WrapType, Or, AnyInput, Optional-from openvino.runtime.passes import (+from openvino.passes import Matcher, WrapType, Or, AnyInput, Optional+from openvino.passes import (consumers_count,has_static_dim,has_static_dims,diff --git a/src/bindings/python/tests/test_transformations/test_public_transformations.py b/src/bindings/python/tests/test_transformations/test_public_transformations.pyindex a10fea786b9..eac356cd134 100644--- a/src/bindings/python/tests/test_transformations/test_public_transformations.py+++ b/src/bindings/python/tests/test_transformations/test_public_transformations.py@@ -7,7 +7,7 @@ import numpy as npfrom openvino import Model, PartialShape, Shape, Corefrom openvino.runtime import opset13 as ops-from openvino.runtime.passes import (+from openvino.passes import (Manager,ConstantFolding,MakeStateful,diff --git a/src/bindings/python/tests/test_transformations/utils/utils.py b/src/bindings/python/tests/test_transformations/utils/utils.pyindex e0239ce05fd..b5f09a68ff1 100644--- a/src/bindings/python/tests/test_transformations/utils/utils.py+++ b/src/bindings/python/tests/test_transformations/utils/utils.py@@ -4,7 +4,7 @@from openvino import Model, PartialShapefrom openvino.runtime import opset13 as ops-from openvino.runtime.passes import ModelPass, Matcher, MatcherPass, WrapType+from openvino.passes import ModelPass, Matcher, MatcherPass, WrapTypedef get_relu_model():