Skip to content

parse_where: broadcast dynamic ternary inputs via add_common_op#4925

Open
chun-wan wants to merge 1 commit into
ROCm:developfrom
chun-wan:fix/parse-where-dyn-broadcast
Open

parse_where: broadcast dynamic ternary inputs via add_common_op#4925
chun-wan wants to merge 1 commit into
ROCm:developfrom
chun-wan:fix/parse-where-dyn-broadcast

Conversation

@chun-wan
Copy link
Copy Markdown

The ONNX Where parser had a long-standing limitation: for all-dynamic inputs it inserted the where op directly with no broadcasting and threw outright on a static/dynamic mix. That meant a dynamic Where whose inputs were not already identically shaped (e.g. one input is a broadcast_with_dims / ONNX Expand output {0, SIZE_MAX}) failed at parse with "same_dims: where: Dimensions do not match".

Route the three inputs through add_common_op (common_type=false so the bool condition and the data-type branches keep their own types), exactly as binary ops already do. This handles static, dynamic, and mixed inputs uniformly; the dynamic path goes through compute_common_dyn_dims so unconstrained inputs intersect with their peers instead of requiring an exact shape match. A fast path keeps the common same-dims case (including all-dynamic identical shapes) as a bare where op, so existing IR is unchanged there.

Tests:

  • where_test (static broadcast) and where_dyn_test (identical dynamic): unchanged, still pass.
  • where_mixed_test: previously asserted "throws"; now asserts the mixed static+dynamic inputs broadcast to the expected {3,2,2} result. Full test_onnx_test (882 cases) and ref where verify tests pass.

Motivation

Technical Details

Changelog Category

Add a CHANGELOG.md entry for any option other than Not Applicable

    • Added: New functionality.
    • Changed: Changes to existing functionality.
    • Removed: Functionality or support that has been removed. (Compared to a previous release)
    • Optimized: Component performance that has been optimized or improved.
    • Resolved Issues: Known issues from a previous version that have been resolved.
    • Not Applicable: This PR is not to be included in the changelog.

@chun-wan chun-wan requested a review from causten as a code owner May 30, 2026 04:55
The ONNX Where parser had a long-standing limitation: for all-dynamic
inputs it inserted the where op directly with no broadcasting and threw
outright on a static/dynamic mix. That meant a dynamic Where whose
inputs were not already identically shaped (e.g. one input is a
broadcast_with_dims / ONNX Expand output {0, SIZE_MAX}) failed at parse
with "same_dims: where: Dimensions do not match".

Route the three inputs through add_common_op (common_type=false so the
bool condition and the data-type branches keep their own types), exactly
as binary ops already do. This handles static, dynamic, and mixed inputs
uniformly; the dynamic path goes through compute_common_dyn_dims so
unconstrained inputs intersect with their peers instead of requiring an
exact shape match. A fast path keeps the common same-dims case (including
all-dynamic identical shapes) as a bare where op, so existing IR is
unchanged there.

Tests:
- where_test (static broadcast) and where_dyn_test (identical dynamic):
  unchanged, still pass.
- where_mixed_test: previously asserted "throws"; now asserts the mixed
  static+dynamic inputs broadcast to the expected {3,2,2} result.
Full test_onnx_test (882 cases) and ref where verify tests pass.
@chun-wan chun-wan force-pushed the fix/parse-where-dyn-broadcast branch from e0502d3 to 72ae166 Compare May 30, 2026 05:00
@chun-wan chun-wan requested a review from a team as a code owner May 30, 2026 05:00
@chun-wan chun-wan force-pushed the fix/parse-where-dyn-broadcast branch from 72ae166 to 3c1ae00 Compare May 30, 2026 05:03
@codecov
Copy link
Copy Markdown

codecov Bot commented May 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4925      +/-   ##
===========================================
- Coverage    92.66%   92.66%   -0.00%     
===========================================
  Files          588      588              
  Lines        30412    30402      -10     
===========================================
- Hits         28180    28170      -10     
  Misses        2232     2232              
Files with missing lines Coverage Δ
src/onnx/parse_where.cpp 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant