NVIDIA-AI-IOT / torch2trt

An easy to use PyTorch to TensorRT converter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent inference results between PyTorch and converted TensorRT model with AvgPool2d operator

hongliyu0716 opened this issue · comments

Description:

The inference results obtained by PyTorch and converted TensorRT are inconsistent for a model with AvgPool2d operator. I noticed that AvgPool3d has the same problem #892

Reproduce

This issue can be reproduced by the following script:

import torch
from torch.nn import Module
from torch2trt import torch2trt

para_0 = torch.randn([2, 3, 6, 6], dtype=torch.float32).cuda()
para_1 = (2, 2)
para_2 = (2, 2)
para_3 = 0
para_4 = False
para_5 = True
para_6 = 1
class avg_pool2d(Module):
    def forward(self, *args):
        return torch.nn.functional.avg_pool2d(args[0], para_1,para_2,para_3,para_4,para_5,para_6,)
model = avg_pool2d().float().eval().cuda()
model_trt = torch2trt(model, [para_0])

output = model(para_0)
output_trt = model_trt(para_0)
print(torch.max(torch.abs(output - output_trt)))

The output is:

tensor(2.5595, device='cuda:0')

Environment

  • torch: 2.1.1
  • torch2trt: 0.4.0
  • tensorrt: 8.6.1