Skip to content

[FIX][TOPI][strided_slice] Fix topi.strided_slice output shape#17502

Merged
Hzfengsy merged 7 commits intoapache:mainfrom
PatrikPerssonInceptron:feature/topi.strided_slice-shape-fix-v2
Nov 12, 2024
Merged

[FIX][TOPI][strided_slice] Fix topi.strided_slice output shape#17502
Hzfengsy merged 7 commits intoapache:mainfrom
PatrikPerssonInceptron:feature/topi.strided_slice-shape-fix-v2

Conversation

@PatrikPerssonInceptron
Copy link
Contributor

Fixed inconsistency between relax.strided_slice output shape and topi.strided_slice output shape when assume_inbound
is set to false.

I added an assume_inbound flag to topi.strided_slice. If it is false then the begin and end indices are canonicalized before the dimension length is calculated. To avoid introducing duplicate code i removed the corresponding functions from relax/../index.cc and instead reference the new functions defined in include/tvm/topi/transform.h.

I added a regression test for the case with assume_inbound = false when the end of the slice is at infinity, e.g. v[begin:], which previously caused an incorrect output shape.

relax.strided_slice given a assume_inbound flag
…is assumed

in the associated unit tests

moved misplaced function description

fixed shape error and added a assume_inbound=True to test_strided_slice_symbolic_sliced_axis

added param description for assume_inbound
Copy link
Member

@Hzfengsy Hzfengsy left a comment

Choose a reason for hiding this comment

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

General LGTM

"""relax.op.strided_slice FLegalize must support dynamic begin/end"""

@I.ir_module
class before:
Copy link
Member

Choose a reason for hiding this comment

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

You can use # fmt: off and # fmt: on to disable black for specific code (e.g. TVMScript)

@Hzfengsy Hzfengsy merged commit 0d5bde5 into apache:main Nov 12, 2024
@PatrikPerssonInceptron PatrikPerssonInceptron deleted the feature/topi.strided_slice-shape-fix-v2 branch November 18, 2024 08:01
ShiboXing pushed a commit to ShiboXing/tvm that referenced this pull request Aug 10, 2025
…e#17502)

* updated topi.strided_slice to perform the same canonicalize index as
relax.strided_slice given a assume_inbound flag

* applied formatting

* removed debug statements

* set assume_inbound=True in leg_redistribute_replica_to_shard as this is assumed
in the associated unit tests

moved misplaced function description

fixed shape error and added a assume_inbound=True to test_strided_slice_symbolic_sliced_axis

added param description for assume_inbound

* added doc for param assume_inbound in dynamic_strided_slice

* added # fmt: off and # fmt: on
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