TensorRT icon indicating copy to clipboard operation
TensorRT copied to clipboard

Multi-batch Inference Slow on TensorRT 7

Open shroudie opened this issue 6 years ago • 6 comments

Description

Hello all, I was experimenting multi-batching on TensorRT with AlexNet provided in PyTorch. So I exported to onnx model with dynamic batch size, and I load trt engine with optimization profile.

I am not sure whether I am doing multi-batching correctly but I have verified the output correctness. However, I am seeing a linear growth in inference time, for example:

with 1 batch, inference takes 0.0057s with 8 batch, inference takes 0.0105s with 32 batch, inference takes 0.0194s

I am expecting the inference time to stay almost same regardless of what batch size I use, which is true when I use different batch sizes on raw PyTorch model.

I was wondering whether batching are parallel on TensorRT, like all batches are evaluated simultaneously but not in a way that different batches are enqueued at a different time. Or whether I am not doing it in a correct way.

Thanks a lot!

Environment

TensorRT Version: 7.2 CUDA Version: 10.2 Operating System + Version: Ubuntu 18.04 Python Version (if applicable): 3.6

shroudie avatar Nov 30 '20 19:11 shroudie

I had some misunderstanding about batching, closing!

shroudie avatar Dec 01 '20 22:12 shroudie

I had some misunderstanding about batching, closing!

I have exactly the same problem. @shroudie could you please elaborate what your misunderstanding was ? Thanks !

scar2608 avatar Dec 02 '20 11:12 scar2608

I had some misunderstanding about batching, closing!

I have exactly the same problem. @shroudie could you please elaborate what your misunderstanding was ? Thanks !

How fast are your multi-batch models? What are you comparing them to?

I was expecting multi-batch to run at the same speed with single batch, since I thought just by spawning more cuda blocks could achieve this. But it does not seem like it is the way it worked.

shroudie avatar Dec 02 '20 20:12 shroudie

I had some misunderstanding about batching, closing!

I have exactly the same problem. @shroudie could you please elaborate what your misunderstanding was ? Thanks !

How fast are your multi-batch models? What are you comparing them to?

I was expecting multi-batch to run at the same speed with single batch, since I thought just by spawning more cuda blocks could achieve this. But it does not seem like it is the way it worked.

I am comparing inference time of Tensor-RT to raw PyTorch model. If I use batch size 1, the performance is similar. However. if I increase batch size, to say 16, PyTorch inference time barely increases, while Tensor-RT increases linearly (exactly like in your case). Environment and scenario is exactly like yours: exported ONNX model, dynamic batch size, optimization profile.

It is difficult for me to believe that Tensor-RT is so much worse in optimizing for multi-batch inference.

scar2608 avatar Dec 03 '20 09:12 scar2608

I had some misunderstanding about batching, closing!

I have exactly the same problem. @shroudie could you please elaborate what your misunderstanding was ? Thanks !

How fast are your multi-batch models? What are you comparing them to? I was expecting multi-batch to run at the same speed with single batch, since I thought just by spawning more cuda blocks could achieve this. But it does not seem like it is the way it worked.

I am comparing inference time of Tensor-RT to raw PyTorch model. If I use batch size 1, the performance is similar. However. if I increase batch size, to say 16, PyTorch inference time barely increases, while Tensor-RT increases linearly (exactly like in your case). Environment and scenario is exactly like yours: exported ONNX model, dynamic batch size, optimization profile.

It is difficult for me to believe that Tensor-RT is so much worse in optimizing for multi-batch inference.

I was comparing to MXNet, which I later found out that they use async operations. In other words, I have to call some "wait"' function at the end of infer for benchmark. And as a result, the raw model also grows linearly in terms of batch. I hope this would be related to your case!

At the end I still do understand why since logically, just by creating more thread blocks to execute the more batches should not have inference time grow linearly. But for my cases, running on TensorRT framework is definitely faster than raw models and that is all I need to know.

shroudie avatar Dec 03 '20 09:12 shroudie

I had some misunderstanding about batching, closing!

I have exactly the same problem. @shroudie could you please elaborate what your misunderstanding was ? Thanks !

How fast are your multi-batch models? What are you comparing them to? I was expecting multi-batch to run at the same speed with single batch, since I thought just by spawning more cuda blocks could achieve this. But it does not seem like it is the way it worked.

I am comparing inference time of Tensor-RT to raw PyTorch model. If I use batch size 1, the performance is similar. However. if I increase batch size, to say 16, PyTorch inference time barely increases, while Tensor-RT increases linearly (exactly like in your case). Environment and scenario is exactly like yours: exported ONNX model, dynamic batch size, optimization profile. It is difficult for me to believe that Tensor-RT is so much worse in optimizing for multi-batch inference.

I was comparing to MXNet, which I later found out that they use async operations. In other words, I have to call some "wait"' function at the end of infer for benchmark. And as a result, the raw model also grows linearly in terms of batch. I hope this would be related to your case!

At the end I still do understand why since logically, just by creating more thread blocks to execute the more batches should not have inference time grow linearly. But for my cases, running on TensorRT framework is definitely faster than raw models and that is all I need to know.

Thanks for clarifications!! That is exactly what happened in my case !!

scar2608 avatar Dec 03 '20 09:12 scar2608