Skip to content

Conversation

@Divyanshu-hash
Copy link

What does this PR do?

This PR adds support for numpy.diagonal in the OpenVINO backend for Keras 3 inference.

The implementation decomposes numpy.diagonal using OpenVINO opset operations and enables the corresponding tests for the OpenVINO backend.

What has been done?

  • Implemented numpy.diagonal in keras/src/backend/openvino/numpy.py
  • Removed the corresponding test exclusion to enable backend coverage
  • Added pytest.ini to ensure tests run with KERAS_BACKEND=openvino

Testing

Tests were run locally with:

KERAS_BACKEND=openvino python -m pytest -c pytest.ini keras/src/ops/numpy_test.py -k diagonal

Some NumpyDtypeTest::test_diagonal failures are due to missing JAX locally; these are expected to pass in CI where JAX is installed.

Related issue
Fixes #29116

CC: @rkazants

@google-cla
Copy link

google-cla bot commented Dec 25, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Divyanshu-hash, 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 significantly enhances the OpenVINO backend for Keras 3 by introducing full support for the numpy.diagonal operation. This integration improves the compatibility of Keras models with OpenVINO for inference, ensuring that models relying on this common NumPy function can be correctly executed. The changes also include updates to the testing infrastructure to validate this new functionality and simplify local testing setup.

Highlights

  • OpenVINO numpy.diagonal Support: Implemented the numpy.diagonal function for the OpenVINO backend, allowing Keras 3 inference to utilize this NumPy operation by decomposing it into OpenVINO opset operations.
  • Test Coverage Enabled: Removed NumpyOneInputOpsCorrectnessTest::test_diagonal from the OpenVINO backend's excluded tests, enabling comprehensive testing for the newly added functionality.
  • Testing Configuration: Introduced a pytest.ini file to automatically set KERAS_BACKEND=openvino for local test runs, streamlining the testing process for the OpenVINO backend.

🧠 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.

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.diagonal to the OpenVINO backend. The implementation correctly uses transpose to align the axes before calling the backend's diagonal operation. The corresponding test is also enabled.

I have two main points of feedback:

  1. The axis normalization in diagonal should be improved to handle out-of-bounds axes correctly, consistent with NumPy's behavior and other functions in the backend.
  2. The addition of pytest.ini at the root level might unintentionally affect the entire test suite by setting the default backend to OpenVINO. This should be reviewed to ensure it doesn't break CI for other backends.

Overall, a good addition to improve OpenVINO backend coverage.

@codecov-commenter
Copy link

codecov-commenter commented Dec 25, 2025

Codecov Report

❌ Patch coverage is 1.09890% with 90 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.67%. Comparing base (7660ee3) to head (b686d69).

Files with missing lines Patch % Lines
keras/src/backend/openvino/numpy.py 1.09% 90 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21952      +/-   ##
==========================================
- Coverage   82.69%   78.67%   -4.02%     
==========================================
  Files         588      588              
  Lines       61369    61413      +44     
  Branches     9612     9622      +10     
==========================================
- Hits        50749    48318    -2431     
- Misses       8135    10728    +2593     
+ Partials     2485     2367     -118     
Flag Coverage Δ
keras 78.51% <1.09%> (-4.01%) ⬇️
keras-jax 61.53% <0.00%> (-0.05%) ⬇️
keras-numpy 56.78% <0.00%> (-0.04%) ⬇️
keras-openvino ?
keras-tensorflow 63.69% <1.09%> (-0.05%) ⬇️
keras-torch 62.44% <1.09%> (-0.05%) ⬇️

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.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants