Skip to content

concat: treat fully-unconstrained dynamic dim as a wildcard#4924

Open
chun-wan wants to merge 1 commit into
ROCm:developfrom
chun-wan:fix/concat-dyn-expand-wildcard
Open

concat: treat fully-unconstrained dynamic dim as a wildcard#4924
chun-wan wants to merge 1 commit into
ROCm:developfrom
chun-wan:fix/concat-dyn-expand-wildcard

Conversation

@chun-wan
Copy link
Copy Markdown

broadcast_with_dims (ONNX Expand) whose target shape is only known at runtime emits a fully-unconstrained dynamic dim {0, SIZE_MAX} on every axis. When such a tensor was concatenated with a tensor carrying a real dynamic range (e.g. a {1, 1000} batch dim), concat::normalize_compute_shape threw "CONCAT: all input dimensions should match in axis N" at parse time -- before split_single_dyn_dim / simplify_dyn_ops had a chance to constant-fold the Expand into a static multibroadcast -- crashing compile on otherwise-valid dynamic-shape models.

Fix: in the all-dynamic branch of concat, treat {0, SIZE_MAX} as a wildcard. On non-concat axes it matches any dim and adopts that dim's constraint; two genuinely-different concrete dynamic dims still throw. On the concat axis, if any input is unconstrained the summed dim is emitted as a wildcard rather than overflowing SIZE_MAX. After the program is specialised the Expand folds to a static multibroadcast and the exact shape is recovered.

Adds op_shape regression test test_dyn_concat_unconstrained. Reproduced the original crash and verified the fix end-to-end (Expand-on-dynamic + concat ONNX model compiles for the ref target); full test_op_shape_test (512 cases) passes.

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:54
broadcast_with_dims (ONNX Expand) whose target shape is only known at
runtime emits a fully-unconstrained dynamic dim {0, SIZE_MAX} on every
axis. When such a tensor was concatenated with a tensor carrying a real
dynamic range (e.g. a {1, 1000} batch dim), concat::normalize_compute_shape
threw "CONCAT: all input dimensions should match in axis N" at parse time
-- before split_single_dyn_dim / simplify_dyn_ops had a chance to
constant-fold the Expand into a static multibroadcast -- crashing compile
on otherwise-valid dynamic-shape models.

Fix: in the all-dynamic branch of concat, treat {0, SIZE_MAX} as a
wildcard. On non-concat axes it matches any dim and adopts that dim's
constraint; two genuinely-different concrete dynamic dims still throw.
On the concat axis, if any input is unconstrained the summed dim is
emitted as a wildcard rather than overflowing SIZE_MAX. After the program
is specialised the Expand folds to a static multibroadcast and the exact
shape is recovered.

Adds op_shape regression test test_dyn_concat_unconstrained. Reproduced
the original crash and verified the fix end-to-end (Expand-on-dynamic +
concat ONNX model compiles for the ref target); full test_op_shape_test
(512 cases) passes.
@chun-wan chun-wan force-pushed the fix/concat-dyn-expand-wildcard branch from acd0d1e to 2e90081 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
@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    #4924   +/-   ##
========================================
  Coverage    92.66%   92.66%           
========================================
  Files          588      588           
  Lines        30412    30422   +10     
========================================
+ Hits         28180    28190   +10     
  Misses        2232     2232           
Files with missing lines Coverage Δ
src/include/migraphx/op/concat.hpp 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