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] Constant/Tensor from scalars #16270

Merged

Conversation

jiwaszki
Copy link

@jiwaszki jiwaszki commented Mar 13, 2023

Details:

  • Improve implementation of Constant/Tensor to allow creation of scalars from numpy arrays with 0-dim.
  • Updated data_dispatcher to use new feature. Adjust the function to correctly consume scalars in other forms.
  • Added test cases for new constructors and inference with scalar inputs. Check for data sharing in various cases (in other words, validate inner-workings of data_dispatcher).

Example:

In [1]: import numpy as np
   ...: import openvino.runtime as ov
   ...: 
   ...: value = np.array(1)
   ...: t_copy = ov.Tensor(value, shared_memory=False)
   ...: t_shared = ov.Tensor(value, shared_memory=True)
   ...: 

In [2]: t_copy.data
Out[2]: array(1)

In [3]: np.shares_memory(t_copy.data, value)
Out[3]: False

In [4]: t_shared.data
Out[4]: array(1)

In [5]: value[()] = 3

In [6]: t_shared.data
Out[6]: array(3)

In [7]: np.shares_memory(t_shared.data, value)
Out[7]: True

Tickets:

  • 104709

@jiwaszki jiwaszki added the category: Python API OpenVINO Python bindings label Mar 13, 2023
@jiwaszki jiwaszki added this to the 2022.3 milestone Mar 13, 2023
@jiwaszki jiwaszki requested a review from a team as a code owner March 13, 2023 17:32
@jiwaszki jiwaszki self-assigned this Mar 13, 2023
@mlukasze mlukasze added the Feature Freeze Label to highlight PR for Feature Freeze label Mar 15, 2023
@jiwaszki jiwaszki merged commit 0372ca9 into openvinotoolkit:master Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: Python API OpenVINO Python bindings Feature Freeze Label to highlight PR for Feature Freeze
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants