Skip to content

fix: Remove references to implicit batch for TRT 10 #2773

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
Apr 23, 2024
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
9 changes: 3 additions & 6 deletions py/torch_tensorrt/dynamo/conversion/impl/normalization/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def batch_norm(

# For BatchNorm1d, reshape 1d to 2d
output_shape = input.shape
if not ctx.net.has_implicit_batch_dimension and len(input.shape) < 4:
if len(input.shape) < 4:
assert (
len(get_dynamic_dims(input.shape)) <= 1
), "BatchNorm1D with more than one dynamic dims is not currently supported."
Expand All @@ -75,7 +75,7 @@ def batch_norm(
output = layer.get_output(0)

# For BatchNorm1d, reshape output back to 1d
if not ctx.net.has_implicit_batch_dimension and len(output_shape) < 4:
if len(output_shape) < 4:
output = impl.shuffle.reshape(
ctx,
target,
Expand Down Expand Up @@ -411,7 +411,7 @@ def softmax(
input: TRTTensor,
dim: Optional[Any] = None,
) -> Union[TRTTensor, Sequence[TRTTensor]]:
input_ranks = len(input.shape) + (1 if ctx.net.has_implicit_batch_dimension else 0)
input_ranks = len(input.shape)

if not isinstance(input, TRTTensor):
raise RuntimeError(
Expand All @@ -433,9 +433,6 @@ def get_softmax_dim(ndim: int) -> int:
dim = cast(int, dim)

dim = get_positive_dim(dim, input_ranks)
if ctx.net.has_implicit_batch_dimension:
assert dim != 0, "Can't apply softmax on batch dimension when it's implicit."
dim -= 1

layer = ctx.net.add_softmax(input)
layer.axes = 1 << dim
Expand Down
15 changes: 4 additions & 11 deletions py/torch_tensorrt/dynamo/conversion/impl/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,12 @@ def select(
"of the TensorRT region!"
)

ranks = len(input.shape) + (1 if ctx.net.has_implicit_batch_dimension else 0)
ranks = len(input.shape)
dim = get_positive_dim(cast(int, dim), ranks)
dynamic_shape = has_dynamic_shape(input.shape)
if ctx.net.has_implicit_batch_dimension:
if dim == 0:
raise RuntimeError(
f"We do not support slice_tensor at batch dim when it's implicit, got {dim}!"
)
dim = dim - 1
else:
if dynamic_shape:
# Check whether slice target dim is dynamic shape dim
assert input.shape[dim] != -1, "Can't select on negative shape dimension!"
if dynamic_shape:
# Check whether slice target dim is dynamic shape dim
assert input.shape[dim] != -1, "Can't select on negative shape dimension!"
index = index

if index >= input.shape[dim]:
Expand Down
5 changes: 1 addition & 4 deletions py/torch_tensorrt/dynamo/conversion/impl/squeeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ def squeeze(
for dim in dims:
dim = get_positive_dim(
dim,
len(input.shape) + (1 if ctx.net.has_implicit_batch_dimension else 0),
len(input.shape),
)
if ctx.net.has_implicit_batch_dimension:
assert dim != 0, "We don't support squeeze batch dim when it's implicit."
dim -= 1

assert input.shape[dim] != -1, "We don't support squeeze dynamic dim."
assert (
Expand Down
10 changes: 1 addition & 9 deletions py/torch_tensorrt/dynamo/conversion/impl/unsqueeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,9 @@ def unsqueeze(

dim = cast(int, dim)

input_shape_size = (
len(input_val.shape) + 1
if ctx.net.has_implicit_batch_dimension
else len(input_val.shape)
)
input_shape_size = len(input_val.shape)
dim = get_positive_dim(dim, input_shape_size + 1)

if ctx.net.has_implicit_batch_dimension:
assert dim != 0
dim -= 1

assert (
len(get_dynamic_dims(input_val.shape)) <= 1
), "Currently we don't support unsqueeze with more than one dynamic dims."
Expand Down
Loading