-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
[2/N] Chunked prefill data update #3538
[2/N] Chunked prefill data update #3538
Conversation
vllm/worker/model_runner.py
Outdated
@@ -819,8 +840,7 @@ def capture_model(self, kv_caches: List[torch.Tensor]) -> None: | |||
context_lens=context_lens[:batch_size], | |||
block_tables=block_tables[:batch_size], | |||
use_cuda_graph=True, | |||
kv_cache_dtype=self.kv_cache_dtype, | |||
) | |||
kv_cache_dtype=self.kv_cache_dtype) |
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.
nit: What is this change for?
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.
Hmm not sure why it is formatted. Reverted
@WoosukKwon I just pushed a change based on #3538 (comment) comment (the previous commit works, but the commit with this change is not cleaned up yet. I pushed it to demonstrate the difference). Can you take a look at 5e0f87e and see if you feel less hacky this way (or the previous one is better, or lmk if you have the third option I can take). |
@@ -27,18 +27,40 @@ class PreemptionMode(enum.Enum): | |||
RECOMPUTE = enum.auto() | |||
|
|||
|
|||
class ScheduledSequenceGroup: |
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.
TODO remove and use tuple
vllm/worker/model_runner.py
Outdated
@@ -819,8 +840,7 @@ def capture_model(self, kv_caches: List[torch.Tensor]) -> None: | |||
context_lens=context_lens[:batch_size], | |||
block_tables=block_tables[:batch_size], | |||
use_cuda_graph=True, | |||
kv_cache_dtype=self.kv_cache_dtype, | |||
) | |||
kv_cache_dtype=self.kv_cache_dtype) |
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.
Hmm not sure why it is formatted. Reverted
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 is updated based on the initial feedback (to make it more general).
- Removed max_chunk_prefill_len. Instead, we will infer this value from max_batched_tokens in the future PR (which is equivalent to the paper https://arxiv.org/pdf/2403.02310.pdf). Thank you @AgrawalAmey !
- Instead of updating prefill range, I record "computed_tokens", which is 1 for decoding and chunk size for prefill. Scheduler and SequenceGroupMetadata is updated accordingly.
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 for doing this. I left mostly style and clarification comments.
The only thing about the chunk size value during decode. I'm fine with whatever you end up with as long as we have it well documented.
vllm/sequence.py
Outdated
def on_recompute(self): | ||
"""Reset the sequence states for recomputation.""" | ||
self.data.reset_num_computed_tokens() |
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.
maybe call this reset_state
so it's easier to understand. recompute
is when reset is needed (currently the only scenario but very specific) but this operation is just resetting.
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.
The confusing part (and the reason why I chose more specific term here) is that it actually doesn't "reset" the state because reset sounds like output_token_ids are also cleared. But this API doesn't do that. What about reset_state_for_recompute?
if is_prompt: | ||
self._token_chunk_size = list(seq_data.values())[0].get_len() | ||
else: | ||
self._token_chunk_size = 1 |
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 the value here is not meaningful because it's not accessed for decode, now i wonder whether it make sense to use None
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.
No strong opinion. I just thought it makes more sense as API (that it returns 1 than None). Also less confusing because scheduler returns token_chunk_size == 1 when it is decoding.
Thanks for reviewing the PR at late night @simon-mo ! Addressing comments rn... |
comments are addressed |
It is the second PR to enable chunked prefill.
This PR introduces prefill's start and end indexes and API to access them. Also add metadata to
SequenceGroupMetadata
to indicate if the seq_group is in chunked prefill stage.Ideally, this mechanism should be unified to computed_num_blocks approach, but I will do this after merging chunked prefill PRs (since it already works e2e).
Related #3130
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:
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.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!