Skip to content

Conversation

DeepC004
Copy link

@DeepC004 DeepC004 commented Mar 15, 2025

Adds numpy.logaddexp function to OpenVino backend. Fixes 29489

Copy link

google-cla bot commented Mar 15, 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 Mar 15, 2025

Codecov Report

❌ Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.44%. Comparing base (6e688ab) to head (271fb9a).
⚠️ Report is 211 commits behind head on master.

Files with missing lines Patch % Lines
keras/src/backend/openvino/numpy.py 0.00% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21043      +/-   ##
==========================================
- Coverage   82.47%   82.44%   -0.04%     
==========================================
  Files         563      563              
  Lines       53834    53857      +23     
  Branches     8359     8362       +3     
==========================================
+ Hits        44401    44402       +1     
- Misses       7392     7414      +22     
  Partials     2041     2041              
Flag Coverage Δ
keras 82.26% <0.00%> (-0.04%) ⬇️
keras-jax 63.77% <0.00%> (-0.03%) ⬇️
keras-numpy 58.73% <0.00%> (-0.03%) ⬇️
keras-openvino 32.70% <0.00%> (-0.02%) ⬇️
keras-tensorflow 64.09% <0.00%> (-0.03%) ⬇️
keras-torch 63.80% <0.00%> (-0.03%) ⬇️

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.

Comment on lines 856 to 866
x1 = get_ov_output(x1, element_type)
x2 = get_ov_output(x2, element_type)
x1, x2 = _align_operand_types(x1, x2, "logaddexp()")
x_type = x1.get_element_type()
if x_type.is_integral():
ov_type = OPENVINO_DTYPES[config.floatx()]
x1 = ov_opset.convert(x1, ov_type)
x2 = ov_opset.convert(x2, ov_type)
exp_x1 = ov_opset.exp(x1).output(0)
exp_x2 = ov_opset.exp(x2).output(0)
sum_exp = ov_opset.add(exp_x1, exp_x2).output(0)
Copy link
Contributor

@rkazants rkazants Mar 16, 2025

Choose a reason for hiding this comment

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

I propose to make it more numerical stable for big x1 and x2 numbers:

ln(e^x1 + e^x2) = ln (e^k(e^(x1-k) + e^(x2-k))) = k ln (e^(x1-k) + e^(x2-k)), where k is maximum from x1 and x2. pay attention that by this trick x1-k and x2-k will be less than one that provides more compute stable for exponent that outputs non-negative value less than one that is better represented for floating point.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch on compute stability. I have made the changes

@@ -848,9 +848,23 @@ def log2(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 switch on tests for this functionality.

Copy link
Author

Choose a reason for hiding this comment

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

In issue you mentioned ./keras/src/ops/numpy_test.py for testing. I initially thought that tests automatically invoke the numpy from correct backend. But on tracking knp imports in numpy_test file they seem to come from ./keras/src/backend/numpy module instead of openvino. I verify this by executing tests without implementing logaddexp() and they PASSED (a number of other unimplemented functions inside ./keras/src/backend/openvino/numpy.py also pass). What should I change exactly to test the function in current test setup?

Copy link
Contributor

Choose a reason for hiding this comment

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

please rebase to latest master and you will see corresponding lines for logaddexp

@hertschuh
Copy link
Collaborator

@rkazants

Can you decide between this PR and #21522 ?

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.

[Good First Issue][Keras 3 OpenVINO Backend]: Support numpy.logaddexp operation
6 participants