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

Fix deepcopy of ov.Tensor #1146

Closed
wants to merge 6 commits into from
Closed

Fix deepcopy of ov.Tensor #1146

wants to merge 6 commits into from

Conversation

kshpv
Copy link

@kshpv kshpv commented Feb 5, 2025

What does this PR do?

Fix applying deepcopy to ov.Tensor

elif isinstance(inputs, tuple):
new_inputs = tuple(deepcopy_data(elem) for elem in inputs)
elif isinstance(inputs, openvino.Tensor):
new_inputs = openvino.Tensor(np.zeros(inputs.shape, dtype=inputs.element_type.to_dtype()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
new_inputs = openvino.Tensor(np.zeros(inputs.shape, dtype=inputs.element_type.to_dtype()))
new_inputs = openvino.Tensor(np.empty(inputs.shape, dtype=inputs.element_type.to_dtype()))

elif isinstance(inputs, tuple):
new_inputs = tuple(deepcopy_data(elem) for elem in inputs)
elif isinstance(inputs, openvino.Tensor):
new_inputs = openvino.Tensor(np.zeros(inputs.shape, dtype=inputs.element_type.to_dtype()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

What will happen if inputs.element_type is bf16, u4 or i4?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the comment!
I added a type argument to be sure that output tensor has a correct type.

"f": [ov.Tensor(np.ones((1, 2, 3))), ov.Tensor(np.ones((1, 2, 3)))],
}
copied_data = deepcopy_data(data)
assert copied_data["a"] is not data["a"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use self.assertTrue(...) or similar instead of assert ...

Copy link
Author

Choose a reason for hiding this comment

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

updated

@kshpv kshpv marked this pull request as ready for review February 6, 2025 09:21
Copy link
Collaborator

@nikita-savelyevv nikita-savelyevv left a comment

Choose a reason for hiding this comment

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

Thanks!

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@AlexKoff88
Copy link
Collaborator

The right place for this fix is OpenVINO Python API. If we do it we can fix it in all the integrations of OV to 3rd party projects including Optimum, Ulralytics, etc.

@kshpv
Copy link
Author

kshpv commented Feb 6, 2025

The right place for this fix is OpenVINO Python API. If we do it we can fix it in all the integrations of OV to 3rd party projects including Optimum, Ulralytics, etc.

There is an open ticket to add deepcopy support in the OpenVINO Python API. Until it is resolved, this workaround can prevent bugs in the main branch. What do you think?

@AlexKoff88
Copy link
Collaborator

The right place for this fix is OpenVINO Python API. If we do it we can fix it in all the integrations of OV to 3rd party projects including Optimum, Ulralytics, etc.

There is an open ticket to add deepcopy support in the OpenVINO Python API. Until it is resolved, this workaround can prevent bugs in the main branch. What do you think?

I am still thinking that this is not a good idea to fix OV issues in 3rd party projects. From what I understood you have problems with NNCF CI. To address them quickly, you could:

  • Prepare fix to OV Python API
  • Wait until it is merged
  • Move NNCF CI to openvino-nightly build with the fix

cc'ed @alexsu52 to drive that

@kshpv kshpv closed this Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants