TensorRT
TensorRT copied to clipboard
🐛 [Bug] tensor.view() not working anymore when using dynamic inputs with v1.1.0
Bug Description
Since v1.1.0 the conversion to TensorRT fails for one of my modules. From what I tested it seems like it is when using .view() with the new version. From what I saw I think it is realted to the following change https://github.com/pytorch/TensorRT/commit/d39b918 .
I am using dynamic input shapes to have a dynamic batch size. So I make the first dimension variable. When doing this there is no support for the reshape() operation but there was one for view() in v1.0.0. Now with v1.1.0 when I try it the view() seems to be changed to a reshape() and thus causing the error.
Traceback (most recent call last):
File "...", line 25, in <module>
trt_engine = ttrt.ts.convert_method_to_trt_engine(jit_module, method_name='forward', inputs=(trt_input, ),
File "...", line 199, in convert_method_to_trt_engine
return _C.convert_graph_to_trt_engine(module._c, method_name, _parse_compile_spec(compile_spec))
RuntimeError: [Error thrown at core/conversion/converters/impl/shuffle.cpp:47] Resize is currently not support in dynamic input shape compilation
When I replace the view() with a reshape() and run it with v1.0.0 I get the same exact error.
To Reproduce
I created a minimal example, which when I run it in an environment with torch v1.10 and torch_tensorrt v1.0.0 works but it throws the above error when I run it with torch v1.11 and torch_tensorrt v1.1.0
import torch
import torch.nn as nn
import torch_tensorrt as ttrt
class TestModule(nn.Module):
def __init__(self):
super().__init__()
self.conf_layer = nn.Conv2d(256, 256, kernel_size=3, padding=1)
def forward(self, x):
conf = self.conf_layer(x)
conf = conf.view([x.size(0), 256, 4624])
return conf
dummy_input = torch.rand(torch.Size([1, 256, 68, 68]))
trt_input = ttrt.Input(min_shape=(1, 256, 68, 68), opt_shape=(1, 256, 68, 68), max_shape=(4, 256, 68, 68))
test_module = TestModule()
jit_module = torch.jit.trace_module(test_module, {'forward': (dummy_input, )})
device = ttrt.Device('cuda:0')
enabled_precision = {torch.float16}
trt_engine = ttrt.ts.convert_method_to_trt_engine(jit_module, method_name='forward', inputs=(trt_input, ),
device=device, enabled_precisions=enabled_precision)
Expected behavior
I still expect that view() should work the same as in v1.0.0 there it was able to compile to a TensorRT engine when using dynamic inputs.
Environment
- Torch-TensorRT v1.1.0
- PyTorch v1.11
- Ubunut 20.04 x64
- Installed with pip and conda, no difference in behavior
- Using prebuild libs
- Python version: 3.9
- CUDA version: 11.3
Commands I used to setup the env
# torch v1.10 torch_tensorrt v1.0.0
conda create -n torch110 python=3.9
conda activate torch110
conda install pytorch==1.10.0 torchvision==0.11.0 -c pytorch
pip3 install torch_tensorrt==1.0.0 -f https://github.com/NVIDIA/Torch-TensorRT/releases
# torch v1.11 torch_tensorrt v1.1.0
conda create -n torch111 python=3.9
conda activate torch111
conda install pytorch torchvision -c pytorch
pip3 install torch_tensorrt -f https://github.com/NVIDIA/Torch-TensorRT/releases
Are there any updates on this? I would also be fine with hints how to maybe make the conversion from view to reshape optional. Looking at the code it seems not easy, since there is no logic for it and the conversion pipeline is hardcoded as far as I can tell.
This issue has not seen activity for 90 days, Remove stale label or comment or this will be closed in 10 days
@dheerajperi FYI on dynamic shape + resize.
This issue has not seen activity for 90 days, Remove stale label or comment or this will be closed in 10 days
Hello, would it be possible to re-open this issue ?