Skip to content

[OpenVINO] Implement logdet op#22673

Draft
goyaladitya05 wants to merge 6 commits intokeras-team:masterfrom
goyaladitya05:openvino/logdet
Draft

[OpenVINO] Implement logdet op#22673
goyaladitya05 wants to merge 6 commits intokeras-team:masterfrom
goyaladitya05:openvino/logdet

Conversation

@goyaladitya05
Copy link
Copy Markdown
Contributor

Description

This PR implements logdet op for the OpenVINO backend. Since there does not exist a not a native op for this in the currently available ov opsets and the implementation would require decomposition similar to slogdet, so we delegate to slogdet for now.

Closes: openvinotoolkit/openvino/issues/35312

Contributor Agreement

Please check all boxes below before submitting your PR for review:

  • I am a human, and not a bot.
  • I will be responsible for responding to review comments in a timely manner.
  • I will work with the maintainers to push this PR forward until submission.

Note: Failing to adhere to this agreement may result in your future PRs no longer being reviewed.

Copy link
Copy Markdown
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 implements the logdet function for the OpenVINO backend and enables its associated correctness tests. A logic error was identified in the implementation: logdet currently returns the logarithm of the absolute value of the determinant, whereas it should follow the mathematical definition of log(det(x)), returning NaN for tensors with a negative determinant.

@goyaladitya05
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
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 implements the logdet operation for the OpenVINO backend and enables its corresponding correctness tests. The implementation utilizes slogdet and handles negative determinants by returning NaN. A review comment highlights that the current implementation is not robust to dynamic shapes because the underlying slogdet function uses a Python loop over matrix dimensions, which will fail if the inner dimensions are not statically known.

Comment on lines +174 to +184
def logdet(x):
# OpenVINO does not have a direct logdet op
# Can be modified when there is a native op in ov_opset
from keras.src.backend.openvino.numpy import slogdet

sign, logabsdet = slogdet(x)
neg_det = sign < 0
# When determinant is negative return NaN instead of the log-abs value.
nan_value = convert_to_tensor(np.nan, dtype=logabsdet.dtype)

return select([neg_det], [nan_value], default=logabsdet)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The logdet implementation relies on slogdet from keras.src.backend.openvino.numpy. While this is a reasonable fallback given the lack of a native OpenVINO op, the current implementation of slogdet in this backend (lines 5255-5448 of numpy.py) uses a Python loop over the matrix dimension n. This means logdet will only work for matrices with a statically known inner dimension. If x has a dynamic shape for its last two dimensions, slogdet will raise an exception at line 5275. While this might be an existing limitation of the backend's linear algebra support, it's worth noting that this implementation is not fully robust to dynamic shapes.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.93%. Comparing base (e6cde21) to head (1c98908).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #22673   +/-   ##
=======================================
  Coverage   82.93%   82.93%           
=======================================
  Files         596      596           
  Lines       69083    69091    +8     
  Branches    10803    10803           
=======================================
+ Hits        57291    57300    +9     
  Misses       8967     8967           
+ Partials     2825     2824    -1     
Flag Coverage Δ
keras 82.75% <100.00%> (+<0.01%) ⬆️
keras-jax 58.86% <37.50%> (-0.01%) ⬇️
keras-numpy 54.69% <0.00%> (-0.01%) ⬇️
keras-openvino 59.33% <100.00%> (+<0.01%) ⬆️
keras-tensorflow 60.42% <37.50%> (-0.01%) ⬇️
keras-torch 59.20% <37.50%> (-0.01%) ⬇️

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.

@goyaladitya05 goyaladitya05 marked this pull request as draft April 15, 2026 01:35
Copy link
Copy Markdown
Collaborator

@hertschuh hertschuh left a comment

Choose a reason for hiding this comment

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

Thanks!

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Apr 15, 2026
@google-ml-butler google-ml-butler bot removed the ready to pull Ready to be merged into the codebase label Apr 15, 2026
Copy link
Copy Markdown
Collaborator

@hertschuh hertschuh left a comment

Choose a reason for hiding this comment

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

Thanks!

@google-ml-butler google-ml-butler bot added the ready to pull Ready to be merged into the codebase label Apr 15, 2026
@hertschuh
Copy link
Copy Markdown
Collaborator

This is marked as draft, is it ready to merge?

@goyaladitya05
Copy link
Copy Markdown
Contributor Author

This is marked as draft, is it ready to merge?

Hi @hertschuh,
let's hold this for a while, as it will need modifications after the merge of #22678. I'll also be addressing #22678 (comment) in this PR.

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

Labels

kokoro:force-run ready to pull Ready to be merged into the codebase size:S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Keras 3 OpenVINO backend] Support logdet operation

4 participants