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] Optimize get_seqs #7051

Merged
merged 3 commits into from
Aug 2, 2024
Merged

[Performance] Optimize get_seqs #7051

merged 3 commits into from
Aug 2, 2024

Conversation

WoosukKwon
Copy link
Collaborator

@WoosukKwon WoosukKwon commented Aug 1, 2024

This PR optimizes the overhead of seq_group.get_seqs(), which was reported by @youkaichao.

The solution is simple: We maintain seqs: List[Sequence] in addition to seqs_dict: Dict[int, Sequence], and use seqs for all get_seqs calls.

This leads to small performance boost (llama3 8B, 1xH100)

  • Before: Throughput: 23.98 requests/s, 9914.65 tokens/s
  • After: Throughput: 24.52 requests/s, 10138.92 tokens/s

Copy link

github-actions bot commented Aug 1, 2024

👋 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 consists a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of default ones by unblocking the steps in your fast-check build on Buildkite UI.

Once the PR is approved and ready to go, please make sure to run full CI as it is required to merge (or just use auto-merge).

To run full CI, you can do one of these:

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

🚀

@WoosukKwon WoosukKwon added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 1, 2024
Copy link
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

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

lgtm!

vllm/sequence.py Outdated Show resolved Hide resolved
vllm/sequence.py Outdated Show resolved Hide resolved
@@ -458,25 +459,24 @@ def __init__(
self.prompt_adapter_request = prompt_adapter_request
self.encoder_seq = encoder_seq
self.trace_headers = trace_headers
self._first_seq = next(iter(self.seqs_dict.values()))
Copy link
Member

Choose a reason for hiding this comment

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

I think you can still keep self._first_seq = seqs[0] , and use it to replace self.seqs[0]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it doesn't hurt much to use seqs[0] without caching it? _first_seq was introduced to avoid the overhead of retrieving a value from the dictionary. I believe the overhead of seqs[0] will be negligible even if it's Python.

Also, since the sequence can be removed, I feel more comfortable with self.seqs[0] than caching the sequence.

Copy link
Member

@youkaichao youkaichao left a comment

Choose a reason for hiding this comment

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

Glad to see it helps performance.

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