[Core] Get KV from Block, add KV to Block#6808
[Core] Get KV from Block, add KV to Block#6808KrishnaM251 wants to merge 14 commits intovllm-project:mainfrom
Conversation
|
👋 Hi! Thank you for contributing to the vLLM project. 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:
🚀 |
|
Thank you @KrishnaM251 for the thoughts you put into this! As an initial step, let's just focus on implementing the |
🚧 WIP (currently not functioning) 🚧
Background
Adding functionality to begin implementing SSD offloading.
A nice beginning step for SSD offloading is to extend this part of the code so that it supports 2 APIs:
get_kv_cache_from_block(block: Block), a function that can return the corresponding KV cache of the given blockput_kv_cache_into_block(block: Block, kvcache: List[Tensor]), a function that can put the KV cache into the corresponding block.We can then start to implement SSD offloading from these two APIs.
Change Log
[v0.3] - simple
coreonly implementation[v0.3.1]
get_kv_from_blockat theblock_manager_v2.pylevelget_kv_from_blocksimply calls lower level methods from within core to obtain the kv_cache without going to the workerprepare_worker_inputfromworker.pyas inspiration[v0.2] - kv_from_block
Summary
get_kv_cache_from_block, a function that obtains the KV cache of a single working blockget_kv_cache_from_blockfunction, we arbitrarily mark a prempted block as the block we want to extract the kv cache from (see below for details).--preemption-modeflag called "offload" which enables requests to piggyback off of _preempt's existing implementation.kv_from_block, which gets passed between the scheduler and the worker during the execution of step_asynckv_from_blockis aDict[int, int]so that in the future we may easily extend to multiple block-to-kv mappings (instead of just one)Concerns
get_kv_cache_from_blockto thecorelevel (i.e. scheduler.py) and belowkv_from_blocktoSamplerOutputs[v0.1] - buffer
I noticed that
step_asyncinasync_llm_engine.pyis at the intersection of the scheduler and the worker/cache engine (see code). Since scheduling occurs before worker execution, I reasoned that we must somehow indicate at the scheduler level what blocks / KV caches we want to deal with. On top of this, to facilitate communication between the worker and the schedule, I opted to pass a buffer from the scheduler output to the cache engine. The initial PR is merely scaffolding, and is non-functional. Please let me know of any thoughts or concerns by answering the questions in the Questions section below.Questions
n/a
CC List
@KuntaiDu @comaniac
BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE
PR Checklist (Click to Expand)
Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.
PR Title and Classification
Only specific types of PRs will be reviewed. 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.[Frontend]For changes on the vLLM frontend (e.g., OpenAI API server,LLMclass, etc.)[Kernel]for changes affecting CUDA kernels or other compute kernels.[Core]for changes in the core vLLM logic (e.g.,LLMEngine,AsyncLLMEngine,Scheduler, etc.)[Hardware][Vendor]for hardware-specific changes. Vendor name should appear in the prefix (e.g.,[Hardware][AMD]).[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:
format.shto format your code.docs/source/if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.Notes for Large Changes
Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with
rfc-requiredand might not go through the PR.What to Expect for the Reviews
The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:
action-requiredlabel on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.Thank You
Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!