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] Move ie_api.py and exceptions.py files to openvino module #28007

Merged
merged 9 commits into from
Dec 13, 2024

Conversation

almilosz
Copy link
Contributor

Details:

  • move runtime/ie_api.py and rename it to _ov_api.py as ie_api is a legacy name.

  • add runtime/ie_apy/__init__.py as proxy

  • update openvino/__init__ to import from _ov_api.py.

  • move runtime/exceptions.py and add proxy in runtime

  • update test_ovdict to use OVDict defined in openvino.runtime.utils.data_helpers

  • update tensor_from_file import in openvino/__init__.py. This function is located in openvino.runtime.utils.data_helpers

Part of openvino.runtime deprecation

Tickets:

Signed-off-by: Alicja Miloszewska <[email protected]>
Signed-off-by: Alicja Miloszewska <[email protected]>
Signed-off-by: Alicja Miloszewska <[email protected]>
Signed-off-by: Alicja Miloszewska <[email protected]>
Signed-off-by: Alicja Miloszewska <[email protected]>
@almilosz almilosz requested a review from akuporos December 10, 2024 14:49
@github-actions github-actions bot added category: Python API OpenVINO Python bindings category: tools OpenVINO C++ / Python tools category: OVC OVC tool labels Dec 10, 2024
…into almilosz/move-py-files

Signed-off-by: Alicja Miloszewska <[email protected]>
Signed-off-by: Alicja Miloszewska <[email protected]>
@almilosz almilosz marked this pull request as ready for review December 11, 2024 07:58
@almilosz almilosz requested review from a team as code owners December 11, 2024 07:58
@popovaan
Copy link
Contributor

popovaan commented Dec 11, 2024

@almilosz
Copy link
Contributor Author

Do we need to change __init__ files in dev tools? https://github.com/openvinotoolkit/openvino/blob/master/tools/mo/openvino/__init__.py#L26-L30

Currently there are no changes to tools/mo/openvino/__init__.py beacuse it's deprecated and will be removed. But imports like from openvino.runtime import Model should work during the deprecation period for openvino.runtime. openvino.runtime will be dropped in 2026.0 release.

@rkazants rkazants added this to the 2025.0 milestone Dec 11, 2024
from openvino.runtime import CompiledModel
from openvino.runtime import InferRequest
from openvino.runtime import AsyncInferQueue
from openvino._ov_api import Model
Copy link
Member

@rkazants rkazants Dec 11, 2024

Choose a reason for hiding this comment

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

what is the correct (official and offered to user) way to import Model, Core, and others here?
May be it should be just from openvino import Model and from openvino import Core?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, it is
_ov_api contains python wrappers above pybind11 bindings.

Copy link
Member

Choose a reason for hiding this comment

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

To me, _ov_api looks like internal api that nobody should use it.

Copy link
Contributor

@akuporos akuporos Dec 11, 2024

Choose a reason for hiding this comment

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

There is a check that __init__ files of openvino, ovc and benchmark app (prev also mo and openvino-dev) should be the same. It's still openvino/__init__.py. All three __init__ files during wheel building are installed in the same place openvino/__init__. If they aren't identical, they will overload each other.

@@ -43,12 +43,13 @@
from openvino.runtime import Tensor
from openvino.runtime import OVAny

from openvino.runtime import compile_model
# Helper functions for openvino module
from openvino.runtime.utils.data_helpers import tensor_from_file
Copy link
Member

Choose a reason for hiding this comment

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

Will we still have openvino.runtime? May be it is better to have openvino.utils?

Copy link
Contributor

Choose a reason for hiding this comment

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

it will be done in a separate PR

from openvino.runtime import compile_model
# Helper functions for openvino module
from openvino.runtime.utils.data_helpers import tensor_from_file
from openvino._ov_api import compile_model
Copy link
Member

Choose a reason for hiding this comment

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

User will never import in such a way. AFAIK, we propose from openvino import compile_model

Copy link
Contributor

Choose a reason for hiding this comment

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

answered above

Copy link
Member

Choose a reason for hiding this comment

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

It is not clear. Let us use from openvino import compile_model. Now it should work.

Copy link
Contributor

Choose a reason for hiding this comment

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

