symbolic reshape ops#4977
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #4977 +/- ##
===========================================
- Coverage 92.69% 92.67% -0.02%
===========================================
Files 596 596
Lines 31603 31655 +52
===========================================
+ Hits 29292 29334 +42
- Misses 2311 2321 +10
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR extends shape inference for reshape-like operators to support symbolic (migraphx::sym) dimensions, enabling symbolic computation in compute_shape() for flatten, reshape/reshape_lazy, squeeze, and unsqueeze.
Changes:
- Add symbolic shape inference paths for
flatten,reshape/reshape_lazy,squeeze, andunsqueeze(preserving layout where possible). - Generalize
reshape_dims()to operate onsym::exprand add helpers to resolve/validate reshapedims(including 0 and -1 semantics) for symbolic inputs. - Add extensive unit tests covering symbolic reshape/flatten/squeeze/unsqueeze shape inference and stride/layout behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/op_shape_test.cpp | Adds test coverage for symbolic shape inference across flatten/reshape/squeeze/unsqueeze. |
| src/reshape_dims.cpp | Implements symbolic-aware reshape_dims plus helpers to resolve/validate symbolic reshape dims. |
| src/include/migraphx/reshape_dims.hpp | Exposes new symbolic reshape helpers and updates reshape_dims signature to sym::expr. |
| src/include/migraphx/op/unsqueeze.hpp | Adds unified symbolic/static shape inference path for unsqueeze (including symbolic strides). |
| src/include/migraphx/op/squeeze.hpp | Adds unified symbolic/static shape inference path for squeeze with stride preservation. |
| src/include/migraphx/op/reshape.hpp | Switches static handling to symbolic resolution; attempts to preserve layout via reshape_dims. |
| src/include/migraphx/op/reshape_lazy.hpp | Switches static handling to symbolic resolution and uses reshape_dims in lazy mode. |
| src/include/migraphx/op/flatten.hpp | Adds symbolic flatten shape inference path. |
| src/include/migraphx/dim_like.hpp | Adds is_symbolic(dim_like) helper used by reshape validation/resolution. |
Check flagged results 🔆 * No develop baseline was found for this PR's branch point; compared against the latest available develop run instead. |
|
| return not *x_lt; | ||
| }); | ||
| if(x != dim) | ||
| if(indeterminate or x != dim) |
There was a problem hiding this comment.
I think this should use same_value instead of x != dim.
| return nullopt; | ||
| // Broadcasted check to avoid division by zero | ||
| if(stride2 == 0) | ||
| if(stride2 == zero) |
There was a problem hiding this comment.
I think these equality comparisons should use same_value because it might come from a variable with constraints.
There was a problem hiding this comment.
do you mean same_symbol?
| auto n = it - start; | ||
| assert((r + n) <= rdims.size()); | ||
| auto stride = istrides[i] * idim; | ||
| std::for_each(start, it + 1, [&](auto dim) { |
There was a problem hiding this comment.
We need to add sym::expr to the AllowedTypes for copying in the .clang-tidy config.
Motivation
Allow symbolic computation in compute_shapes for reshape ops
Technical Details
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot Applicable