Skip to content
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

Merged

Conversation

rkooo567
Copy link
Collaborator

@rkooo567 rkooo567 commented Mar 21, 2024

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:

  • 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!

benchmarks/benchmark_latency.py Outdated Show resolved Hide resolved
vllm/sequence.py Outdated Show resolved Hide resolved
@@ -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)
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

@rkooo567
Copy link
Collaborator Author

rkooo567 commented Mar 27, 2024

@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:
Copy link
Collaborator Author

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

@@ -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)
Copy link
Collaborator Author

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

Copy link
Collaborator Author

@rkooo567 rkooo567 left a 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).

  1. 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 !
  2. 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.

Copy link
Collaborator

@simon-mo simon-mo left a 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.

benchmarks/benchmark_latency.py Show resolved Hide resolved
tests/test_sequence.py Show resolved Hide resolved
tests/core/test_scheduler.py Outdated Show resolved Hide resolved
vllm/core/scheduler.py Show resolved Hide resolved
vllm/core/scheduler.py Show resolved Hide resolved
vllm/engine/arg_utils.py Outdated Show resolved Hide resolved
vllm/sequence.py Show resolved Hide resolved
vllm/sequence.py Outdated
Comment on lines 232 to 234
def on_recompute(self):
"""Reset the sequence states for recomputation."""
self.data.reset_num_computed_tokens()
Copy link
Collaborator

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

@rkooo567
Copy link
Collaborator Author

Thanks for reviewing the PR at late night @simon-mo ! Addressing comments rn...

@rkooo567
Copy link
Collaborator Author

comments are addressed

@simon-mo simon-mo merged commit b51c1cc into vllm-project:main Mar 28, 2024
33 checks passed
xjpang pushed a commit to xjpang/vllm that referenced this pull request Mar 31, 2024
@simon-mo simon-mo mentioned this pull request Apr 4, 2024
64 tasks
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.

None yet

4 participants