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

[torch2trt/converters] Add element support to torch.Tensor.__getitem__ converter #770

Closed

Conversation

chaoz-dev
Copy link
Contributor

Resolves #768.

This PR adds support for single element arguments to torch.Tensor.__getitem__ converter.
We convert the input into a tuple if it is not already a tuple, which can occur when the input argument is a single argument. All other arguments should be handled the same (especially multiple arguments, as they are already tuples).

Single tuple arguments are unpacked correctly still as expected into multiple indexing arguments.
Note that tuples combined with ellipsis or colon arguments are still not yet supported; see #755.

Also, add a lot of unit tests to check that operations on the batch dimension are handled correctly.

@chaoz-dev chaoz-dev changed the title [torch2trt/converters] Add element support to torch.Tensor.__getitem_ converter [torch2trt/converters] Add element support to torch.Tensor.__getitem__ converter Jul 23, 2022
@chaoz-dev
Copy link
Contributor Author

Note that this was tested on v0.3.x; the unit tests here fail on v0.4.0. See #769.

@chaoz-dev
Copy link
Contributor Author

Running python -m torch2trt.test --name getitem:

NUM_TESTS: 39
NUM_SUCCESSFUL_CONVERSION: 39
NUM_FAILED_CONVERSION: 0
NUM_ABOVE_TOLERANCE: 0
NUM_pSNR_TOLERANCE: 0

Comment on lines +192 to +196
# There is currently an issue with this test case.
# Need to investigate this more.
# @add_module_test(torch.float32, torch.device('cuda'), [(3, 2, 4)], max_batch_size=3)
# def test_tensor_getitem_0d_3tuple():
# return LambdaModule(lambda x: x[(0, 1, 2)])
Copy link
Contributor Author

@chaoz-dev chaoz-dev Nov 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaybdub Looks like there's an issue with this test case, which we'll need to look into more. I don't think it's related to the changes in this PR, however, but with how we're indexing in general.

ie. I believe this was passing on the v0.4.0 release with static shapes, but does not appear to be passing now on latest master.

@chaoz-dev
Copy link
Contributor Author

NUM_TESTS: 38
NUM_SUCCESSFUL_CONVERSION: 38
NUM_FAILED_CONVERSION: 0
NUM_ABOVE_TOLERANCE: 0
NUM_pSNR_TOLERANCE: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant