-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
[V1] Large Block_size solution #21123
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
base: main
Are you sure you want to change the base?
Conversation
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run 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 either: Add 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces an intelligent way to calculate the optimal block size for hybrid models, which should improve memory efficiency. The core logic for the calculation in kv_cache_coordinator.py
is robust and handles edge cases well. The integration in kv_cache_utils.py
is also well-structured.
I've identified one high-severity issue regarding error handling. The use of a broad, silent except Exception
could mask bugs and should be updated to include logging for better maintainability and easier debugging. Other than that, the changes look good.
5d7de66
to
0061d19
Compare
This pull request has merge conflicts that must be resolved before it can be |
0061d19
to
99a755a
Compare
Introduces BlockHash and BlockHashWithGroupId NamedTuple classes for KV cache prefix caching, including support for token IDs, extra keys, and group IDs to facilitate multi‑group cache management and reduce hash collisions. Signed-off-by: WorldExplored <[email protected]>
99a755a
to
f38a044
Compare
Fixed some errors with BlockPool and other files in the core directory. Signed-off-by: WorldExplored <[email protected]>
2148f1c
to
897fc1b
Compare
This PR has mostly fallen apart. The force-push in the commit history wiped my original edits and fixes, but I had worked out a solution to your proposed changes and could use feedback and a bit of guidance on next steps. Restating the original problem: Block sizes are extremely large (~400 tokens) because the current constraint requires: kv_hidden_size * block_size of one attention layer ≥ mamba state size of one layer Main idea: Reduce attention block size to ~100 tokens (what they actually need) instead of ~400 tokens (padded to match mamba). Let's say 1 Aggregation unit = physical memory size of 1 mamba block.
this is only possible if all allocation/deallocation happens at the unit level, not block level. This gives us the memory savings (attention uses 100-token blocks) while maintaining interchangeability (units are swappable). The memory layout would look something like this:
This preserves the interleaving pattern across KVCacheTensors at the unit level. Key Changes:
The most important thing to this idea is decoupling the logical block management at unit level from physical block access at the sub-block level. My concerns are:
What are your thoughts? And should I make a new PR for this, (citing and closing this one). Let me know if I missed a concern you had. Apologies for the confusion. Thanks for the support. |
I think large block size and (2, num_block) layout may be coupled. But for simplifying code review, @nadathurv can you first work on large block size problem, and then extend it to (2, num_block) layout to enable more attention backends? |
@heheda12345 Got it. It will be addressed in a new PR I will cite it here once done. |
This is the updated and current work on this issue. It is related to the To-Do item
Original Problem
Hybrid models were using extremely large block sizes (~400 tokens) due to individual layer constraints. Each attention layer was padded so that
kv_hidden_size * block_size
of one layer was larger than the mamba state size of one layer, leading to inefficient memory usage.Solution
Implement aggregate constraint approach instead of individual layer constraints:
Before: Each layer individually satisfies mamba state requirement
After: Combined memory of all attention layers satisfies mamba state requirement
Key Changes
kv_cache_coordinator.py
: Addcalculate_optimal_block_size()
methodmax_mamba_state / (num_attention_layers * min_per_token_bytes)
OPTIMAL_BLOCK_FALLBACK
when calculation failskv_cache_utils.py
: Add_get_kv_cache_config_optimal_block_size()
integrationget_kv_cache_config()
flow for hybrid modelscc @heheda12345 @tlrmchlsmth
Outdated links: Original Work