Skip to content

chore: Minor fix 2.3 #2866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2024
Merged
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
41 changes: 40 additions & 1 deletion py/torch_tensorrt/dynamo/conversion/impl/slice/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
get_positive_dim,
get_trt_tensor,
)
from torch_tensorrt.dynamo.conversion.impl.cat import cat
from torch_tensorrt.dynamo.conversion.impl.slice.base import slice
from torch_tensorrt.fx.converters.converter_utils import (
has_dynamic_shape,
Expand Down Expand Up @@ -99,7 +100,45 @@ def expand(
[int(i == o) for i, o in zip(input_tensor_shape, shape)]
) # stride == 1 if dimensions match, 0 otherwise

layer = ctx.net.add_slice(input_t, start=start, shape=shape, stride=stride)
shape_ = shape
# Handle dynamic shapes case where shape has dynamic dimension
if any(isinstance(ele, TRTTensor) for ele in shape):
shape_ = cat(
ctx,
target,
source_ir,
name + "_shape_concat",
shape,
0,
cast_dtype=trt.int32,
)
start_tensor = cat(
ctx,
target,
source_ir,
name + "_start_concat",
start,
0,
cast_dtype=trt.int32,
)
stride_tensor = cat(
ctx,
target,
source_ir,
name + "_stride_concat",
stride,
0,
cast_dtype=trt.int32,
)
layer = ctx.net.add_slice(
input_t, start=trt.Dims(), shape=trt.Dims(), stride=trt.Dims()
)
layer.set_input(1, start_tensor)
layer.set_input(2, shape_)
layer.set_input(3, stride_tensor)
else:
layer = ctx.net.add_slice(input_t, start=start, shape=shape_, stride=stride)

set_layer_name(layer, target, name, source_ir)
return layer.get_output(0)

Expand Down
Loading