TensorRT-LLM icon indicating copy to clipboard operation
TensorRT-LLM copied to clipboard

How does TensorRT-LLM use In-flight Batching?

Open liye0626 opened this issue 3 years ago • 12 comments

There is some confusion about how to use TensorRT-LLM Inflighting Batching.

  • How does TensorRT-LLM use In-flight Batching?
  • How do we make sure we use TensorRT-LLM?
  • If In-flight Batching is used, can the output (generation) length of sentences in one batch be different?

liye0626 avatar Oct 27 '23 04:10 liye0626

Hi @liye0626 ,

We expose the in-flight batching feature through the Triton backend (even if it can be enabled in any serving system). Have you taken a look at the Triton backend of TensorRT-LLM?

If you take a look at the latest update in our main branch, you’ll see that we now export a tensor with output sequences.

Thanks, Julien

jdemouth-nvidia avatar Oct 27 '23 05:10 jdemouth-nvidia

Hi @jdemouth-nvidia, You mean, in-flight batching feature must use Triton backend. If we only build TensorRT-LLM by referring to the guide, we cannot use the in-flight batching feature.

  • guide: https://github.com/NVIDIA/TensorRT-LLM/blob/release/0.5.0/docs/source/installation.md

  • tensorrtllm_backend: https://github.com/triton-inference-server/tensorrtllm_backend

liye0626 avatar Oct 27 '23 05:10 liye0626

@liye0626 Technically, you can use in-flight batching without depending on Triton backend. You can refer this example as to how to enable in-flight batching in a more standalone way.

juney-nvidia avatar Oct 28 '23 12:10 juney-nvidia

@juney-nvidia currently both triton backend and the example that you linked is implementing in-flight batching in c++. Is there any examples implementing IFB using the python API? Thanks!

larme avatar Oct 30 '23 15:10 larme

Also, can I implement continuous batching using the python API? I see some mentions in different issues but without a conclusion. Any links to helpful resource will be thankful.

larme avatar Oct 30 '23 16:10 larme

For now support for in-flight batching requires you to use the C++ batch manager together with the C++ runtime. We plan to publish a Python wrapper in the near future but it’s not available yet.

jdemouth-nvidia avatar Oct 31 '23 02:10 jdemouth-nvidia

@jdemouth-nvidia @juney-nvidia Thanks for your help, I have successfully enabled in-flighting batching by batch manager.

liye0626 avatar Oct 31 '23 06:10 liye0626

Awesome. Thanks for your patience. If we can continue to help, let us know :). I’m closing the issue for now.

jdemouth-nvidia avatar Oct 31 '23 06:10 jdemouth-nvidia

@jdemouth-nvidia @juney-nvidia Thanks for your help, I have successfully enabled in-flighting batching by batch manager.

hello, How did you achieve this? use the C++ batch manager?

lyc728 avatar Jan 22 '24 11:01 lyc728

btw for anyone finding this issue, now there is Python API for inflight batching here https://github.com/NVIDIA/TensorRT-LLM/tree/main/examples/bindings/executor#advanced-example

lopuhin avatar Jun 04 '24 16:06 lopuhin

btw for anyone finding this issue, now there is Python API for inflight batching here https://github.com/NVIDIA/TensorRT-LLM/tree/main/examples/bindings/executor#advanced-example顺便说一句,对于发现此问题的人来说,现在这里有用于动态批处理的 Python API https://github.com/NVIDIA/TensorRT-LLM/tree/main/examples/bindings/executor#advanced-example

Thanks for guidance ! How to make sure Infight Batching is turned on in this example code ? And btw does this example also work for TensorRT-LLM 0.5.0 ?

Jackie2049 avatar Jan 09 '25 16:01 Jackie2049

How to make sure Infight Batching is turned on in this example code ? And btw does this example also work for TensorRT-LLM 0.5.0 ?

@2012zzhao pretty sure it would not work with TensorRT-LLM 0.5.0 as it's really old, I think at least 0.9.0 would be needed (and then it's best to check the version of example which corresponds to the library version you're using). As for when it's tuned on, the example code actually does implement inflight batching so there is no need to turn it on, but it's not something you'd be using directly -- e.g. we've used this example to have inflight batching in our python http server, as we didn't need all the features of the triton server.

lopuhin avatar Jan 09 '25 20:01 lopuhin