diff --git a/python/tvm/relax/frontend/torch/base_fx_graph_translator.py b/python/tvm/relax/frontend/torch/base_fx_graph_translator.py index 2615a68ee34c..3a7a62ba391d 100644 --- a/python/tvm/relax/frontend/torch/base_fx_graph_translator.py +++ b/python/tvm/relax/frontend/torch/base_fx_graph_translator.py @@ -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)) diff --git a/python/tvm/relax/frontend/torch/exported_program_translator.py b/python/tvm/relax/frontend/torch/exported_program_translator.py index 4c841b00b56d..c9d06962770f 100644 --- a/python/tvm/relax/frontend/torch/exported_program_translator.py +++ b/python/tvm/relax/frontend/torch/exported_program_translator.py @@ -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 + ): + return x + axes = [dim] begin = [start] end = [end_val]