Skip to content

[OpenVINO] Fix dynamic/symbolic shape handling in get_ov_output and broadcast_to#22692

Merged
hertschuh merged 6 commits intokeras-team:masterfrom
goyaladitya05:openvino/dynamic-shape-handling
Apr 20, 2026
Merged

[OpenVINO] Fix dynamic/symbolic shape handling in get_ov_output and broadcast_to#22692
hertschuh merged 6 commits intokeras-team:masterfrom
goyaladitya05:openvino/dynamic-shape-handling

Conversation

@goyaladitya05
Copy link
Copy Markdown
Contributor

Description

When ops.shape() is called on a tensor with dynamic dimensions, it returns a tuple where unknown dims are OpenVINOKerasTensor scalars rather than Python ints. Any downstream op receiving this tuple as a shape argument would fail because get_ov_output's list/tuple branch unconditionally called ov_opset.constant(x), which internally calls np.array() on each element, triggering the symbolic tensor's __array__ guard:

RuntimeError: An OpenVINOKerasTensor is symbolic: it's a placeholder for a shape and a dtype.

My fix for this:
get_ov_output: When the input list/tuple contains any OpenVINOKerasTensor or ov.Output element, build the shape tensor dynamically, convert each element to a rank-1 [1] output (scalar dims are reshaped, static ints become constant([v])), align dtypes, then concat along axis 0. All-static lists continue through the existing ov_opset.constant path.

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.

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 enhances the OpenVINO backend's get_ov_output function to handle lists containing symbolic tensors, enabling support for dynamic shapes in operations like broadcast_to. Consequently, several dynamic shape tests have been re-enabled. Feedback focuses on improving the robustness of the type checking to include KerasVariable and Tensor, and simplifying the logic by using recursive calls to get_ov_output for individual list elements.

Comment thread keras/src/backend/openvino/core.py Outdated
Comment thread keras/src/backend/openvino/core.py Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.95%. Comparing base (d51c980) to head (eac3a3b).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
keras/src/backend/openvino/core.py 68.42% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #22692   +/-   ##
=======================================
  Coverage   82.94%   82.95%           
=======================================
  Files         596      596           
  Lines       69200    69272   +72     
  Branches    10806    10821   +15     
=======================================
+ Hits        57399    57465   +66     
- Misses       8973     8976    +3     
- Partials     2828     2831    +3     
Flag Coverage Δ
keras 82.77% <71.42%> (+<0.01%) ⬆️
keras-jax 58.70% <9.52%> (-0.06%) ⬇️
keras-numpy 54.55% <0.00%> (-0.06%) ⬇️
keras-openvino 59.43% <71.42%> (+0.04%) ⬆️
keras-tensorflow 60.27% <9.52%> (-0.05%) ⬇️
keras-torch 59.04% <9.52%> (-0.07%) ⬇️

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 17, 2026 16:45
@goyaladitya05 goyaladitya05 marked this pull request as ready for review April 18, 2026 07:24
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 for the fix!

@google-ml-butler google-ml-butler Bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Apr 20, 2026
@hertschuh hertschuh merged commit e5c9a6e into keras-team:master Apr 20, 2026
9 checks passed
@goyaladitya05 goyaladitya05 deleted the openvino/dynamic-shape-handling branch April 21, 2026 03:13
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.

4 participants