Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,7 @@ def _reshape(self, node: fx.Node) -> relax.Var:

# Skip identity reshape
current_shape = self.shape_of(x)
if list(current_shape) == list(dims):
if current_shape is not None and list(current_shape) == list(dims):
return x

return self.block_builder.emit(relax.op.reshape(x, dims))
Expand Down
14 changes: 14 additions & 0 deletions python/tvm/relax/frontend/torch/exported_program_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,20 @@ def _slice(self, node: fx.Node) -> relax.Var:
if end_val is None:
end_val = sys.maxsize

# Skip identity slice (start=0, end>=maxsize, step=1) which is commonly
# emitted by torch.export for dynamic shapes. Without this, strided_slice
# produces shapes like T.min(9223372036854775807, s) that don't simplify,
# causing downstream shape inference failures.
if (
isinstance(start, int)
and isinstance(end_val, int)
and isinstance(step, int)
and start == 0
and end_val >= sys.maxsize
and step == 1
):
Comment on lines +948 to +955

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.

medium

For improved readability and conciseness, you could group the isinstance checks using the all() built-in function. This would make the condition for identifying an identity slice slightly easier to parse.

        if (
            all(isinstance(v, int) for v in (start, end_val, step))
            and start == 0
            and end_val >= sys.maxsize
            and step == 1
        ):

return x

axes = [dim]
begin = [start]
end = [end_val]
Expand Down
Loading