Fix prefill latency performance drop of bench serving#14592
Fix prefill latency performance drop of bench serving#14592Kangyan-Zhou merged 5 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello @gaopengff, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a performance regression observed in the prefill latency of benchmark serving. The root cause was an discrepancy in input length calculation: when prompts were used, the server's tokenizer would add special tokens, increasing the effective input length beyond what was intended. This change implements a crucial truncation step that adjusts the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses a performance issue in benchmark serving caused by incorrect input lengths from server-side tokenization. The fix to truncate input lengths based on the number of special tokens is appropriate. I've provided one suggestion to further optimize the implementation by using a vectorized NumPy operation, which will improve performance, especially with a large number of prompts.
| num_special_tokens = int(tokenizer.num_special_tokens_to_add()) | ||
| for i in range(num_prompts): | ||
| input_lens[i] = max(0, input_lens[i] - num_special_tokens) |
There was a problem hiding this comment.
For better performance and code clarity, you can replace the loop with a vectorized NumPy operation. This is more efficient, especially for a large num_prompts.
Additionally, the int() cast is redundant as tokenizer.num_special_tokens_to_add() already returns an integer.
num_special_tokens = tokenizer.num_special_tokens_to_add()
input_lens = np.maximum(0, input_lens - num_special_tokens)|
@gaopengff explain that vllm benchmark uses the same logic and link the code for it. That will be more straight forward. |
|
Vllm uses the same logic at https://github.com/vllm-project/vllm/blob/v0.12.0/vllm/benchmarks/datasets.py#L484, which subtract num_special_tokens to get real_input_len. |
|
@zhyncs could you please find someone to review this one? a fix for benchmark scripts~ |
Motivation
When use prompt as input for bench serving, the server will get incorrect input length as its encode operation added special tokens. This may cause bad performance of prefill latency. We should truncate it.
Old:
New: