Skip to content

[OpenVINO backend] Support for numpy.eigh #22363

Open
andersendsa wants to merge 3 commits intokeras-team:masterfrom
andersendsa:openvino-eigh
Open

[OpenVINO backend] Support for numpy.eigh #22363
andersendsa wants to merge 3 commits intokeras-team:masterfrom
andersendsa:openvino-eigh

Conversation

@andersendsa
Copy link
Contributor

@andersendsa andersendsa commented Mar 5, 2026

Details :

Implement numpy.eigh operation for the OpenVINO backend.

Closes issue : openvinotoolkit/openvino#34520

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces support for the numpy.eigh operation within the OpenVINO backend. This enhancement allows users to perform symmetric/Hermitian eigenvalue decomposition on static eager tensors, expanding the linear algebra capabilities available in the OpenVINO integration.

Highlights

  • OpenVINO Backend eigh Implementation: The eigh function, which computes the eigenvalues and eigenvectors of a symmetric or Hermitian matrix, has been implemented for the OpenVINO backend.
  • Test Exclusion Removal: The LinalgOpsCorrectnessTest::test_eigh entry was removed from the excluded_concrete_tests.txt file, indicating that the test is now expected to pass.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • keras/src/backend/openvino/excluded_concrete_tests.txt
    • Removed LinalgOpsCorrectnessTest::test_eigh from the list of excluded tests.
  • keras/src/backend/openvino/linalg.py
    • Implemented the eigh function to compute eigenvalues and eigenvectors.
    • Added logic to convert input tensors to NumPy arrays, perform np.linalg.eigh, and convert results back to OpenVINO constants.
    • Included error handling for dynamic or symbolic tensors, restricting eigh to static eager tensors.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for numpy.eigh to the OpenVINO backend by providing a NumPy-based implementation for eager tensors. The approach is sound, and the error handling for symbolic tensors is appropriate. My review includes a suggestion to ensure the return type is consistent with other backend operations by wrapping the output in OpenVINOKerasTensor instances, which is crucial for maintaining the backend's abstraction layer.

Comment on lines +57 to +60
return (
ov_opset.constant(w).output(0),
ov_opset.constant(v).output(0),
)
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.

@codecov-commenter
Copy link

codecov-commenter commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 11.11111% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.01%. Comparing base (95e74a9) to head (67e1afc).
⚠️ Report is 35 commits behind head on master.

Files with missing lines Patch % Lines
keras/src/backend/openvino/linalg.py 11.11% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22363      +/-   ##
==========================================
+ Coverage   82.95%   83.01%   +0.05%     
==========================================
  Files         595      596       +1     
  Lines       66040    66702     +662     
  Branches    10305    10383      +78     
==========================================
+ Hits        54785    55373     +588     
- Misses       8639     8692      +53     
- Partials     2616     2637      +21     
Flag Coverage Δ
keras 82.84% <11.11%> (+0.05%) ⬆️
keras-jax 60.54% <11.11%> (-0.30%) ⬇️
keras-numpy 54.77% <0.00%> (-0.26%) ⬇️
keras-openvino 49.91% <11.11%> (+0.80%) ⬆️
keras-tensorflow 61.78% <11.11%> (-0.28%) ⬇️
keras-torch 60.61% <11.11%> (-0.27%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andersendsa
Copy link
Contributor Author

hi @hertschuh this pr passes all the tests and is ready for review

Comment on lines +57 to +60
return (
ov_opset.constant(w).output(0),
ov_opset.constant(v).output(0),
)
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.

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


a = convert_to_tensor(a)
try:
a_np = convert_to_numpy(a)
Copy link
Contributor

Choose a reason for hiding this comment

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

We do the implementations using OpenVINO opsets specifically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will change it asap

@andersendsa
Copy link
Contributor Author

andersendsa commented Mar 12, 2026

hi @hertschuh i have done the changes and the pr passes all the tests and is ready for review

Comment on lines +57 to +65
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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants