Skip to content

Added openvino backend support for numpy.median (Issue #30115) #21379

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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

alungriffith
Copy link

Added decomposition for numpy.median using OpenVINO backend.

Copy link

google-cla bot commented Jun 13, 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.

@codecov-commenter
Copy link

codecov-commenter commented Jun 13, 2025

Codecov Report

Attention: Patch coverage is 79.36508% with 13 lines in your changes missing coverage. Please review.

Project coverage is 77.19%. Comparing base (e4bca84) to head (0eeaa5e).
Report is 32 commits behind head on master.

Files with missing lines Patch % Lines
keras/src/backend/openvino/numpy.py 79.36% 9 Missing and 4 partials ⚠️

❗ There is a different number of reports uploaded between BASE (e4bca84) and HEAD (0eeaa5e). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (e4bca84) HEAD (0eeaa5e)
keras 5 4
keras-torch 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21379      +/-   ##
==========================================
- Coverage   82.67%   77.19%   -5.48%     
==========================================
  Files         565      565              
  Lines       55064    55559     +495     
  Branches     8569     8670     +101     
==========================================
- Hits        45525    42891    -2634     
- Misses       7441    10605    +3164     
+ Partials     2098     2063      -35     
Flag Coverage Δ
keras 77.11% <79.36%> (-5.38%) ⬇️
keras-jax 63.33% <0.00%> (-0.17%) ⬇️
keras-numpy 58.54% <0.00%> (-0.14%) ⬇️
keras-openvino 33.76% <79.36%> (+0.31%) ⬆️
keras-tensorflow 63.78% <0.00%> (-0.13%) ⬇️
keras-torch ?

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.

@gbaned gbaned requested a review from mattdangerw June 16, 2025 10:33
@gbaned gbaned added this to PR Queue Jun 16, 2025
@github-project-automation github-project-automation bot moved this to Assigned Reviewer in PR Queue Jun 16, 2025
@alungriffith
Copy link
Author

@rkazants PR is ready for review.

Apologies for all the commits, it took me a second to fix my local testing to run on openvino backend on macOS.

@alungriffith alungriffith changed the title Median support ov Added openvino backend support for numpy.median (Issue #30115) Jun 21, 2025
@divyashreepathihalli
Copy link
Collaborator

/gemini review

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.median to the OpenVINO backend. The implementation handles scenarios for the axis and keepdims parameters. A critical bug was identified in the logic for handling multiple reduction axes, making that code path unreachable. Additionally, high-severity issues were found where the code relies on static shape information, leading to failures with dynamic input shapes. Suggestions have been provided to address these points and improve robustness.

@alungriffith
Copy link
Author

/gemini review

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

The code changes introduce OpenVINO backend support for numpy.median. There is a high severity issue in the logic for flattening axes within the median function that needs to be addressed, as well as a medium-severity suggestion to improve the code's correctness.

@alungriffith
Copy link
Author

/gemini review

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.median for the OpenVINO backend. The implementation is comprehensive, handling various cases for axis and keepdims. I've made a few suggestions to improve maintainability by adding comments to complex parts of the logic, and fixed a correctness issue in the ndim function.

@alungriffith
Copy link
Author

/gemini review

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

The pull request adds OpenVINO backend support for the numpy.median function. The implementation involves a complex series of OpenVINO operations to handle different input scenarios and calculate the median. I've suggested adding more comments to improve the code's readability and maintainability, especially around the tensor manipulations and specific OpenVINO operations used.

@alungriffith
Copy link
Author

@mattdangerw PR is ready for review.

Gemini's raised concerns have been addressed, I believe it might be going over old ground with the latest suggestions but I'm happy to add more comments if needed.

The torch test is failing in today's commits but I don't think this is due to my median function updates.

pytest.ini Outdated
Comment on lines 1 to 3
[pytest]
env =
KERAS_BACKEND=openvino
Copy link
Contributor

Choose a reason for hiding this comment

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

please revert

Copy link
Author

Choose a reason for hiding this comment

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

File has been deleted.

if np.isscalar(x):
x = get_ov_output(x)
return OpenVINOKerasTensor(x)

Copy link
Contributor

Choose a reason for hiding this comment

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

please add comments to explain the logic of the algorithm you implemented

Copy link
Author

Choose a reason for hiding this comment

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

Comments added and some variables renamed to better explain the logic.

@alungriffith
Copy link
Author

@rkazants updated with comments and better clarity, ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Assigned Reviewer
Development

Successfully merging this pull request may close these issues.

5 participants