Skip to content

[PyOV][25.3] Remove deprecated binary operations Node API #30636

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 0 additions & 10 deletions src/bindings/python/src/openvino/runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,3 @@
# Helper functions for openvino module
from openvino.runtime.ie_api import tensor_from_file
from openvino.runtime.ie_api import compile_model

from openvino.utils import deprecated

# Extend Node class to support binary operators
Node.__eq__ = deprecated(version="2025.3", message="Use ops.equal instead")(opset13.equal)
Node.__ne__ = deprecated(version="2025.3", message="Use ops.not_equal instead")(opset13.not_equal)
Node.__lt__ = deprecated(version="2025.3", message="Use ops.less instead")(opset13.less)
Node.__le__ = deprecated(version="2025.3", message="Use ops.less_equal instead")(opset13.less_equal)
Node.__gt__ = deprecated(version="2025.3", message="Use ops.greater instead")(opset13.greater)
Node.__ge__ = deprecated(version="2025.3", message="Use ops.greater_equal instead")(opset13.greater_equal)
Original file line number Diff line number Diff line change
Expand Up @@ -366,62 +366,3 @@ def test_runtime_passes_manager():

assert count_ops_of_type(model, node_ceil) == 0
assert count_ops_of_type(model, node_constant) == 1


# from test_graph/test_ops_binary.py
@pytest.mark.parametrize(
("operator", "expected_type", "warning_type"),
[
(operator.add, Type.f32, warnings.catch_warnings(record=True)),
(operator.sub, Type.f32, warnings.catch_warnings(record=True)),
(operator.mul, Type.f32, warnings.catch_warnings(record=True)),
(operator.truediv, Type.f32, warnings.catch_warnings(record=True)),
(operator.eq, Type.boolean, pytest.warns(DeprecationWarning)),
(operator.ne, Type.boolean, pytest.warns(DeprecationWarning)),
(operator.gt, Type.boolean, pytest.warns(DeprecationWarning)),
(operator.ge, Type.boolean, pytest.warns(DeprecationWarning)),
(operator.lt, Type.boolean, pytest.warns(DeprecationWarning)),
(operator.le, Type.boolean, pytest.warns(DeprecationWarning)),
],
)
def test_binary_operators(operator, expected_type, warning_type):
value_b = np.array([[4, 5], [1, 7]], dtype=np.float32)

shape = [2, 2]
parameter_a = ops.parameter(shape, name="A", dtype=np.float32)

with warning_type:
model = operator(parameter_a, value_b)

assert model.get_output_size() == 1
assert list(model.get_output_shape(0)) == shape
assert model.get_output_element_type(0) == expected_type


@pytest.mark.parametrize(
("operator", "expected_type", "warning_type"),
[
(operator.add, Type.f32, warnings.catch_warnings(record=True)),
(operator.sub, Type.f32, warnings.catch_warnings(record=True)),
(operator.mul, Type.f32, warnings.catch_warnings(record=True)),
(operator.truediv, Type.f32, warnings.catch_warnings(record=True)),
(operator.eq, Type.boolean, pytest.warns(DeprecationWarning)),
(operator.ne, Type.boolean, pytest.warns(DeprecationWarning)),
(operator.gt, Type.boolean, pytest.warns(DeprecationWarning)),
(operator.ge, Type.boolean, pytest.warns(DeprecationWarning)),
(operator.lt, Type.boolean, pytest.warns(DeprecationWarning)),
(operator.le, Type.boolean, pytest.warns(DeprecationWarning)),
],
)
def test_binary_operators_with_scalar(operator, expected_type, warning_type):
value_b = np.array([[5, 6], [7, 8]], dtype=np.float32)

shape = [2, 2]
parameter_a = ops.parameter(shape, name="A", dtype=np.float32)

with warning_type:
model = operator(parameter_a, value_b)

assert model.get_output_size() == 1
assert list(model.get_output_shape(0)) == shape
assert model.get_output_element_type(0) == expected_type
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ def test_replace_node():


def test_replace_output_update_name():
# Before replacement: param -> relu -> exp -> result
# After replacement: param -> relu -> result
param = ops.parameter(PartialShape([1, 3, 22, 22]), name="parameter")
relu = ops.relu(param.output(0))
exp = ops.exp(relu.output(0))
res = ops.result(exp.output(0), name="result")

replace_output_update_name(exp.output(0), exp.input_value(0))

assert res.input_value(0).get_node() == exp
assert res.input_value(0).get_node().get_instance_id() == relu.get_instance_id()
assert res.input_value(0).get_node().get_friendly_name() == exp.get_friendly_name()
Loading