Skip to content

Update handling for empty tensors - #5384

Open
CharlieL7 wants to merge 10 commits into
developfrom
split/empty-tensor-core
Open

CharlieL7 wants to merge 10 commits into
developfrom
split/empty-tensor-core

Conversation

@CharlieL7

Copy link
Copy Markdown
Collaborator

Motivation

  • We get empty tensors (tensors with a zero dimension) through the data-dependent operators. Need to handle them through the MIGraphX run.

Technical Details

  • Have common broadcast dimension select the other dimension if one of them is zero.
  • Short-circuit reshape for zero tensor.
  • Updated permutation to account for zero dimension not leading to a reordering of the strides.
  • simplify_reshapes short-circuit find_gather for zero tensor indices.
  • verify_args for empty tensors just check shape.

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.

Follow the LLVM AI Tool Use Policy for contributions using AI.

@CharlieL7
CharlieL7 marked this pull request as ready for review October 14, 2026 21:57
@CharlieL7
CharlieL7 requested a review from causten as a code owner October 14, 2026 21:57
@CharlieL7
CharlieL7 requested review from TedThemistokleous and kahmed10 and a balanced review from Copilot October 14, 2026 21:57
Comment thread test/verify_args.cpp
Comment on lines +68 to +72
auto result = migraphx::verify_args(
"empty shape mismatch",
migraphx::argument{target_shape, nullptr},
migraphx::verify::expected{migraphx::argument{ref_shape, nullptr}},
migraphx::verify::tolerance{1e-3});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[format.py] reported by reviewdog 🐶

Suggested change
auto result = migraphx::verify_args(
"empty shape mismatch",
migraphx::argument{target_shape, nullptr},
migraphx::verify::expected{migraphx::argument{ref_shape, nullptr}},
migraphx::verify::tolerance{1e-3});
auto result =
migraphx::verify_args("empty shape mismatch",
migraphx::argument{target_shape, nullptr},
migraphx::verify::expected{migraphx::argument{ref_shape, nullptr}},
migraphx::verify::tolerance{1e-3});

Comment thread test/verify_args.cpp
Comment on lines +82 to +86
auto result = migraphx::verify_args(
"empty type mismatch",
migraphx::argument{target_shape, nullptr},
migraphx::verify::expected{migraphx::argument{ref_shape, nullptr}},
migraphx::verify::tolerance{1e-3});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[format.py] reported by reviewdog 🐶

Suggested change
auto result = migraphx::verify_args(
"empty type mismatch",
migraphx::argument{target_shape, nullptr},
migraphx::verify::expected{migraphx::argument{ref_shape, nullptr}},
migraphx::verify::tolerance{1e-3});
auto result =
migraphx::verify_args("empty type mismatch",
migraphx::argument{target_shape, nullptr},
migraphx::verify::expected{migraphx::argument{ref_shape, nullptr}},
migraphx::verify::tolerance{1e-3});

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved issues include a debug assertion failure, incorrect compound-symbolic permutation rejection, and unwritten verification error output.

3 open findings
What changed in this PR

Improves MIGraphX handling of zero-element tensors produced by data-dependent operators.

Changes:

  • Updates broadcasting, reshape execution, and gather simplification for empty tensors.
  • Adjusts symbolic permutation checks and empty-argument verification.
  • Adds regression tests for these behaviors.
File Description
test/​verify_args.cpp Tests empty-argument comparisons.
test/​simplify_reshapes_test.cpp Adds a zero-output gather regression.
test/​shape_test.cpp Tests symbolic zero-extent permutations.
test/​ref/​reshape.cpp Tests empty reshape execution.
test/​ref/​multibroadcast.cpp Tests empty broadcasting execution.
test/​op_shape_test.cpp Tests zero-extent shape inference.
src/​verify_args.cpp Adds shape-based empty comparisons.
src/​simplify_reshapes.cpp Guards empty gather indices.
src/​permutation.cpp Restricts ordering checks to nonempty layouts.
src/​include/​migraphx/​op/​reshape.hpp Short-circuits empty reshape copies.
src/​common.cpp Preserves zero extents during broadcasting.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/permutation.cpp
Comment on lines +75 to +76
else if(sym::to<int64_t>(bounds.min) == 0)
nonzero_dim_bounds.emplace(dd.sym_expr, sym::interval{int64_t{1}, bounds.max});
Comment thread src/simplify_reshapes.cpp
Comment on lines +1450 to +1451
if(indices.empty())
return std::nullopt;
Comment thread src/verify_args.cpp
Comment on lines +79 to +80
if(auto empty_result = verify_empty_args(name, t_arg, r_arg))
return *empty_result;

This branch has not been deployed

No deployments
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.

2 participants