Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Performance][Spec Decode] Optimize ngram lookup performance #9333

Merged
merged 4 commits into from
Oct 16, 2024

Conversation

LiuXiaoxuanPKU
Copy link
Collaborator

@LiuXiaoxuanPKU LiuXiaoxuanPKU commented Oct 14, 2024

After benchmarking the performance of ngram in vllm, it seems that the proposal time is longer than expected. The main reason is that there are (1) CPU <-> GPU communication when building the ngram lookup table. (2) Building the ngram contains many small kernels (duration < 5 microseconds) as show below:
Screenshot 2024-10-13 at 11 07 44 PM

Zoom in the propose time:
Screenshot 2024-10-13 at 11 09 55 PM

The PR tries to
(1) perform lookup operation on CPU.
(2) trigger CPU <-> GPU communication only when there is a match in lookup.

Some performance numbers on a single H100:
input_len: 550, output_len: 150
I changed the prompt to try different system efficiency (which might include the number of CPU <-> GPU sync).

System efficiency propose time before this PR propose time after this PR end2end latency before this PR end2end latency after this PR
0.31 4.4ms 2.2ms 6.4s 5.6s
0.63 3.3ms 1.5ms 3.8s 3.2s
0.80 2.6 ms 1.5ms 3.0s 2.6s

input_len: 2048, output_len: 150

System efficiency propose time before this PR propose time after this PR end2end latency before this PR end2end latency after this PR
0.30 6.00ms 4.54ms 9.83s 9.25s
0.63 2.90ms 2.70ms 5.84s 5.45s

Copy link

👋 Hi! Thank you for contributing to the vLLM project.
Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

Copy link
Collaborator

@comaniac comaniac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@comaniac
Copy link
Collaborator

btw does this approach still have speedup if the prompt length is much longer? I'm just thinking about the trade off between CPU-GPU sync overhead and (maybe) slower CPU computation.

@LiuXiaoxuanPKU
Copy link
Collaborator Author

btw does this approach still have speedup if the prompt length is much longer? I'm just thinking about the trade off between CPU-GPU sync overhead and (maybe) slower CPU computation.

Yeah will do more benchmarks here

Copy link
Collaborator

@mgoin mgoin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is worth considering just for the aspect of simplicity. It could even make sense to write a CPU kernel in C++ instead of trying to do it on GPU

@mgoin mgoin added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 14, 2024
@LiuXiaoxuanPKU
Copy link
Collaborator Author

Will change the PR so that we can change the device based on the sequence length.

@mgoin mgoin merged commit 8345045 into vllm-project:main Oct 16, 2024
53 checks passed
charlifu pushed a commit to charlifu/vllm that referenced this pull request Oct 23, 2024
vrdn-23 pushed a commit to vrdn-23/vllm that referenced this pull request Oct 23, 2024
Alvant pushed a commit to compressa-ai/vllm that referenced this pull request Oct 26, 2024
garg-amit pushed a commit to garg-amit/vllm that referenced this pull request Oct 28, 2024
FerdinandZhong pushed a commit to FerdinandZhong/vllm that referenced this pull request Oct 29, 2024
sumitd2 pushed a commit to sumitd2/vllm that referenced this pull request Nov 14, 2024
mfournioux pushed a commit to mfournioux/vllm that referenced this pull request Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants