Skip to content
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

fix: Add support for default dimension in aten.cat #1863

Merged
merged 1 commit into from
May 24, 2023
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
2 changes: 1 addition & 1 deletion py/torch_tensorrt/fx/converters/aten_ops_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def aten_ops_cat(
) -> Union[TRTTensor, Sequence[TRTTensor]]:
kwargs_new = {
"tensors": args[0],
"dim": args[1],
"dim": args[1] if len(args) >= 2 else 0,
}
return acc_ops_converters.acc_ops_cat(network, target, None, kwargs_new, name)

Expand Down
39 changes: 37 additions & 2 deletions py/torch_tensorrt/fx/test/converters/aten_op/test_cat_aten.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestCatConverter(DispatchTestCase):
@parameterized.expand(
[
("pos", 1),
# ("neg", -2), #dim can not have dynamic input
("neg", -2),
]
)
def test_cat(self, _, dim):
Expand All @@ -27,7 +27,7 @@ def forward(self, x, y, z):
@parameterized.expand(
[
("pos", 1),
# ("neg", -2), #dim can not have dynamic input
("neg", -2),
]
)
def test_cat_dynamic_shape(self, _, dim):
Expand All @@ -53,6 +53,41 @@ def forward(self, x, y):
expected_ops={torch.ops.aten.cat.default},
)

def test_cat_no_dim(self):
class Cat(nn.Module):
def forward(self, x, y, z):
return torch.cat((x, y, z))

inputs = [torch.randn(2, 1, 3), torch.randn(1, 1, 3), torch.randn(3, 1, 3)]
self.run_test(
Cat(),
inputs,
expected_ops={torch.ops.aten.cat.default},
)

def test_cat_dynamic_shape_no_dim(self):
frank-wei marked this conversation as resolved.
Show resolved Hide resolved
class Cat(nn.Module):
def forward(self, x, y):
return torch.cat((x, y))

input_specs = [
InputTensorSpec(
shape=(-1, 16, 3),
dtype=torch.float32,
shape_ranges=[((2, 16, 3), (3, 16, 3), (32, 16, 3))],
),
InputTensorSpec(
shape=(-1, 16, 3),
dtype=torch.float32,
shape_ranges=[((2, 16, 3), (3, 16, 3), (32, 16, 3))],
),
]
self.run_test_with_dynamic_shape(
Cat(),
input_specs,
expected_ops={torch.ops.aten.cat.default},
)


if __name__ == "__main__":
run_tests()