IndexError when converting torch pad operator to TensorRT
Thrsu opened this issue · comments
Thrsu commented
Description
I encountered an issue while trying to convert the pad operator from torch to TensorRT. The following error message is displayed:
Traceback (most recent call last):
File "test_4014.py", line 13, in <module>
model_trt = torch2trt(model, [para_0])
File "/home/henry/anaconda3/envs/tensorrt/lib/python3.8/site-packages/torch2trt-0.4.0-py3.8.egg/torch2trt/torch2trt.py", line 779, in torch2trt
outputs = module(*inputs)
File "/home/henry/anaconda3/envs/tensorrt/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1128, in _call_impl
result = forward_call(*input, **kwargs)
File "test_4014.py", line 10, in forward
return torch.nn.functional.pad(input, para_1,mode='circular',)
File "/home/henry/anaconda3/envs/tensorrt/lib/python3.8/site-packages/torch2trt-0.4.0-py3.8.egg/torch2trt/torch2trt.py", line 310, in wrapper
converter["converter"](ctx)
File "/home/henry/anaconda3/envs/tensorrt/lib/python3.8/site-packages/torch2trt-0.4.0-py3.8.egg/torch2trt/converters/pad.py", line 12, in convert_pad
pre_padding = (pad[2], pad[0])
IndexError: tuple index out of range
Reproduce
This bug can be reproduced by the below script:
from torch2trt import torch2trt
import torch
from torch.nn import Module
para_0 = torch.randn([2, 2, 4], dtype=torch.float32).cuda()
para_1 = (1, 1)
class pad(Module):
def forward(self, input):
return torch.nn.functional.pad(input, para_1,mode='circular',)
model = pad().float().cuda()
model_trt = torch2trt(model, [para_0])
y = model(para_0)
y_trt = model_trt(para_0)
# check the output against PyTorch
print(torch.max(torch.abs(y - y_trt)))
Environment
- torch: 1.11.0
- torch2trt: 0.4.0
- tensorrt: 8.6.1.6
timegoby commented
It's only support padding H,W at same time.
reference: https://github.com/NVIDIA-AI-IOT/torch2trt/blob/master/torch2trt/converters/pad.py#L17
Thrsu commented
Thank you for your response :)