NVIDIA-AI-IOT / torch2trt

An easy to use PyTorch to TensorRT converter
MIT License
4.58k stars 675 forks source link

Inconsistent inference results between PyTorch and TensorRT using torch2trt with ELU operator #889

Open Thrsu opened 10 months ago

Thrsu commented 10 months ago

Description:

I'm experiencing a discrepancy between the inference results of my PyTorch model and the TensorRT model obtained by converting it using the torch2trt tool.

Reproduce

This can be reproduced by the following script:

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

model = torch.nn.ELU(inplace=True,).cuda()
input_data=torch.randn([1, 3, 10, 10], dtype=torch.float32).cuda()
model_trt = torch2trt(model, [input_data])
y = model(input_data)
y_trt = model_trt(input_data)

# check the output against PyTorch
print(torch.max(torch.abs(y - y_trt)))

The output is:

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

Environment

Thrsu commented 10 months ago

Moreover, I noticed the inference results for LeakyRelu operator are also inconsistent between PyTorch and TensorRT. The script is as below:

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

model = torch.nn.LeakyReLU(inplace=True,).cuda()
input_data = torch.randn([3, 2, 5], dtype=torch.float32).cuda()
model_trt = torch2trt(model, [input_data])
y = model(input_data)
y_trt = model_trt(input_data)

# check the output against PyTorch
print(torch.max(torch.abs(y - y_trt)))