Skip to content

[SWDEV-587978] Fix simplify reshapes error for thm models#4894

Open
urpetkov-amd wants to merge 6 commits into
developfrom
fix_simplify_reshapes_thm
Open

[SWDEV-587978] Fix simplify reshapes error for thm models#4894
urpetkov-amd wants to merge 6 commits into
developfrom
fix_simplify_reshapes_thm

Conversation

@urpetkov-amd
Copy link
Copy Markdown
Collaborator

Motivation

Compiling certain optical-flow models on GPU fails inside simplify_reshapes with:

Error simplify_reshapes: same_dims: add: Dimensions do not match

This affects models where find_gather rewrites a gather whose output is later expanded by a multibroadcast on the same axis the slice operates on. The existing axis-multiplicity guard in find_slice_shape_transforms (added in #4728 for claa models) does not catch this case.

Technical Details

In find_slice_shape_transforms::apply, after desc.rebase(slice.in.lens) the rebased descriptor can silently absorb a 1 → N multibroadcast on the sliced axis (because the slice input is no longer singleton on that axis). The pass then emits a slice with the wrong output shape and the next pointwise op fails its same_dims check.

Added one extra invariant in the same guard style as the existing check: for each sliced axis the rebased dst-axis length must scale by slice_input_len / slice_output_len relative to the original ins output length. If it does not, the rewrite would change the output shape, so we bail to the existing safe path that is already used for the axis-split case.

Added regression test TEST_CASE(slice_multibroadcast_over_sliced_axis) in test/simplify_reshapes_test.cpp that reproduces the exact pattern produced by find_gather on the affected model and asserts get_output_shapes is preserved. Complements the existing slice_reshape_multibroadcast_rebase_axis test from #4728 which covers the orthogonal "axis split" case.

Changelog Category

  • 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.

@urpetkov-amd urpetkov-amd requested a review from causten as a code owner May 19, 2026 12:59
@urpetkov-amd urpetkov-amd changed the title Fix simplify reshapes error for thm models [SWDEV-587978] Fix simplify reshapes error for thm models May 19, 2026
urpetkov-amd and others added 3 commits May 19, 2026 15:13
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Comment thread test/simplify_reshapes_test.cpp
@urpetkov-amd urpetkov-amd requested a review from pfultz2 May 19, 2026 14:34
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4894   +/-   ##
========================================
  Coverage    92.88%   92.88%           
========================================
  Files          587      587           
  Lines        30331    30335    +4     
========================================
+ Hits         28170    28174    +4     
  Misses        2161     2161           
Files with missing lines Coverage Δ
src/simplify_reshapes.cpp 97.96% <100.00%> (+0.01%) ⬆️
🚀 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.

3 participants