-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[Chunked Prefill][4/n] Chunked prefill scheduler. #3853
Merged
simon-mo
merged 21 commits into
vllm-project:main
from
rkooo567:chunked-prefill-scheduler-done
Apr 5, 2024
+1,218
−183
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6b71130
code complete. wip test
rkooo567 6ab059c
ip
rkooo567 2ae3444
ip
rkooo567 07c35b9
Done
rkooo567 29b1a26
done
rkooo567 bcbad91
Merge branch 'main' into chunked-prefill-scheduler-done
rkooo567 81e8dc4
Fixed
rkooo567 7ee4655
addressed 2
rkooo567 afa0df2
removed assert
rkooo567 24fe6dc
Merge branch 'main' into chunked-prefill-scheduler-done
rkooo567 df86440
test fix
rkooo567 1941fec
revert basic corr test
rkooo567 4f64529
done
rkooo567 b570f96
Fixed an issue
rkooo567 f93e677
fixed a bug
rkooo567 150beab
done
rkooo567 020b31f
Merge branch 'main' into chunked-prefill-scheduler-done
rkooo567 e7c0d6c
fix
rkooo567 8ba003e
trial
rkooo567 26193dd
test add
rkooo567 705313e
fixed tests
rkooo567 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
addressed 2
- Loading branch information
commit 7ee465538e25d869d341d0d7aef7f5a4991cf365
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,32 +48,27 @@ def can_schedule(self, *, num_new_tokens: int, num_new_seqs: int): | |
def remaining_token_budget(self): | ||
return self.token_budget - self.num_batched_tokens | ||
|
||
def add_num_batched_tokens(self, seq_group: SequenceGroup, | ||
num_batched_tokens: int): | ||
req_id = seq_group.request_id | ||
def add_num_batched_tokens(self, req_id: str, num_batched_tokens: int): | ||
if req_id in self._requeset_ids_num_batched_tokens: | ||
return | ||
|
||
self._requeset_ids_num_batched_tokens.add(req_id) | ||
self._num_batched_tokens += num_batched_tokens | ||
|
||
def subtract_num_batched_tokens(self, seq_group: SequenceGroup, | ||
def subtract_num_batched_tokens(self, req_id: str, | ||
num_batched_tokens: int): | ||
req_id = seq_group.request_id | ||
if req_id in self._requeset_ids_num_batched_tokens: | ||
self._requeset_ids_num_batched_tokens.remove(req_id) | ||
self._num_batched_tokens -= num_batched_tokens | ||
|
||
def add_num_seqs(self, seq_group: SequenceGroup, num_curr_seqs: int): | ||
req_id = seq_group.request_id | ||
def add_num_seqs(self, req_id: str, num_curr_seqs: int): | ||
if req_id in self._requeset_ids_num_curr_seqs: | ||
return | ||
|
||
self._requeset_ids_num_curr_seqs.add(req_id) | ||
self._num_curr_seqs += num_curr_seqs | ||
|
||
def subtract_num_seqs(self, seq_group: SequenceGroup, num_curr_seqs: int): | ||
req_id = seq_group.request_id | ||
def subtract_num_seqs(self, req_id: str, num_curr_seqs: int): | ||
if req_id in self._requeset_ids_num_curr_seqs: | ||
self._requeset_ids_num_curr_seqs.remove(req_id) | ||
self._num_curr_seqs -= num_curr_seqs | ||
|
@@ -376,9 +371,10 @@ def _schedule_running( | |
|
||
running_queue.popleft() | ||
while not self._can_append_slots(seq_group): | ||
budget.subtract_num_batched_tokens(seq_group, | ||
budget.subtract_num_batched_tokens(seq_group.request_id, | ||
num_running_tokens) | ||
budget.subtract_num_seqs(seq_group, num_running_seqs) | ||
budget.subtract_num_seqs(seq_group.request_id, | ||
num_running_seqs) | ||
if curr_loras is not None and seq_group.lora_int_id > 0: | ||
curr_loras.pop(seq_group.lora_int_id) | ||
|
||
|
@@ -419,8 +415,9 @@ def _schedule_running( | |
ScheduledSequenceGroup( | ||
seq_group=seq_group, | ||
token_chunk_size=num_running_tokens)) | ||
budget.add_num_batched_tokens(seq_group, num_running_tokens) | ||
budget.add_num_seqs(seq_group, num_running_seqs) | ||
budget.add_num_batched_tokens(seq_group.request_id, | ||
num_running_tokens) | ||
budget.add_num_seqs(seq_group.request_id, num_running_seqs) | ||
if curr_loras is not None and seq_group.lora_int_id > 0: | ||
curr_loras.add(seq_group.lora_int_id) | ||
|
||
|
@@ -525,8 +522,8 @@ def _schedule_swapped( | |
decode_seq_groups.append( | ||
ScheduledSequenceGroup(seq_group, | ||
token_chunk_size=num_new_tokens)) | ||
budget.add_num_batched_tokens(seq_group, num_new_tokens) | ||
budget.add_num_seqs(seq_group, num_new_seqs) | ||
budget.add_num_batched_tokens(seq_group.request_id, num_new_tokens) | ||
budget.add_num_seqs(seq_group.request_id, num_new_seqs) | ||
|
||
swapped_queue.extendleft(leftover_swapped) | ||
|
||
|
@@ -639,8 +636,8 @@ def _schedule_prefills( | |
seq_groups.append( | ||
ScheduledSequenceGroup(seq_group=seq_group, | ||
token_chunk_size=num_new_tokens)) | ||
budget.add_num_batched_tokens(seq_group, num_new_tokens) | ||
budget.add_num_seqs(seq_group, num_new_seqs) | ||
budget.add_num_batched_tokens(seq_group.request_id, num_new_tokens) | ||
budget.add_num_seqs(seq_group.request_id, num_new_seqs) | ||
|
||
# Queue requests that couldn't be scheduled. | ||
waiting_queue.extendleft(leftover_waiting_sequences) | ||
|
@@ -668,7 +665,7 @@ def _schedule_default(self) -> SchedulerOutputs: | |
# Make sure we include num running seqs before scheduling prefill, | ||
# so that we don't schedule beyond max_num_seqs for prefill. | ||
for seq_group in self.running: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was a bug (we should not include num_batched tokens in the beginning). it is fixed & regression tests are added. |
||
budget.add_num_seqs(seq_group, | ||
budget.add_num_seqs(seq_group.request_id, | ||
seq_group.get_max_num_running_seqs()) | ||
curr_loras = set( | ||
seq_group.lora_int_id | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
when would this happen? I think this should raise an exception
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.
same case as #3853 (comment)