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

[Py OV] Alias classes and functions in flatten openvino namespace #28085

Merged
merged 14 commits into from
Dec 19, 2024

Conversation

almilosz
Copy link
Contributor

@almilosz almilosz commented Dec 16, 2024

Details:

  • Add imports from _pyopenivno on the top of the openvino __init__.py
  • Move Node binary operators support at the bottom of openvino __init__.py

Classes and functions available in openvino/runtime will match those in flatten openvino

Tickets:

Signed-off-by: Alicja Miloszewska <[email protected]>
…into almilosz/alias-classes

Signed-off-by: Alicja Miloszewska <[email protected]>
Signed-off-by: Alicja Miloszewska <[email protected]>
@almilosz almilosz requested review from a team as code owners December 16, 2024 20:29
@github-actions github-actions bot added category: Python API OpenVINO Python bindings category: tools OpenVINO C++ / Python tools category: OVC OVC tool labels Dec 16, 2024
@almilosz almilosz requested a review from a team as a code owner December 17, 2024 13:39
Signed-off-by: Alicja Miloszewska <[email protected]>
Comment on lines 93 to 110
# Extend Node class to support binary operators
Node.__add__ = opset13.add
Node.__sub__ = opset13.subtract
Node.__mul__ = opset13.multiply
Node.__div__ = opset13.divide
Node.__truediv__ = opset13.divide
Node.__radd__ = lambda left, right: opset13.add(right, left)
Node.__rsub__ = lambda left, right: opset13.subtract(right, left)
Node.__rmul__ = lambda left, right: opset13.multiply(right, left)
Node.__rdiv__ = lambda left, right: opset13.divide(right, left)
Node.__rtruediv__ = lambda left, right: opset13.divide(right, left)
Node.__eq__ = utils.deprecated(version="2025.3", message="Use ops.equal instead")(opset13.equal)
Node.__ne__ = utils.deprecated(version="2025.3", message="Use ops.not_equal instead")(opset13.not_equal)
Node.__lt__ = utils.deprecated(version="2025.3", message="Use ops.less instead")(opset13.less)
Node.__le__ = utils.deprecated(version="2025.3", message="Use ops.less_equal instead")(opset13.less_equal)
Node.__gt__ = utils.deprecated(version="2025.3", message="Use ops.greater instead")(opset13.greater)
Node.__ge__ = utils.deprecated(version="2025.3", message="Use ops.greater_equal instead")(opset13.greater_equal)

Copy link
Member

Choose a reason for hiding this comment

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

we don't need it here. You can extend it in one place and re-use it overall.
Let say in py file for Node class that is more logical to have

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fully agree with your comment. I created a task to improve this.
This PR is simply about moving functionality from openvino/runtime/__init__ to openvino/__init__ so let's discuss it as a separate issue.

Copy link
Member

@rkazants rkazants Dec 18, 2024

Choose a reason for hiding this comment

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

Let us do in this PR. It is normal process to get feedback and apply it in right away. Moreover, it is slight change and not a big deal:)

Signed-off-by: Alicja Miloszewska <[email protected]>
…into almilosz/alias-classes

Signed-off-by: Alicja Miloszewska <[email protected]>
Copy link
Member

@rkazants rkazants left a comment

Choose a reason for hiding this comment

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

Please remove duplicating code with defining Node class methods.
Yan can simple define it in Node py file (that is logical) and use it overall

@almilosz
Copy link
Contributor Author

Node class is extended in a few places (and the code duplicates) because openvino, ovc and benchmark_tool inits have to be the same. There won't be a situation when somebody forget to update one of these files.
Unfortunately there are still some samples in jenkins that depend on mo init and openvino_dev init. That's why those two are also updated.

Please remove duplicating code with defining Node class methods. Yan can simple define it in Node py file (that is logical) and use it overall

I agree with you, but I don't want to introduce any new logic or new namespace in this PR. Let's discuss it separately. I created a task to not forget about it :)

@akuporos

@almilosz almilosz requested a review from rkazants December 18, 2024 14:20
Copy link
Contributor

@p-wysocki p-wysocki left a comment

Choose a reason for hiding this comment

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

LGTM, one concerning thing is the specific opset13 imports in the main __init__.py file, but in my opinion it's out of scope of this PR.

Comment on lines 94 to 103
Node.__add__ = opset13.add
Node.__sub__ = opset13.subtract
Node.__mul__ = opset13.multiply
Node.__div__ = opset13.divide
Node.__truediv__ = opset13.divide
Node.__radd__ = lambda left, right: opset13.add(right, left)
Node.__rsub__ = lambda left, right: opset13.subtract(right, left)
Node.__rmul__ = lambda left, right: opset13.multiply(right, left)
Node.__rdiv__ = lambda left, right: opset13.divide(right, left)
Node.__rtruediv__ = lambda left, right: opset13.divide(right, left)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have opset13 here specifically? I'm not blocking the PR, it's a separate discussion.

There's no mechanism to get the "newest opset" op (which I think would be a good addition to the API), but still, there has to be room for improvement here. We may introduce a new version for one of these ops, for any reason, it's an edge case to remember that it also should be bumped here.

