onnxruntime: [Performance] Regression observed when using CUDA execution provider

Describe the issue

We are seeing a regression when using onnxruntime with the CUDA execution provider starting from version 1.14.1. Before version 1.14.1, there was no regression. We also observe the regression in subsequent versions, including the latest version, 1.17.1.

To reproduce

pip install onnxruntime-gpu for different versions, and run the script below

import onnxruntime as ort
import numpy as np
import time

def run_inference(session, input_data):
    """
    Run a single inference and return the latency.
    """
    start_time = time.time()
    _ = session.run(None, input_data)
    return time.time() - start_time

def generate_dummy_img_input(batch_size=1):
    # use random data
    input_data = np.random.rand(1, 3, 224, 224).astype(np.float32)
    return {"gpu_0/data_0": input_data}

model_path = "/path/to/resnet50-1.2.onnx"
session = ort.InferenceSession(model_path, providers=['CUDAExecutionProvider'])
input_data = generate_dummy_img_input()

latencies = []
for _ in range(100):
    latency = run_inference(session, input_data)
    latencies.append(latency)
# print(f"Latencies (ms): {latencies}")
# Remove the first value for model warm-up, calculate the average of the rest
latencies = latencies[1:]
average_latency = sum(latencies) / len(latencies)
print(f"Average latency (ms): {average_latency * 1000}")

Sharing some numbers: onnxruntime-gpu == 1.13.1

Average latency (ms): 3.55936060048113
Average latency (ms): 3.6028346630057904
Average latency (ms): 3.526743012245255
Average latency (ms): 3.408121340202563
Average latency (ms): 3.644895071935172

onnxruntime-gpu == 1.14.1

Average latency (ms): 4.1407864503186165
Average latency (ms): 4.213094711303711
Average latency (ms): 3.9710492798776342
Average latency (ms): 3.977019377429076
Average latency (ms): 3.976980845133464

onnxruntime-gpu == 1.17.1

Average latency (ms): 4.22009795603126
Average latency (ms): 4.130989614159169
Average latency (ms): 4.265643129445086
Average latency (ms): 4.415384446731721
Average latency (ms): 4.095142537897283

The latency increase from version 1.13.1 to version 1.14.1 is approximately 14.29%. The latency increase from version 1.14.1 to version 1.17.1 is approximately 4.18%.

Note that when using the CPU execution provider, there is no regression. It only occurs when using the CUDA execution provider.

For a simpler reproduction, I’m using a resnet50 model. We observe a latency increase of more than 20x with our model: onnxruntime-gpu == 1.13.1

Average:0.1200742244720459

onnxruntime-gpu == 1.16.3

Average:3.157811665534973

The regression can be observed using the C++ code as well.

Urgency

High

Platform

Linux

OS Version

22.04

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.17.1

ONNX Runtime API

Python

Architecture

X64

Execution Provider

CUDA

Execution Provider Library Version

CUDA 12.2 and 11.8

Model File

No response

Is this a quantized model?

No

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

I reproduced the issue with https://github.com/onnx/models/blob/main/validated/vision/classification/resnet/model/resnet50-v1-12.onnx in A100. The average latency (ms) output: ORT 1.13.1: 2.98 ORT 1.14.0: 3.20 ORT 1.17.1: 3.20 So there is some regression from 1.13.1 to 1.14.0. I will take a look at the cause.

@krishung5 I would recommend trying to use a CUDA graph, that might help reducing the execution time for such small networks.