Added converter for torch.Tensor.expand_as() method #614
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR is related to Issue #565, but this issue cannot be closed yet even when this PR is merged.
A converter for
torch.Tensor.expand(size)
already exists, but one fortorch.Tensor.expand_as(other)
did not.Users can convert
expand_as
by replacing allexpand_as(other)
withexpand(other.size())
, but it should not be a favorable way.I made a converter
torch2trt/converters/expand_as.py
similar totorch2trt/converters/expand.py
, with some new test cases.The result of testing in my environment is as follows:
Environment
Ubuntu 20.04
Python 3.8.8
torch 1.8.1
torch2trt 0.3.0
cuda 11.1
cudnn 8.1.1
TensorRT 7.2.2
Test Result
| torch2trt.converters.expand_as.test_tensor_expand_as_scalar | float32 | [1] | {} | 0.00E+00 | nan | 0.00E+00 | 3.4e+05 | 1.88e+04 | 0.014 | 0.0646 |
| torch2trt.converters.expand_as.test_tensor_expand_as_singledim | float32 | [(1, 1, 3, 3)] | {} | 0.00E+00 | nan | 0.00E+00 | 3.3e+05 | 1.97e+04 | 0.0129 | 0.0631 |
| torch2trt.converters.expand_as.test_tensor_expand_as_multidim | float32 | [(1, 1, 1, 3)] | {} | 0.00E+00 | nan | 0.00E+00 | 3.2e+05 | 1.78e+04 | 0.0138 | 0.0635 |
| torch2trt.converters.expand_as.test_tensor_expand_as_singledim_half | float16 | [(1, 1, 3, 3)] | {} | 0.00E+00 | nan | 0.00E+00 | 3.17e+05 | 1.52e+04 | 0.0167 | 0.0877 |
| torch2trt.converters.expand_as.test_tensor_expand_as_multidim_half | float16 | [(1, 1, 1, 3)] | {} | 0.00E+00 | nan | 0.00E+00 | 3.25e+05 | 1.53e+04 | 0.0134 | 0.0784 |
NUM_TESTS: 5
NUM_SUCCESSFUL_CONVERSION: 5
NUM_FAILED_CONVERSION: 0
NUM_ABOVE_TOLERANCE: 0
NUM_pSNR_TOLERANCE: 0