Skip to content

[Core] Get KV from Block, add KV to Block#6808

Closed
KrishnaM251 wants to merge 14 commits intovllm-project:mainfrom
KrishnaM251:kvcache-transfer
Closed

[Core] Get KV from Block, add KV to Block#6808
KrishnaM251 wants to merge 14 commits intovllm-project:mainfrom
KrishnaM251:kvcache-transfer

Conversation

@KrishnaM251
Copy link
Copy Markdown
Contributor

@KrishnaM251 KrishnaM251 commented Jul 26, 2024

🚧 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 block
  • put_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 core only implementation

[v0.3.1]

  • implemented get_kv_from_block at the block_manager_v2.py level
  • get_kv_from_block simply calls lower level methods from within core to obtain the kv_cache without going to the worker
    • used the prepare_worker_input from worker.py as inspiration

[v0.2] - kv_from_block

Summary

  • This version focuses on getting a simple working implementation of get_kv_cache_from_block, a function that obtains the KV cache of a single working block
    • Note that in this version, rather than having a get_kv_cache_from_block function, we arbitrarily mark a prempted block as the block we want to extract the kv cache from (see below for details).
  • I added a new option for the --preemption-mode flag called "offload" which enables requests to piggyback off of _preempt's existing implementation.
    • This is because eventually, we will want certain preempted sequences to be offloaded to the SSD
  • During one decoding iteration (step_async), we arbitrarily choose one block to get the KV cache from
  • The relevant Block and KV is stored in an object called kv_from_block, which gets passed between the scheduler and the worker during the execution of step_async
    • kv_from_block is a Dict[int, int] so that in the future we may easily extend to multiple block-to-kv mappings (instead of just one)
  • The KV cache can be found in the

Concerns

  • This implementation is initiated at the API Server level, and results get returned to API Server level
    • We want to confine the execution / results of get_kv_cache_from_block to the core level (i.e. scheduler.py) and below
  • I have not tested this yet (will begin after pushing this).
  • line 285 of worker_base.py is incorrect, need to find proper way to add kv_from_block to SamplerOutputs

[v0.1] - buffer

I noticed that step_async in async_llm_engine.py is 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, LLM class, 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:

  • We adhere to Google Python style guide and Google C++ style guide.
  • Pass all linter checks. Please use format.sh to format your code.
  • The code need to be well-documented to ensure future contributors can easily understand the code.
  • Include sufficient tests to ensure the project to stay correct and robust. This includes both unit tests and integration tests.
  • Please add documentation to 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-required and 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:

  • After the PR is submitted, the PR will be assigned to a reviewer. Every reviewer will pick up the PRs based on their expertise and availability.
  • After the PR is assigned, the reviewer will provide status update every 2-3 days. If the PR is not reviewed within 7 days, please feel free to ping the reviewer or the vLLM team.
  • After the review, the reviewer will put an action-required label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.
  • Please respond to all comments within a reasonable time frame. If a comment isn't clear or you disagree with a suggestion, feel free to ask for clarification or discuss the suggestion.

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!

@github-actions
Copy link
Copy Markdown

👋 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 consists a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of default ones by unblocking the steps in your fast-check build on Buildkite UI.

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:

  • Comment /ready on the PR
  • Add ready label to the PR
  • Enable auto-merge.

🚀

@KuntaiDu
Copy link
Copy Markdown
Collaborator

Thank you @KrishnaM251 for the thoughts you put into this! As an initial step, let's just focus on implementing the get_kv_cache_from_block and put_kv_cache_into_block for just one block as a way to get you more familiarized with the code base (and these 2 functions are definitely useful for future implementation). No need to implement the buffer for now.

@KrishnaM251 KrishnaM251 marked this pull request as draft July 30, 2024 00:38
@KrishnaM251 KrishnaM251 deleted the kvcache-transfer branch July 30, 2024 18:32
@KrishnaM251 KrishnaM251 restored the kvcache-transfer branch July 30, 2024 18:36
@KrishnaM251 KrishnaM251 reopened this Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants