Skip to content

Sym reshapes#4832

Open
shivadbhavsar wants to merge 15 commits into
developfrom
sym_reshapes
Open

Sym reshapes#4832
shivadbhavsar wants to merge 15 commits into
developfrom
sym_reshapes

Conversation

@shivadbhavsar
Copy link
Copy Markdown
Contributor

Motivation

Refactor reshape ops to use dim-like variant to handle symbolic shapes. This will be required when trying to enable simplification passes for symbolic shapes.

Technical Details

Add dim_like variant that works out of the box for current int64 representation for static shapes but can be extended to dyn_dims for symbolic shapes to allow symbolic target dims.

compute_shape will be modified in a later PR, the purpose here is to just introduce the new variant and ensure it causes no regressions with existing static shape compilation.

Later we would want to use this similarly for other ops such as slice, resize, etc. We can also consider refactoring broadcast ops to consolidate the current dual attribute implementation with out_lens and out_dyn_dims

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.

@shivadbhavsar shivadbhavsar changed the base branch from develop to to_symbolic_helper April 29, 2026 23:20
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 95.12195% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/include/migraphx/op/reshape.hpp 93.33% 1 Missing ⚠️
src/include/migraphx/op/reshape_lazy.hpp 92.31% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4832      +/-   ##
===========================================
- Coverage    92.66%   92.66%   -0.00%     
===========================================
  Files          588      590       +2     
  Lines        30412    30437      +25     
===========================================
+ Hits         28180    28203      +23     
- Misses        2232     2234       +2     
Files with missing lines Coverage Δ
src/dim_like.cpp 100.00% <100.00%> (ø)
src/include/migraphx/dim_like.hpp 100.00% <100.00%> (ø)
src/include/migraphx/picked_variant.hpp 100.00% <ø> (ø)
src/include/migraphx/op/reshape.hpp 98.81% <93.33%> (-1.19%) ⬇️
src/include/migraphx/op/reshape_lazy.hpp 96.92% <92.31%> (-1.41%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from to_symbolic_helper to develop April 30, 2026 17:04
@shivadbhavsar shivadbhavsar requested a review from CharlieL7 May 1, 2026 16:53
@pfultz2
Copy link
Copy Markdown
Collaborator

pfultz2 commented May 5, 2026

I would like to merge in #3753 first which unifies the reshape calculation for both reshape and reshape_lazy and it also propagates the permutation.

Comment thread src/include/migraphx/dim_like.hpp Outdated
@shivadbhavsar shivadbhavsar requested a review from pfultz2 May 20, 2026 22:31
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@shivadbhavsar shivadbhavsar marked this pull request as ready for review May 27, 2026 21:32
@shivadbhavsar shivadbhavsar requested a review from causten as a code owner May 27, 2026 21:32
Copilot AI review requested due to automatic review settings May 27, 2026 21:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new dim_like attribute element type (int64 or shape::dynamic_dimension) and refactors reshape operators to store dims as std::vector<dim_like>, with accompanying serialization support and tests. This is a foundational change to enable future symbolic-shape reshape support without regressing existing static-shape behavior.

Changes:

  • Add migraphx::dim_like (picked-variant) plus to_value/from_value serialization support.
  • Refactor reshape / reshape_lazy ops to use std::vector<dim_like> for dims.
  • Add unit tests for dim_like behavior and update an ONNX reshape parse test accordingly.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
test/onnx/parse/reshape_test.cpp Adjust test to populate reshape::dims with the new dim_like element type.
test/dim_like_test.cpp New unit tests covering construction, equality, streaming, and serialization round-trips for dim_like.
src/include/migraphx/op/reshape.hpp Switch dims to std::vector<dim_like>; update shape inference logic to accommodate the new representation.
src/include/migraphx/op/reshape_lazy.hpp Switch dims to std::vector<dim_like>; update lazy reshape shape inference logic accordingly.
src/include/migraphx/dim_like.hpp New public header defining dim_like, stream support, and serialization declarations.
src/dim_like.cpp Implements dim_like serialization (migraphx_to_value/migraphx_from_value).
src/CMakeLists.txt Adds dim_like.cpp to the core library build.
.gitignore Adds ignores for local caches/venv-related directories.

Comment thread src/include/migraphx/op/reshape.hpp
Comment thread src/include/migraphx/op/reshape.hpp
Comment thread src/include/migraphx/op/reshape_lazy.hpp
Comment thread src/include/migraphx/op/reshape_lazy.hpp
Comment thread src/include/migraphx/op/reshape_lazy.hpp
Comment thread src/include/migraphx/dim_like.hpp Outdated
Comment thread test/dim_like_test.cpp Outdated
Comment thread test/dim_like_test.cpp Outdated
Comment thread src/include/migraphx/dim_like.hpp Outdated

// Templated to hide from ADL on unrelated types: a non-template overload would
// be probed during overload resolution for things like vector<dim_like>, which
// would instantiate Picker::apply(vector<...>) and hard-fail.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update the picked_variant constructor to propagate the substitution failure instead, Picker::apply(vector<...>) is a substitution failure which is fine, but not when using the picked_variant constructor where it becomes a error(the AI says hard-fail which is a really confusing term).

@shivadbhavsar shivadbhavsar requested a review from pfultz2 May 28, 2026 18:10
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.

3 participants