-
-
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
[Bugfix] Multi-sequence broken #11898
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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 |
---|---|---|
|
@@ -815,7 +815,9 @@ def set_finished_time(self, time: Optional[float]) -> None: | |
def get_max_num_running_seqs(self) -> int: | ||
"""The maximum number of sequences running in parallel in the remaining | ||
lifetime of the request.""" | ||
return 0 if self.first_seq.is_finished() else 1 | ||
if self.is_single_seq: | ||
return 0 if self.first_seq.is_finished() else 1 | ||
return self.num_seqs() - self.num_finished_seqs() | ||
|
||
def get_seqs( | ||
self, | ||
|
@@ -824,7 +826,10 @@ def get_seqs( | |
if status is None: | ||
return self.seqs | ||
|
||
return self.seqs if self.first_seq.status == status else [] | ||
if self.is_single_seq: | ||
return self.seqs if self.first_seq.status == status else [] | ||
|
||
return [seq for seq in self.seqs if seq.status == status] | ||
|
||
def is_encoder_decoder(self) -> bool: | ||
return self.encoder_seq is not None | ||
|
@@ -833,19 +838,22 @@ def get_encoder_seq(self) -> Optional[Sequence]: | |
return self.encoder_seq | ||
|
||
def get_finished_seqs(self) -> List[Sequence]: | ||
return self.seqs if self.first_seq.is_finished() else [] | ||
if self.is_single_seq: | ||
return self.seqs if self.first_seq.is_finished() else [] | ||
|
||
return [seq for seq in self.seqs if seq.is_finished()] | ||
|
||
def update_num_computed_tokens(self, num_new_computed_tokens: int): | ||
"""Update number of tokens computed so far.""" | ||
seq = self.first_seq | ||
if not seq.is_finished(): | ||
seq.data.update_num_computed_tokens(num_new_computed_tokens) | ||
for seq in self.seqs: | ||
if not seq.is_finished(): | ||
seq.data.update_num_computed_tokens(num_new_computed_tokens) | ||
|
||
def get_num_uncomputed_tokens(self) -> int: | ||
num_uncomputed_tokens = 0 | ||
seq = self.first_seq | ||
if not seq.is_finished(): | ||
num_uncomputed_tokens += seq.data.get_num_uncomputed_tokens() | ||
for seq in self.seqs: | ||
if not seq.is_finished(): | ||
num_uncomputed_tokens += seq.data.get_num_uncomputed_tokens() | ||
return num_uncomputed_tokens | ||
|
||
def num_seqs(self, status: Optional[SequenceStatus] = None) -> int: | ||
|
@@ -860,10 +868,14 @@ def num_seqs(self, status: Optional[SequenceStatus] = None) -> int: | |
return len(self.get_seqs(status)) | ||
|
||
def num_finished_seqs(self) -> int: | ||
return 1 if self.first_seq.is_finished() else 0 | ||
if self.is_single_seq: | ||
return 1 if self.seqs[0].is_finished() else 0 | ||
return len(self.get_finished_seqs()) | ||
|
||
def is_finished(self) -> bool: | ||
return self.first_seq.is_finished() | ||
if self.is_single_seq: | ||
return self.first_seq.is_finished() | ||
return all(seq.is_finished() for seq in self.seqs) | ||
|
||
def is_prefill(self) -> bool: | ||
return self.first_seq.is_prefill() | ||
|
@@ -1391,13 +1403,15 @@ class ParallelSampleSequenceGroup(SequenceGroupBase): | |
@staticmethod | ||
def add_request(request_id: str, engine, params, **kwargs): | ||
original_params = params | ||
params = original_params.clone() | ||
params.n = 1 | ||
group = ParallelSampleSequenceGroup(request_id) | ||
seqs = [] | ||
for i in range(original_params.n): | ||
request_id_i = f"{request_id}_parallel_sample_{i}" | ||
group.seq_id_to_index[request_id_i] = i | ||
params = copy.deepcopy(original_params) | ||
params.n = 1 | ||
if params.seed is not None: | ||
params.seed += i | ||
Comment on lines
+1411
to
+1414
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 part makes sense to me. |
||
seq_group = engine._add_processed_request( | ||
request_id_i, | ||
params=params, | ||
|
@@ -1432,33 +1446,34 @@ def maybe_assemble_group( | |
self, seq_group: SequenceGroup) -> Optional[SequenceGroup]: | ||
|
||
# in the streaming mode, we will return the assembled sequence | ||
# for the first sequence, and then return None for the rest of | ||
# sequences | ||
# for the first remaining sequence, and then return None for the | ||
# rest of sequences | ||
if self.streaming: | ||
if self.seq_id_to_index[seq_group.request_id] == 0: | ||
first_remaining_id = next(iter(self.to_be_finished)) | ||
if seq_group.request_id == first_remaining_id: | ||
return self.assembled_seq_group | ||
return None | ||
|
||
# in the non-streaming mode, we will return the assembled sequence | ||
# once after all sequences finish, and then return None for the | ||
# when the last sequences finishes, and then return None for the | ||
# rest of the time | ||
|
||
if len(self.to_be_finished) > 0: | ||
return None | ||
|
||
assert self.assembled_seq_group is not None | ||
params = self.assembled_seq_group.sampling_params | ||
assert isinstance(params, SamplingParams) | ||
if not self.output_produced: | ||
self.output_produced = True | ||
if params._real_n is not None: | ||
# Get the top-n sequences. | ||
n = params._real_n or params.n | ||
seqs = self.assembled_seq_group.seqs | ||
sorting_key = lambda seq: seq.get_cumulative_logprob() | ||
sorted_seqs = sorted(seqs, key=sorting_key, reverse=True) | ||
top_n_seqs = sorted_seqs[:n] | ||
self.assembled_seq_group.seqs = top_n_seqs | ||
return self.assembled_seq_group | ||
if self.output_produced: | ||
return None | ||
if (len(self.to_be_finished) == 1 | ||
and seq_group.request_id in self.to_be_finished | ||
and seq_group.is_finished()): | ||
assert self.assembled_seq_group is not None | ||
params = self.assembled_seq_group.sampling_params | ||
assert isinstance(params, SamplingParams) | ||
if not self.output_produced: | ||
self.output_produced = True | ||
if params._real_n is not None: | ||
# Get the top-n sequences. | ||
n = params._real_n or params.n | ||
seqs = self.assembled_seq_group.seqs | ||
sorting_key = lambda seq: seq.get_cumulative_logprob() | ||
sorted_seqs = sorted(seqs, key=sorting_key, reverse=True) | ||
top_n_seqs = sorted_seqs[:n] | ||
self.assembled_seq_group.seqs = top_n_seqs | ||
return self.assembled_seq_group | ||
if self.output_produced: | ||
return None | ||
return None |
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.
would this test be flaky? e.g. when we generate with
n=10
, if two sequences happen to generate the same answer ...