The TensorRT result is incorrect when the kernel_size and stride of Conv2D are both [14, 14]
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 13.4k
- Forks
- 2.4k
- Avg merge
- 5d 3h
- Merged PRs (30d)
- 2
Description
Description
The TensorRT result is incorrect when the conv2d's kernel_size and stride are both [14, 14] .
Environment
TensorRT Version: 10.14.1.48
NVIDIA GPU: RTX 3090
NVIDIA Driver Version: 570.133.07
CUDA Version: 12.8
CUDNN Version: 9.1.0.70
ONNX Version: 1.17.0
ONNXRuntime Version: 1.19.0
Operating System: Linux
Python Version (if applicable): 3.10.14
Tensorflow Version (if applicable):
PyTorch Version (if applicable): 2.6.0
Baremetal or Container (if so, version):
Relevant Files
Steps To Reproduce
You can reproduce my issue by running the following python code, my result is: Max Diff: tensor(2.8298, device='cuda:0')
import os
import torch
import onnxruntime
import tensorrt as trt
from PIL import Image
from torchvision.transforms import v2
if __name__ == "__main__":
# you can download this image in (https://github.com/user-attachments/assets/18dd13ae-c030-42f4-86f7-1ae4e1cfe422)
image = Image.open('test_image.jpg')
width, height = image.size
image = v2.functional.to_image(image)
transform = v2.Compose([
v2.ToDtype(torch.uint8, scale=True),
v2.Resize(size=(1008, 1008)),
v2.ToDtype(torch.float32, scale=True),
v2.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])])
image = transform(image).unsqueeze(0).to('cuda').to(torch.float32)
model = torch.nn.Sequential(torch.nn.Conv2d(3, 1024, kernel_size=(14, 14),stride=(14, 14))).to('cuda').eval()
torch.onnx.export(model, image, "conv.onnx",input_names=['image'], output_names=['output'])
os.system("trtexec --onnx=conv.onnx --saveEngine=conv.engine")
assert os.path.exists('conv.engine')
with open('conv.engine', "rb") as f, trt.Runtime(trt.Logger()) as runtime:
engine = runtime.deserialize_cuda_engine(f.read())
context = engine.create_execution_context()
trt_input = [image.clone()]
trt_output = [torch.empty(1, 1024, 72, 72, dtype=torch.float32, device='cuda')]
bindings = [v.data_ptr() for v in (trt_input + trt_output)]
context.execute_v2(bindings=bindings)
sess = onnxruntime.InferenceSession('conv.onnx', providers=["CUDAExecutionProvider"])
onnx_output = sess.run(['output'], {'image': image.clone().cpu().numpy()})
trt_output, onnx_output = trt_output[0], torch.from_numpy(onnx_output[0]).to(trt_output[0])
assert trt_output.shape == onnx_output.shape
print("Max Diff: ", (trt_output - onnx_output).abs().max())
Commands or scripts:
Have you tried the latest release?: Yes
Attach the captured .json and .bin files from TensorRT's API Capture tool if you're on an x86_64 Unix system
Can this model run on other frameworks? It can be run.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Python reproduction with the listed TensorRT, CUDA, PyTorch, and GPU versions, then compare the TensorRT and ONNX Runtime outputs for conv.onnx. Done means the Conv2D case with kernel_size and stride [14, 14] no longer produces the reported maximum difference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100