[feat] Support hybrid allocator#1436
Conversation
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
There was a problem hiding this comment.
Summary of Changes
Hello @KuntaiDu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces support for a hybrid allocator within LMCache, enabling more flexible and potentially optimized management of KV (Key-Value) cache memory. This change is designed to work in conjunction with related updates in the vLLM project, specifically targeting improvements in how KV cache groups are handled across different layers of a model.
Highlights
- Hybrid Allocator Configuration: New fields have been added to LMCacheEngineMetadata to configure layer-to-KV-cache-group mappings, facilitating the setup of a hybrid memory allocation scheme.
- KV Cache Group Management: The internal RequestTracker and ReqMeta structures have been updated to manage allocated_block_ids and slot_mappings as dictionaries, allowing for distinct KV cache groups per layer or group of layers.
- VLLM Integration Updates: The integration with vLLM has been refined to align with vLLM 0.9.0+ block ID handling, ensuring compatibility and proper propagation of KV cache group information during request processing.
- GPU Connector Enhancements: The GPU memory connector now incorporates KV cache group awareness, enabling batched operations (batched_to_gpu, batched_from_gpu) to correctly handle and map memory operations to their respective KV cache groups.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces support for a hybrid allocator in LMCache, which involves significant changes across the configuration, vLLM adapter, and GPU connector. The changes are well-structured to handle multiple KV cache groups. I've found one critical issue that could lead to a runtime error, which I've detailed in a specific comment. Overall, the changes are in the right direction to support the new feature.
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
YaoJiayi
left a comment
There was a problem hiding this comment.
Thanks! Left a few comments:)
| self, | ||
| new_token_ids: list[int], | ||
| new_block_ids: Union[Optional[tuple[list[int], ...]], list[int]], | ||
| new_block_ids: Optional[tuple[list[int], ...]], |
There was a problem hiding this comment.
@maobaolong @chunxiaozheng Do we still need backward compatibility here?
| token_ids=token_ids, | ||
| slot_mapping=slot_mapping, | ||
| slot_mappings=slot_mappings, | ||
| slot_mapping=slot_mappings[0], |
There was a problem hiding this comment.
What's the difference between slot_mapping and slot_mappings?
There was a problem hiding this comment.
slot_mapping == slot_mappings[0]. Basically slot mapping only contain the first KV cache group. This is for test compatibility.
| kvcaches=kvcaches, | ||
| slot_mapping=slot_mapping[:lmcache_cached_tokens], | ||
| # FIXME(Kuntai): need to support multiple kv cache groups | ||
| slot_mapping=slot_mappings[0][:lmcache_cached_tokens], |
There was a problem hiding this comment.
The todo is to fully deprecate slot_mapping in all connectors and substitute them with slot_mappings.
There was a problem hiding this comment.
I am planning to rename it to group_id_to_slot_mapping as slot_mappings looks too similar to slot_mapping (and I have several bugs that was simply because I misread slot_mappings to slot_mapping). Does that sound good to you @YaoJiayi ?
There was a problem hiding this comment.
Just talked to @ApostaC . @YaoJiayi the plan is:
- write a gpu connector that only handles the hybrid KV cache allocator, and leave all other gpu connectors unchanged. We will refactor other gpu connectors in future PRs
- Stick to
slot_mappings, and make it a tensor with shape[# of kv cache groups, # of tokens].
|
|
||
| self.dtype = kwargs["dtype"] | ||
| self.device = kwargs["device"] | ||
| self.layer_id_to_kv_cache_group_id = kwargs.get( |
There was a problem hiding this comment.
Can we have two global mappings for layer_name_to_kv_cache_group_id and layer_id_to_kv_cache_group_id so the all gpu connectors can benefit from them in the future?
There was a problem hiding this comment.
I thought in the future, there may be multiple vLLM instances on the same machine connecting to one LMCache process (which is a result @ApostaC 's proposal about separating connector process from vLLM process) and in that case we need to have different layer_name_to_kv_cache_group_id for different connector. Is that the case @ApostaC ?
There was a problem hiding this comment.
@YaoJiayi I confirmed with @ApostaC that the case that I mentioned will happen. In this case I guess it's better for us to keep layer_name_to_kv_cache_group_id local to the gpu connector class. I will still separate the logic of converting kv_cache_config to layer_name_to_kv_cache_group_id to a util function.
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
…name to kv cache group id Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
…gpu connectors Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
… storage manager Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
…v_cache_group_id in new VLLMPagedMemLayerwiseGPUConnectorForHybridAlloc. This is doable because it is separated into a new connector and previous version of vLLM will no longer touch VLLMPagedMemLayerwiseGPUConnectorForHybridAlloc Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
|
New updates:
Not covered in this PR (we can do it in future PRs)
This PR is ready for review. |
…ata --- now it is tied to gpu connector Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
| slot_mappings: torch.Tensor | ||
| # Slot mapping for backward compatibility |
There was a problem hiding this comment.
Probably we want a unified interface to get the slot mapping
|
TODO:
|
…t to avoid spamming Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
…back to LMCache, as it needs more careful design to be pushed into vllm Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
…back to LMCache, as it needs more careful design to be pushed into vllm Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
Signed-off-by: KuntaiDu <kuntai@uchicago.edu>
|
Bump, would love to use this feature and let me know if I can help in anyway ! |
|
This feature is being deprioritized for now :( , this is a pure performance PR and is less urgent than feature PRs (e.g. process disaggregation, P2P backend. |
Currently vLLM crashes when LMCache is enabled for models that requires hybrid kv cache(e.g. Qwen3-Next-80B-A3B-Instruct) |
|
This pull request has been automatically marked as stale because it has not had activity within 60 days. It will be automatically closed if no further activity occurs within 30 days. |
|
vllm is still crashing with this error are there any plan to support hybrid models? |
|
Hello, |
|
We are switching to LMCache multiprocess mode, which allows full separation between vllm container and LMCache container. After finalizing the support of multiprocess mode we will then start to circle back to hybrid model. |
|
hi, i tried qwen 3.5 35B A3B FP8 with llmcache and the latest vllm and i have the following error "Hybrid KV cache manager is disabled but failed to convert the KV cache specs to one unified type" |
I noticed vLLM has continued working on the hybrid allocator in vllm-project/vllm#30166 (and support is now merged). The original PR mentionned is now Closed. |
|
This pull request has been automatically marked as stale because it has not had activity within 60 days. It will be automatically closed if no further activity occurs within 30 days. |
This PR supports hybrid allocator in LMCache. Need to work together with vllm-project/vllm#23624.
PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE
PR Checklist (Click to Expand)
Thank you for your contribution to LMCache! Before submitting the pull request, please ensure the PR meets the following criteria. This helps us maintain the code quality and improve the efficiency of the review process.
PR Title and Classification
Please try to classify PRs for easy understanding of the type of changes. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:
[Bugfix]for bug fixes.[CI/Build]for build or continuous integration improvements.[Doc]for documentation fixes and improvements.[Model]for adding a new model or improving an existing model. Model name should appear in the title.[Core]for changes in the core LMCache logic (e.g.,LMCacheEngine,Backendetc.)[Misc]for PRs that do not fit the above categories. Please use this sparingly.Note: If the PR spans more than one category, please include all relevant prefixes.
Code Quality
The PR need to meet the following code quality standards:
What to Expect for the Reviews
We aim to address all PRs in a timely manner. If no one reviews your PR within 5 days, please @-mention one of KuntaiDu, ApostaC or YaoJiayi.