[OpenVINO] Fix dynamic/symbolic shape handling in get_ov_output and broadcast_to#22692
Conversation
There was a problem hiding this comment.
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.
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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: