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

[V1] Implement Cascade Attention #11635

Merged
merged 23 commits into from
Jan 1, 2025
Merged

[V1] Implement Cascade Attention #11635

merged 23 commits into from
Jan 1, 2025

Conversation

WoosukKwon
Copy link
Collaborator

@WoosukKwon WoosukKwon commented Dec 30, 2024

This PR implements a simple version of Cascade Attention. Cascade attention can save the HBM bandwidth for reading KV cache when requests share the same prefix.

NOTE: For simplicity, this PR only uses cascade attention when every running request shares the same KV cache. If one or more requests do not share the KV cache, cascade attention is not used.

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.

🚀

@mergify mergify bot added the ci/build label Dec 30, 2024
Signed-off-by: Woosuk Kwon <[email protected]>
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.

Overall LGTM. The implementation is pretty clean. One optimization we can do in the future is having a wrapper CUDA kernel in flash attention so that we can save kernel invocation overheads. This is how FlashInfer does as well.

@raywanb since you've worked on FlashInfer cascade kernel integration in v0, can you also take a look at the current v1 interface and see if this interface can integrate FlashInfer easily in the future?

vllm/v1/core/kv_cache_manager.py Outdated Show resolved Hide resolved
vllm/v1/core/kv_cache_manager.py Outdated Show resolved Hide resolved
vllm/v1/worker/gpu_model_runner.py Outdated Show resolved Hide resolved
vllm/v1/attention/backends/flash_attn.py Outdated Show resolved Hide resolved
vllm/v1/attention/backends/flash_attn.py Outdated Show resolved Hide resolved
@raywanb
Copy link
Contributor

raywanb commented Dec 31, 2024

Overall LGTM. The implementation is pretty clean. One optimization we can do in the future is having a wrapper CUDA kernel in flash attention so that we can save kernel invocation overheads. This is how FlashInfer does as well.

@raywanb since you've worked on FlashInfer cascade kernel integration in v0, can you also take a look at the current v1 interface and see if this interface can integrate FlashInfer easily in the future?

Yes, seems pretty straightforward to integrate Flashinfer!

Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
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. Just two minor questions.
Also do you have a unit test to verify the correctness?

vllm/v1/core/kv_cache_manager.py Outdated Show resolved Hide resolved
vllm/v1/worker/gpu_model_runner.py Outdated Show resolved Hide resolved
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
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.

Thanks for adding this! I'll probably try to benchmark this feature next week if I got a chance.

Signed-off-by: Woosuk Kwon <[email protected]>
@WoosukKwon WoosukKwon added the ready ONLY add when PR is ready to merge/full CI is needed label Jan 1, 2025
@WoosukKwon WoosukKwon merged commit 7300144 into main Jan 1, 2025
89 of 92 checks passed
@WoosukKwon WoosukKwon deleted the v1-cascade branch January 1, 2025 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/build 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