-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
[Core] Implementing disaggregated prefilling, and caching KV cache in CPU/disk/database. #8498
base: main
Are you sure you want to change the base?
Conversation
👋 Hi! Thank you for contributing to the vLLM project. 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 do one of these:
🚀 |
eb751d6
to
60ede08
Compare
/cc |
@KuntaiDu this is ready to review? |
Final bug fix on TP case when connecting to LMCache. Will ping you when it's ready for review (most likely tomorrow) |
It‘s a good job! |
@rkooo567 Now this code is ready for review |
Lol huggingface is down and I will rerun the test tomorrow. |
mark |
1 similar comment
mark |
All tests are now passed! |
@KuntaiDu hi !According to your commit, I implemented valkey (supporting TCP and rdma) as the kv cache storage pool in the prefill and decode nodes(#8724). Due to license reasons, I implemented valkey instead of redis, and valkey also supports rdma after version 8.0. Can you give me some suggestions? |
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.
First review the changes in the vLLM core.
vllm/distributed/parallel_state.py
Outdated
- 2 * tp * pp | ||
- Why: both prefill vLLM and decode vLLM is in the world |
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.
Does that mean we now only support 1-prefill + 1-decode?
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.
Yes for this PR. Support on multi prefil and multi decode vllm instances with different tp/pp is on the roadmap but not in this PR.
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 guess you are wondering if this architecture is scalable enough to support XpYd scenario. It can. Here is a planned architecture:
(prefill worker --- database frontend) --- database backend --- (database frontend --- decode worker)
The instances in the same bracket share the same world in torch.distributed
.
Basically for XpYd & multiple prefill multiple decode worker scenario, I am planning to not connect prefill worker to decoder worker. Instead, I will connect them to a database and let the database handle all the network topology related optimizations and let it handle different tp/pp conversion.
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.
So in summary if we want to achieve XpYd, then we should separately configure Xp workers and Yd workers. Can you elaborate how to configure Xp workers as an example? I suppose we will only configure KV producer?
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.
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.
(And LMCache can be one example solution for the database. It implements this frontend and backend, and the frontend placement can be in various places (CPU, GPU, disk)).
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.
Right now, to configure Xp workers and Yd workers will be quite messy in parallel state. For example, when we have 4 prefill workers(TP=4) and 2 decode workers(TP=2), world size will not be 4 * 2 here, and _DISAGG
tuples will not be one to one. Another issue will occur in torch_distributed_pipe
. Since send operations and recv operations will be doubled when prefill has twice worker as decode.
Even with a database, the database frontend will need to manage the difference between prefill workers and decode workers, and perform concat
or scatter
operations when necessary.
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.
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.
Yes, but the overhead is engineeringly optimizable by, e.g., pipelining the send/recv of the KV cache with model forwarding, or by using RDMA database, etc.
Rest assured that we are planning to support both one-hop connection (i.e. prefiller directly connected to decoder) and two-hop connection (i.e. prefiller --- database --- decoder).
Thank you (rdma yes!). I left some comments to your PR. |
Thanks! |
Hi @KuntaiDu I'm the author of Valkey Over RDMA, please feel free to contact me [email protected] on any issue or suggestion. |
@comaniac I have fixed the comments. Thank you for your review 😄. As for the hidden states send/recv and sampler output send/recv, I need to do some extra model runner condition checks, and I will make a follow-up PR to do this (this PR is already huge). |
vllm/worker/model_runner.py
Outdated
bypass_model_exec = False | ||
if self.need_recv_kv(model_input, kv_caches): | ||
hidden_or_intermediate_states, bypass_model_exec, model_input = \ | ||
get_disagg_group().recv_kv_caches_and_hidden_states( |
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.
Just curious. Is this recv function blocking?
It seems to me that adding an independent thread that constantly waiting for kvcache might hide the communication cost, but I am not sure if this is feasible under current block manager logic.
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.
Yeah currently it is blocking (and it is an intentional design choice).
Reasons behind this design:
- Transfer delay is not significant (~5ms). Most of the overheads in the implementation is tokenizing the whole request twice and de-tokenizing the first token twice (~20ms). Optimizing other overheads will give us more perf improvement.
- Non-blocking KV transfer requires adding GPU buffer at decoding vLLM side. Since decoding is memory-bounded, this is not ideal (as buffering reduces # of available GPU memory for decoding KV caches).
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.
- Transfer delay is not significant (~5ms). Most of the overheads in the implementation is tokenizing the whole request twice and de-tokenizing the first token twice (~20ms).
Thanks for this helpful information! I agree with your observation. Skipping sampling & output processor in prefill side and sending kvcache immediately after hidden states will be more significant.
It would be nice if the decode part could support non-blocking reception and continious batching. |
when the consumer receives a complete new request , should it work or reject it?in this case, should we add some warnings? |
The goal of this PR is to create minimum core change so that people can easily understand the code when review it. We can add this optimization in future PRs. |
It will redo the prefill. Currently we won't show a warning, but we do expect some logging and warning mechanism in the future. |
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.
Took a pass to the kv transfer implementation. Overall is clean is easy to follow. Will take a deeper look at the performance later.
Meanwhile, @youkaichao could you take a look at the parallel states? The current way of handling torch.distributed is a bit messy, but I don't have a better way to deal with it in my mind.
@rkooo567 please also take a look at the parallel states. I believe the current implementation would have some issues with Ray integration.
vllm/distributed/parallel_state.py
Outdated
- 2 * tp * pp | ||
- Why: both prefill vLLM and decode vLLM is in the world |
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.
So in summary if we want to achieve XpYd, then we should separately configure Xp workers and Yd workers. Can you elaborate how to configure Xp workers as an example? I suppose we will only configure KV producer?
@@ -0,0 +1,444 @@ | |||
"""vLLM distributed KV cache transfer API. |
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.
Is there any planned adaptor in the future?
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.
Personally I feel vLLM will only have one adapter (not sure if other guys will implement new adapters in vLLM tho). But I do expect that other applications (like other serving engines, or a KV database application) implement their own adapters to integrate the transferred KV caches to their application workflow.
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 see that's interesting. So you're expecting someone to just from vllm.distributed import kv_transfer
, and only use the kv_transfer
for other frameworks?
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.
Yes. I am expecting different applications to follow the same set of kv_transfer
protocol so that they can communicate with vLLM (by, for example, "pretending" to be a vLLM decode instance).
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.
Also kv_transfer
library is intentionally designed in a way that it has no code dependency on vLLM so that other applications can use it.
@comaniac Thanks for reviewing! Code changes done. Also pinged Kaichao for further review on Performance-wise, here are some bottlenecks I know (these bottlenecks are sorted by how significant they are).
|
Signed-off-by: Russell Bryant <[email protected]>
…lm-project#9766) Signed-off-by: ElizaWszola <[email protected]>
…lls (vllm-project#10452) Signed-off-by: Max de Bayser <[email protected]>
Signed-off-by: Alexei V. Ivanov <[email protected]>
Signed-off-by: Lucas Wilkinson <[email protected]>
Signed-off-by: Yanyi Liu <[email protected]>
…ading (vllm-project#10456) Signed-off-by: Isotr0py <[email protected]>
…t#10470) Signed-off-by: DarkLight1337 <[email protected]>
Signed-off-by: skylee-01 <[email protected]>
…ect#10471) Signed-off-by: DarkLight1337 <[email protected]>
Signed-off-by: MengqingCao <[email protected]>
Signed-off-by: Kuntai Du <[email protected]>
Signed-off-by: Kuntai Du <[email protected]>
529c425
to
1780820
Compare
This pull request has merge conflicts that must be resolved before it can be |
lol something happened when I tried to sign off. I'll fix it tmrw |
TL; DR: implemented disaggregated prefill with <100 core line change (and most of them are comments)
This PR is a continuation of PR #6170 , with a new design that allows future extension.
Current supported applications:
examples/disagg_prefill/disagg_prefill_example.sh
for an example, andbenchmarks/disagg_prefill
for various benchmarks. Benchmarking script are all one-click runnable (after settingHF_TOKEN
)LMCache
. Examples TBD.Two roles: KV provider (e.g. prefill vLLM instance) and KV consumer (e.g. decode vLLM instance)
insert
: insert a KV cache to a buffer, so that it can be transferred upon requestdrop_select
: select a KV cache based on tokens, transfer the selected KV, and drop this KV out from the bufferExample workflow (the
buffer
in the following figure is the same asinsert
)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:
format.sh
to 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.Adding or changing kernels
Each custom kernel needs a schema and one or more implementations to be registered with PyTorch.
Tensors
require meta-functions. Meta-functions should be implemented and registered in python so that dynamic dims can be handled automatically. See above documents for a description of meta-functions.torch.libary.opcheck()
to test the function registration and meta-function for any registered ops. Seetests/kernels
for examples.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:
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.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!