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
@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    30429   +17     
========================================
+ Hits         28180    28197   +17     
  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.

@chun-wan chun-wan force-pushed the fix/concat-dyn-expand-wildcard branch from 2e90081 to 4d15ef9 Compare June 1, 2026 13:08
@causten causten requested review from kahmed10 and shivadbhavsar June 1, 2026 15:14
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. Concatenating such a tensor with one carrying a real dynamic range
(e.g. a {1, 1000} batch dim) crashed compile in two places:

1. Parse time: concat's all-dynamic branch required non-concat axes to
   match exactly, so {0, SIZE_MAX} != {1, 1000} threw
   "CONCAT: all input dimensions should match in axis N".
2. Pipeline time: split_single_dyn_dim specialises one concat input to a
   static shape while the Expand output is still dynamic, so concat then
   saw a static/dynamic mix and threw "Cannot mix static and dynamic
   input shapes" -- before simplify_dyn_ops could constant-fold the
   Expand into a static multibroadcast.

Fix: in concat's dynamic path, treat {0, SIZE_MAX} as a wildcard that
matches any dim on a non-concat axis (adopting that dim's constraint);
two genuinely-different concrete dynamic dims still throw. On the concat
axis, an unconstrained input yields an unconstrained sum rather than
overflowing SIZE_MAX. Static/dynamic mixes are reconciled by promoting
the static inputs to fixed dynamic dims and running the same logic,
instead of hard-failing. After the program is fully specialised the
exact shape is recovered.

Adds op_shape regression tests test_dyn_concat_unconstrained and
test_dyn_concat_mixed_static_dynamic. Verified end-to-end: an
Expand-on-dynamic + concat model compiles on both the ref and GPU
pipelines and evaluates correctly at batch 1/64/1024; full
test_op_shape_test passes.
@chun-wan chun-wan force-pushed the fix/concat-dyn-expand-wildcard branch from 4d15ef9 to dce30ef Compare June 1, 2026 18:04
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