Skip to content

Index converter dynamic cases fix #3694

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,9 @@ def index_dtype_validator(


@dynamo_tensorrt_converter(
torch.ops.aten.index.Tensor, capability_validator=index_dtype_validator
torch.ops.aten.index.Tensor,
capability_validator=index_dtype_validator,
supports_dynamic_shapes=True,
)
@enforce_tensor_types(
{
Expand Down
26 changes: 25 additions & 1 deletion tests/py/dynamo/conversion/test_index_aten.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,31 @@ def forward(self, input):
dtype=torch.float32,
),
]
self.run_test_with_dynamic_shape(TestModule(), input_specs)
self.run_test_with_dynamic_shape(
TestModule(), input_specs, use_dynamo_tracer=True
)


class TestIndexDynamicInputNonDynamicIndexConverter(DispatchTestCase):
def test_index_input_non_dynamic_index_dynamic(self):
class TestIndexWithRuntimeIndex(torch.nn.Module):
def forward(self, x):
mask = x > 0
idx = torch.nonzero(mask, as_tuple=True)
return torch.ops.aten.index.Tensor(x, idx)

input_specs = [
Input(
min_shape=(2, 2),
opt_shape=(2, 2),
max_shape=(8, 8),
dtype=torch.float32,
),
]
# In this case the index args[1] gets itself converted to a List of TRTTensors with use_dynamo_tracer=True
self.run_test_with_dynamic_shape(
TestIndexWithRuntimeIndex(), input_specs, use_dynamo_tracer=True
)


if __name__ == "__main__":
Expand Down
Loading