-
Notifications
You must be signed in to change notification settings - Fork 19.7k
[OpenVINO backend] Support for numpy.eigh #22363
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||||||||||||||
| import numpy as np | ||||||||||||||||||
| import openvino.opset15 as ov_opset | ||||||||||||||||||
| from openvino import Type | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -6,6 +7,7 @@ | |||||||||||||||||
| from keras.src.backend.common import dtypes | ||||||||||||||||||
| from keras.src.backend.openvino.core import OpenVINOKerasTensor | ||||||||||||||||||
| from keras.src.backend.openvino.core import cast | ||||||||||||||||||
| from keras.src.backend.openvino.core import convert_to_numpy | ||||||||||||||||||
| from keras.src.backend.openvino.core import convert_to_tensor | ||||||||||||||||||
| from keras.src.backend.openvino.core import get_ov_output | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -42,7 +44,33 @@ def eig(a): | |||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def eigh(a): | ||||||||||||||||||
| raise NotImplementedError("`eigh` is not supported with openvino backend") | ||||||||||||||||||
| a = convert_to_tensor(a) | ||||||||||||||||||
| a_ov = get_ov_output(a) | ||||||||||||||||||
|
|
||||||||||||||||||
| a_ov_type = a_ov.get_element_type() | ||||||||||||||||||
| if not a_ov_type.is_real(): | ||||||||||||||||||
| a_ov = ov_opset.convert(a_ov, Type.f32).output(0) | ||||||||||||||||||
| out_ov_type = Type.f32 | ||||||||||||||||||
| else: | ||||||||||||||||||
| out_ov_type = a_ov_type | ||||||||||||||||||
|
|
||||||||||||||||||
| a_evaluated = OpenVINOKerasTensor(a_ov) | ||||||||||||||||||
| try: | ||||||||||||||||||
| a_np = convert_to_numpy(a_evaluated) | ||||||||||||||||||
| except Exception as e: | ||||||||||||||||||
| raise ValueError( | ||||||||||||||||||
| "eigh is only supported for static eager tensors " | ||||||||||||||||||
| "in the openvino backend. Received a dynamic or symbolic tensor." | ||||||||||||||||||
| ) from e | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+57
to
+65
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why this would be needed. Also, we don't want numpy on the execution path, otherwise something that could run on GPU would run on CPU with NumPy instead of OV. |
||||||||||||||||||
| w_np, v_np = np.linalg.eigh(a_np) | ||||||||||||||||||
|
|
||||||||||||||||||
| w_const = ov_opset.constant(w_np, out_ov_type).output(0) | ||||||||||||||||||
| v_const = ov_opset.constant(v_np, out_ov_type).output(0) | ||||||||||||||||||
| return ( | ||||||||||||||||||
| OpenVINOKerasTensor(w_const), | ||||||||||||||||||
| OpenVINOKerasTensor(v_const), | ||||||||||||||||||
| ) | ||||||||||||||||||
|
Comment on lines
+70
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with other operations in the OpenVINO backend (e.g.,
Suggested change
References
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please address the gemini reviews given here. |
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def inv(a): | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we implement eig as well in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure will do it