Copy link
Member

Choose a reason for hiding this comment

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

Moreover, these arithmetic methods are semantically incorrect to have. That is because we can't sum up nodes that have more one outputs.
It is more logical to define such methods for ov::Output (corresponding to tensors).

@rkazants
Copy link
Member

rkazants commented Dec 18, 2024

I agree with you, but I don't want to introduce any new logic or new namespace in this PR. Let's discuss it separately. I created a task to not forget about it :)

I don't think this is a right approach to create task for review comments that can be applied easily by extra commit. Let us do this in this PR because the task can be forgotten, postponed for long time and closed finally as not implemented. Moreover, in that logic you have weak spot using opset13 that is repeating in several places. Let us have this weak spot just in one place that will be more easy to fix further.

Copy link
Member

@rkazants rkazants left a comment

Choose a reason for hiding this comment

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

still not convinced

Copy link
Contributor

@akuporos akuporos left a comment

Choose a reason for hiding this comment

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

I give the green light with one condition: let's rollback changes for Node magic methods and move them from __init__ in a separate PR.
This PR blocks #27694, but magic methods IMHO doesn't, so they can be moved after holidays.

@akuporos akuporos requested a review from rkazants December 18, 2024 16:16
@mlukasze mlukasze enabled auto-merge December 19, 2024 05:51
@mlukasze mlukasze added this pull request to the merge queue Dec 19, 2024
Merged via the queue into openvinotoolkit:master with commit d0a8a39 Dec 19, 2024
203 of 204 checks passed
11happy pushed a commit to 11happy/openvino that referenced this pull request Dec 23, 2024
…envinotoolkit#28085)

### Details:
 - Add imports from _pyopenivno on the top of the openvino `__init__.py`
- Move `Node` binary operators support at the bottom of openvino
`__init__.py`

Classes and functions available in `openvino/runtime` will match those
in flatten `openvino`

### Tickets:
 - [CVS-129453](https://jira.devtools.intel.com/browse/CVS-129453)

---------

Signed-off-by: Alicja Miloszewska <[email protected]>
Co-authored-by: Michal Lukaszewski <[email protected]>
ilya-lavrenov added a commit to ilya-lavrenov/openvino that referenced this pull request Dec 24, 2024
github-merge-queue bot pushed a commit that referenced this pull request Dec 24, 2024
### Reverted:
- #28062 (Guilty one)
- #28085 (Relies on
Guilty one)
- #28166 (Relies on
Guilty one)
github-merge-queue bot pushed a commit that referenced this pull request Jan 16, 2025
### Details:
Add deprecation warning for `openvino.runtime` that will be shown
**ONCE** when sb will access runtime functionality for the first time.
Examples:
![Screenshot 2025-01-10
114701](https://github.com/user-attachments/assets/4229ede3-3b86-418a-8dbf-f230ff91983b)

![warn_updated](https://github.com/user-attachments/assets/4b4a7c56-c5ca-4b7b-8b34-f89f3a4bc627)

`openvino.runtime` funtionality was added to openvino namespace in these
PRs:
- #27785
- #27902
- #28007
- #28062
- #28085

Internal calls in `openvino` module also triggered warning, so they were
updated:
 - #28166 
 - #28356

### Tickets:
 - [CVS-129451](https://jira.devtools.intel.com/browse/CVS-129451)

---------

Signed-off-by: Alicja Miloszewska <[email protected]>
Co-authored-by: Anastasia Kuporosova <[email protected]>
MirceaDan99 pushed a commit to MirceaDan99/openvino that referenced this pull request Jan 22, 2025
MirceaDan99 pushed a commit to MirceaDan99/openvino that referenced this pull request Jan 22, 2025
…7694)

### Details:
Add deprecation warning for `openvino.runtime` that will be shown
**ONCE** when sb will access runtime functionality for the first time.
Examples:
![Screenshot 2025-01-10
114701](https://github.com/user-attachments/assets/4229ede3-3b86-418a-8dbf-f230ff91983b)

![warn_updated](https://github.com/user-attachments/assets/4b4a7c56-c5ca-4b7b-8b34-f89f3a4bc627)

`openvino.runtime` funtionality was added to openvino namespace in these
PRs:
- openvinotoolkit#27785
- openvinotoolkit#27902
- openvinotoolkit#28007
- openvinotoolkit#28062
- openvinotoolkit#28085

Internal calls in `openvino` module also triggered warning, so they were
updated:
 - openvinotoolkit#28166 
 - openvinotoolkit#28356

### Tickets:
 - [CVS-129451](https://jira.devtools.intel.com/browse/CVS-129451)

---------

Signed-off-by: Alicja Miloszewska <[email protected]>
Co-authored-by: Anastasia Kuporosova <[email protected]>
@almilosz almilosz deleted the almilosz/alias-classes branch January 30, 2025 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: OVC OVC tool category: Python API OpenVINO Python bindings category: tools OpenVINO C++ / Python tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants