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

Optimize the KV transfer pipe implementation #3

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

ApostaC
Copy link
Collaborator

@ApostaC ApostaC commented Sep 10, 2024

Main changes

  • Removed useless dependencies and unused variables
  • Avoid cudaMemcpyH2D by removing to(self.device)
  • Change the way of sending metadata. Now all the metadata will be sent/recved in a single tensor with a single H2D/D2H copy
  • Change what is being done in the sender's thread to avoid underutilization caused by GIL

Performance benchmark

The numbers are tested between 2 A40s WITHOUT NVLINK

Average latency (ms) 10% latency (ms) Median latency (ms) 90% latency (ms) 98% latency (ms)
Original version 193.1 150.7 198.0 211.8 368.5
Fix to(self.device) 64.33 56.38 56.98 70.42 139.16
Final version 52.52 45.84 46.72 52.72 64.59

Notes

We should still avoid sending too many tensors. The current implementation needs a single H2D/D2H memcpy when dealing with metadata, where Each H2D/D2H call will incur a fixed 100~200us overhead. (The overhead mainly comes from synchronization between nccl stream and default stream).

It takes 400~500us for NCCL to send/recv a tensor of ~4Mbytes (2000 tokens * 1024 hidden dimensions * 1 layer * BF16), which means the H2D/D2H memcpy overhead can be as large as 20~30%.

This overhead will be decreased when the size of the tensor grows larger. When sending 80 layers together, the estimated overhead is only 2~3%.

@KuntaiDu Please also test it under NVLink environments and let me know if there is any unexpected problems.

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 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.

🚀

Copy link
Owner

@KuntaiDu KuntaiDu left a comment

Choose a reason for hiding this comment

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

LGTM

@KuntaiDu KuntaiDu merged commit 1377912 into kuntai-disagg-refactor Sep 11, 2024
1 check passed
KuntaiDu added a commit that referenced this pull request Nov 20, 2024
Optimize the KV transfer pipe implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants