vllm
vllm copied to clipboard
[Core] Sliding window for block manager v2
This implements sliding window in v2 block manager.
First commit comes from #3967 by @ruthe98, but the actual change was somewhat more complex including the concept of a null block.
It passes correctness tests with starcoder3b (the smallest model with sliding window I could find). The test does a bunch of assignments "x1 = 10; x2 = 33; ..." and then asks for value of one of them (which is outside the sliding window). If we tell it upfront which we are going to be looking for, then it answers correctly.
When using chunked prefill all the blocks for prompt are allocated immediately, while we could only allocate enough blocks for the chunk, and free any blocks that are no longer needed. After processing the prompt however, it does free the beginning of prompt at the first generation step.
This can be fixed later. The main problem with fixing this, is that if we're generating more than one sequence, they are all forked in BlockSpaceManagerV2.allocate(), but they really should only be forked after the prompt is fully computed. (see aborted attempt at fixing this)
CC @cadedaniel @ruthe98
FIX #3665 FIX #4057
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:
- We adhere to Google Python style guide and Google C++ style guide.
- Pass all linter checks. Please use
format.shto 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-requiredlabel 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!
-
FYI prefix caching + sliding window doesn't work with block manager v1 yet. so it's ok to prioritize that deprioritize that for this PR https://github.com/vllm-project/vllm/blob/b8afa8b95a4eee008a9b72440620113e5bfbe962/vllm/core/block_manager_v1.py#L218-L220
-
personally I think it's OK to allocate entire prompt len for chunked prefill. it's a compute optimization, not a memory capacity optimization, after all
-
for testing, we can copy this test except run a sliding window model. it's important to go over the sliding window boundary (although in general the sliding window test coverage is pretty poor). I think one can mock the sliding window size to be much smaller for test convenience, FYI. https://github.com/vllm-project/vllm/blob/b8afa8b95a4eee008a9b72440620113e5bfbe962/tests/core/block/e2e/test_correctness.py#L28
@cadedaniel @rkooo567 @simon-mo this should be ready for review
WTAL on Monday
QQ: is this the last feature that's needed before enabling block manager v2?
See https://github.com/vllm-project/vllm/issues/4537
Hmm maybe I can help getting cpu swapping done
@cadedaniel let me know if you need any more info from my side!
oh didn't know this also covers chunked prefill. I will make sure to finish review it by tmrw!
@cadedaniel @rkooo567 should be good for another review
@cadedaniel @rkooo567 anything I can help with?
I will have the final look today!
sorry it's been slipped! I will take a look at it by tmrw!
@mmoskal can you check the merge conflict? will merge after
Unfortunately, after merge the tests stopped working. The problem is that it's also the baseline tests (not using v2 block manager) that are not working. I'm getting the first token of the output correct, and the remaining tokens not complete gibberish but also not correct - so this is a problem with the decode phase or maybe kv cache entry arrangement?
I tried reverting all my changes in model_runner.py and the baseline tests still fail, which suggests it's something in the recent changes.
OK should work now - I fixed slot_mapping computation in _prepare_model_input
as soon are tests are green let's merge. cc @rkooo567 for next week.
the failing tests don't look related to what I'm doing; I just tried pushing a random change to re-run
@rkooo567 @cadedaniel tests are green, please merge!
Thanks for the contribution! Should we next resume the paged attn PR?
Thank you for merging! I probably won't have time to work on the paged attn kernel PR in the next few weeks :/ The thing is, with this PR the paged attention is almost correct, it just pays attention to a few tokens too many.