_ov_api.py is just a place for Python wrappers for C++ bindings (sometimes they're necessary, not in all cases). Since all __init__.py files are merged into one in wheel, they have to be aligned - that's why that change is also in tools/ovc/openvino/__init__.py.

Because it's in __init__.py, this import is indeed "internal" as you mentioned - the user will still be able to run from openvino import compile_model, because that __init__.py pulls compile_model from _ie_api.py and publishes it in the main openvino module.

The act of publishing the function to the main module itself is internal, it's not public API and should not concern the user, who keeps the same functionality of from openvino import compile_model.

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 clarify what is a concept of having _ov_api? Can't we just import directly from openvino?

@almilosz
Copy link
Contributor Author

To sum up
There is a way to import Core, Model and etc. directly from openvino. In the deprecation notice for openvino.runtime we would like to put the information to migrate to it.

From the user perspective it's a change a like this:

Before openvino.runtime deprecation After openvino.runtime deprecation
from openvino.runtime import Core from openvino import Core
from openvino.runtime import Model from openvino import Model
from openvino.runtime import compile_model from openvino import compile_model
from openvino.runtime import tensor_from_file from openvino import tensor_from_file

Please clarify what is a concept of having _ov_api?

It's a bad practice to have the implementation of classes and functions in openvino.__init__.py. It should be clean and focused on the public API. So the implementation will be located in _ov_api.py, while public API will be accessible directly from openvino.

@mlukasze
Copy link
Contributor

@rkazants @akuporos @p-wysocki
CI is Green, answers delivered, please take a look again.

@rkazants
Copy link
Member

To sum up There is a way to import Core, Model and etc. directly from openvino. In the deprecation notice for openvino.runtime we would like to put the information to migrate to it.

From the user perspective it's a change a like this:

Before openvino.runtime deprecation After openvino.runtime deprecation
from openvino.runtime import Core from openvino import Core
from openvino.runtime import Model from openvino import Model
from openvino.runtime import compile_model from openvino import compile_model
from openvino.runtime import tensor_from_file from openvino import tensor_from_file

Please clarify what is a concept of having _ov_api?

It's a bad practice to have the implementation of classes and functions in openvino.__init__.py. It should be clean and focused on the public API. So the implementation will be located in _ov_api.py, while public API will be accessible directly from openvino.

I am lost. So do you mean I need to use _ov_api.py for importing Core class? And do you propose to users to import openvino._ov_api? It looks awkward because names with prefix _ used for internal API.

Best regards,
Roman

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.

Need clarification of further Python API design and not clear why _ov_api is needed and targeted for.

from openvino.runtime import compile_model
# Helper functions for openvino module
from openvino.runtime.utils.data_helpers import tensor_from_file
from openvino._ov_api import compile_model
Copy link
Contributor

Choose a reason for hiding this comment

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

_ov_api.py is just a place for Python wrappers for C++ bindings (sometimes they're necessary, not in all cases). Since all __init__.py files are merged into one in wheel, they have to be aligned - that's why that change is also in tools/ovc/openvino/__init__.py.

Because it's in __init__.py, this import is indeed "internal" as you mentioned - the user will still be able to run from openvino import compile_model, because that __init__.py pulls compile_model from _ie_api.py and publishes it in the main openvino module.

The act of publishing the function to the main module itself is internal, it's not public API and should not concern the user, who keeps the same functionality of from openvino import compile_model.

@almilosz almilosz requested a review from rkazants December 13, 2024 13:54
@rkazants rkazants added this pull request to the merge queue Dec 13, 2024
Merged via the queue into openvinotoolkit:master with commit f790885 Dec 13, 2024
176 checks passed
11happy pushed a commit to 11happy/openvino that referenced this pull request Dec 23, 2024
…envinotoolkit#28007)

### Details:
- move `runtime/ie_api.py` and rename it to `_ov_api.py` as ie_api is a
legacy name.
- add `runtime/ie_apy/__init__.py` as proxy
- update `openvino/__init__` to import from `_ov_api.py`.

- move `runtime/exceptions.py` and add proxy in `runtime`
- update `test_ovdict` to use `OVDict` defined in
`openvino.runtime.utils.data_helpers`
- update `tensor_from_file` import in `openvino/__init__.py`. This
function is located in `openvino.runtime.utils.data_helpers`

Part of `openvino.runtime` deprecation

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

---------

Signed-off-by: Alicja Miloszewska <[email protected]>
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
…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]>
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.

6 participants