Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion keras/src/backend/openvino/excluded_concrete_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ LayerTest::test_stateless_call
LinalgOpsCorrectnessTest::test_cholesky
LinalgOpsCorrectnessTest::test_det
LinalgOpsCorrectnessTest::test_eig
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure will do it

LinalgOpsCorrectnessTest::test_eigh
LinalgOpsCorrectnessTest::test_lstsq
LinalgOpsCorrectnessTest::test_lu_factor
LinalgOpsCorrectnessTest::test_norm_2_-2
Expand Down
30 changes: 29 additions & 1 deletion keras/src/backend/openvino/linalg.py
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

Expand All @@ -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

Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

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

high

For consistency with other operations in the OpenVINO backend (e.g., inv, norm), this function should return a tuple of OpenVINOKerasTensor instances instead of raw ov.Output objects. This ensures that the results remain within the Keras backend tensor abstraction, allowing subsequent Keras operations to work correctly on them.

Suggested change
return (
ov_opset.constant(w).output(0),
ov_opset.constant(v).output(0),
)
return (
OpenVINOKerasTensor(ov_opset.constant(w).output(0)),
OpenVINOKerasTensor(ov_opset.constant(v).output(0)),
)
References
  1. According to the Keras API design guidelines, objects that perform similar functions should have consistent APIs. Other linear algebra functions in this backend return OpenVINOKerasTensor instances, and eigh should follow this pattern for consistency. (link)

Copy link
Contributor

@goyaladitya05 goyaladitya05 Mar 11, 2026

Choose a reason for hiding this comment

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

Please address the gemini reviews given here.



def inv(a):
Expand Down
Loading