Linear Increase in Batched 1st Token Latency with Larger Batch Sizes
Hello TensorRT Team,
I am currently utilizing the TensorRT-LLM and have encountered an interesting performance characteristic that I hope to gain more insights on.
Issue Description: During my experiments, I've observed that the latency for generating the first token in a batched setting (referred to as "Batched 1st token latency") seems to increase almost linearly with the increase in batch size. This behavior appears to be consistent across different batch sizes.
Specifics of the Issue:
- Model: Baichuan2/Llama2 (I just try this two)
- Observed Behavior: Linear increase in latency for the first token generation in batched inference.
- Expected Behavior: Ideally, I would expect a less than linear scaling in latency with respect to batch size, considering the parallel processing capabilities of GPUs.
- Hardware: GPU 1*3090 CPU i9-12900K Memory: 128G
Request for Information:
- Has this behavior been observed or documented in any of your internal tests?
- If yes, could you provide insights or explanations as to why this linear increase in latency occurs with larger batch sizes?
- Are there any recommendations or best practices to mitigate this latency increase when working with larger batches?
Any information or guidance on this matter would be greatly appreciated, as it would help in optimizing the use of TensorRT LLM for scenarios requiring batched processing.
Thank you for your time and assistance.
Best regards
I also noticed this phenomenon, especially in quantized model.
By any chance did you apply some warmup sessions?
for i in range(10):
input0 = [[prompts[0]]]
input0_data = np.array(input0).astype(object)
output0_len = np.ones_like(input0).astype(np.uint32) * output_lens[i]
bad_words_list = np.array([[""]], dtype=object)
stop_words_list = np.array([[""]], dtype=object)
inputs = [
utils.prepare_tensor("text_input", input0_data, FLAGS.protocol),
utils.prepare_tensor("max_tokens", output0_len, FLAGS.protocol),
utils.prepare_tensor("bad_words", bad_words_list, FLAGS.protocol),
utils.prepare_tensor("stop_words", stop_words_list,
FLAGS.protocol),
]
client.infer(model_name, inputs, request_id=str(i))
https://github.com/triton-inference-server/tensorrtllm_backend/blob/release/0.5.0/tools/inflight_batcher_llm/end_to_end_test.py#L101-L117
Hence the term TensorRT engine. More can be found here.
Yes
Any idea for this issue? @byshiue
I think it depends on the input length you use. When the input length is long enough, the GPU utilization is very high in context phase (generating first token) and hence the latency increases linearly when you increase batch size.
Close this bug because the issue is inactivated. Feel free to ask here if you still have question/issue, we will reopen the issue.
Hello, how can we get 1st Token Latency?Thanks.
Hi, I'm observing the same behavior with experiments run on mosaicml/mpt-7b-8k bfp16 2048in 160out TRT engines with 8 / 16 batch sizes utilizing the Python bindings for C++ runtime.
The generation time for the batched first token (when max_output_len == 1), is scaling linearly (batch_size * TTFT at batch size 1), but not subsequent tokens (when max_output_len > 1). I've utilized the GptSession API, specifically the enqueue_requests & await_responses
Warmups were also conducted to exclude that possibility.
This indicates some sort of bottleneck in the initial first token generation process. I'd appreciate if any one has any directions to look further into? This issue should be re-opened.
Question(s) that come to mind:
- Is batch processing being considered as part of the matrix mul implementations in TensorRT-LLM, or is this sequential?