-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
[KV offload][2/N] Introduce LRU-based CPU offloading management #20075
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
Conversation
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.
Summary of Changes
Hello @orozery, 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 a foundational system for managing the offloading of KV (Key-Value) data in vLLM v1. It establishes a flexible, pluggable architecture with an abstract OffloadingManager and Backend interface, enabling different storage mediums. The initial implementation provides an LRU-based management strategy and a concrete CPU memory backend, which is crucial for efficient memory utilization and handling of large language models.
Highlights
- New Offloading System Core: I've introduced an abstract
OffloadingManagerinterface for managing KV data offloading, along withLoadStoreSpecfor medium-specific data handling. This establishes the foundational architecture for flexible offloading. - LRU-based Management: I've implemented
LRUOffloadingManager, a concrete offloading manager that applies a Least Recently Used (LRU) eviction policy. This manager works with a pluggableBackendinterface to decide which blocks to evict when space is needed. - CPU Offloading Backend: I've added a concrete
CPUBackendimplementation for the offloading manager. This allows KV blocks to be efficiently offloaded to and managed within CPU memory, complete with block allocation and freeing mechanisms. - Storage Medium Specifications: I've defined specific
LoadStoreSpecimplementations for different storage mediums, includingGPULoadStoreSpecandCPULoadStoreSpec, to standardize how block data is referenced across various storage types. - Comprehensive Testing and CI Integration: I've included comprehensive unit tests for the
LRUOffloadingManagerandCPUBackendto verify correct functionality, including block storage, loading, lookup, and eviction logic. These tests have also been integrated into the.buildkite/test-pipeline.yamlto ensure continuous validation in the CI/CD process.
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 is currently in preview and 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 to provide feedback.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This PR introduces an LRU-based CPU offloading management system. It includes an OffloadingManager with a pluggable backend and a CPU backend. The system evicts blocks based on the LRU algorithm. I have suggested some improvements to the test cases and the LRU manager.
|
👋 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 🚀 |
a0cb125 to
11d5135
Compare
11d5135 to
d141661
Compare
|
Interested in this PR, and just wondering if the PR is currently runnable or not. |
a346c1b to
5c7cf02
Compare
74d048a to
dd72909
Compare
dd72909 to
852be73
Compare
852be73 to
e74cb03
Compare
Correct. |
ApostaC
left a comment
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.
Otherwise LGTM!
vllm/v1/offloading/lru_manager.py
Outdated
| raise NotImplementedError | ||
|
|
||
|
|
||
| class Backend(ABC): |
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.
Do you think it would be better to put the Backend class into a separate file? I feel like, rather than belonging to the lru_manager, it looks like an independent module that has a well-defined set of functionality.
A proposal:
- Have a file called
backend.pythat has the definition of theBackendclass. - The
lru_managerwill dofrom vllm.v1.offloading.backend import Backend - Have another folder called
offload_backends/undervllm/v1/offloading/, and put the CPU and potential future backend implementation there.
vllm/v1/offloading/lru_manager.py
Outdated
| if not self.blocks.get(block_hash): | ||
| continue | ||
| self.blocks.move_to_end(block_hash) |
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.
Will this also work? Just to simplify the code a bit.
| if not self.blocks.get(block_hash): | |
| continue | |
| self.blocks.move_to_end(block_hash) | |
| if block_hash in self.blocks: | |
| self.blocks.move_to_end(block_hash) |
vllm/v1/offloading/lru_manager.py
Outdated
| def lookup(self, block_hashes: list[int]) -> int: | ||
| hit_count = 0 | ||
| for block_hash in block_hashes: | ||
| block = self.blocks.get(block_hash) | ||
| if block is None or not block.is_ready: | ||
| break | ||
| hit_count += 1 | ||
| return hit_count |
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.
Will there be any race condition that the block is evicted after lookup counts the block as hit? This could potentially cause some correctness issues in the scheduler.
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.
For shared storage you're correct - there's a race.
But shared storage should actually not use LRU manager as the state is too big to keep in memory, and you would actually evict by some less exact mechanism than LRU (e.g. keeping each block for a fixed amount of time).
For CPU or local disk there is no race since they are fully owned by this specific scheduler instance.
e74cb03 to
3877a0b
Compare
ApostaC
left a comment
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.
LGTM!
njhill
left a comment
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.
Thanks @orozery. I think my comments are all style/efficiency related.
| from vllm.v1.offloading.abstract import LoadStoreSpec | ||
|
|
||
|
|
||
| class BlockStatus(ctypes.Structure): |
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.
Curious about the use of c struct for this in particular?
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.
I want to reduce the memory footprint per block.
From what I've read this allows to use more compact representation.
vllm/v1/offloading/backends/cpu.py
Outdated
| self.block_id = block_id | ||
|
|
||
| def get_load_store_spec(self, block_hash: int) -> CPULoadStoreSpec: | ||
| return CPULoadStoreSpec(self.block_id) |
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.
I may not be seeing the whole picture but do we need these wrapper types? We'll be creating many python objects when there's a lot of blocks...
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.
Changed to a single wrapper per list of blocks
| to_evict = [] | ||
| if num_blocks_to_evict > 0: | ||
| for block_hash, block in self.blocks.items(): | ||
| if block.ref_cnt == 0: |
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.
Would it be worth maintaining a count of unused blocks? then this check would be more efficient.
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.
We need to evict blocks by their LRU.
Right now I'm using a single ordered dict that holds all blocks, both "used" and "unused" (ref_cnt==0).
Most blocks should be unused, especially those whose LRU is the oldest, so this should be pretty good.
I don't see a good way to optimize it.
3877a0b to
220a35f
Compare
|
No ciflow labels are configured for this repo. |
220a35f to
43b44ec
Compare
This commit introduces an OffloadingManager with a pluggable backend, which evicts blocks by LRU. A CPU backend is included. Signed-off-by: Or Ozeri <[email protected]>
43b44ec to
2f04f0b
Compare
…-project#20075) Signed-off-by: Or Ozeri <[email protected]>
…-project#20075) Signed-off-by: Or Ozeri <[email protected]>
…-project#20075) Signed-off-by: Or Ozeri <[email protected]>
…-project#20075) Signed-off-by: Or Ozeri <[email protected]> Signed-off-by: charlifu <[email protected]>
…-project#20075) Signed-off-by: Or Ozeri <[email protected]> Signed-off-by: xuebwang-amd <[email protected]>
…-project#20075) Signed-off-by: Or Ozeri <[email protected]>
…-project#20075) Signed-off-by: Or Ozeri <[email protected]>
…-project#20075) Signed-off-by: Or Ozeri <[email protected]> Signed-off-by: xuebwang-amd <[email protected]>
This PR introduces an OffloadingManager with a pluggable backend, which evicts blocks by LRU.
A CPU backend is included.
Part of the work described in RFC #19854
Depends on #19848