microsoft / microsoft/onnxruntime

Mismatch in results for TensorRT session and cuda Session

Open
#20,986 5 comments 0 reactions 1 assignee Claimed by @chilo-ms View on GitHub
ep:CUDA ep:TensorRT model:transformer
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 11h
Merged PRs (30d)
184

Description

### Describe the issue

I am creating onnxruntime session using tensorRT. While evaluating the model's output, The tolerance levels (atol and rtol) both could be passed at most at the value of 1e-3, when compared for cudaSession, cpuSession and tensorRT session.

However, When I tested it with Nvidia's polygraphy tool. For the atol and rtol values, they are getting passed for 1e-5, both.

### To reproduce

Following code is used for the inference

```
import numpy as np
import torch
import onnxruntime as ort
def main():
providers = [
('CUDAExecutionProvider', {
'device_id': 0,
'cudnn_conv_algo_search': 'DEFAULT',
})
]
providers_2= [
('TensorrtExecutionProvider', {
'device_id': 0, # Select GPU to execute
"trt_engine_cache_enable": True,
"trt_engine_cache_path": "trt_models/"
}),
('CUDAExecutionProvider', {
'device_id': 0,
'cudnn_conv_algo_search': 'DEFAULT',
})
]

model_path = "./onnx_test_model/voxceleb_resnet293_LM.onnx"
sess_options = ort.SessionOptions()
sess_options.inter_op_num_threads = 1
sess_options.intra_op_num_threads = 1
session_ = ort.InferenceSession(model_path, sess_options=sess_options, providers=providers)
session_2 = ort.InferenceSession(model_path, sess_options=sess_options, providers=providers_2)
for shape in list(range(860, 900, 10)):
test = np.random.randn(1,shape,80).astype(np.float32)
embedding_1 = session_.run(output_names=["embs"], input_feed={"feats": test} )[0][0]
embeddings_2 = session_2.run(output_names=["embs"], input_feed={"feats": test},)[0][0]
comparison_result = np.allclose(embedding_1, embeddings_2, rtol=1e-05, atol=1e-05)
print("comparison_result",comparison_result)

if __name__ == "__main__":
main()
```

The model can be downloaded from : https://huggingface.co/Wespeaker/wespeaker-voxceleb-resnet293-LM/blob/main/voxceleb_resnet293_LM.onnx

The polygraphy command is as follows
polygraphy run onnx_test_model/voxceleb_resnet293_LM.onnx --trt --onnxrt --atol 1e-5 --rtol 1e-5 --input-shapes feats:[1,800,80]

I am using the docker image : nvcr.io/nvidia/tensorrt:24.05-py3

### Urgency

I need to complete this, as early as possible. I have deadline for this till friday.

### Platform

Linux

### OS Version

Ubuntu 22.04.4 LTS

### ONNX Runtime Installation

Released Package

### ONNX Runtime Version or Commit ID

1.18

### ONNX Runtime API

Python

### Architecture

X86

### Execution Provider

Default CPU, CUDA, TensorRT

### Execution Provider Library Version

cuda_12.4.r12.4, TensorRT-10.0.1.6

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.