Skip to content

Commit

Permalink
fix: deque mutated during iteration in abort_seq_group (vllm-project#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxu2048 authored Jan 12, 2024
1 parent 9746058 commit 48cf1e4
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions vllm/core/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,24 @@ def abort_seq_group(self, request_id: Union[str, Iterable[str]]) -> None:
request_id = (request_id, )
request_ids = set(request_id)
for state_queue in [self.waiting, self.running, self.swapped]:
# We need to reverse the list as we are removing elements
# from it as we iterate over it. If we don't do it,
# indices will get messed up and we will skip over elements.
for seq_group in reversed(state_queue):
aborted_groups = []
for seq_group in state_queue:
if not request_ids:
# Using 'break' here may add two extra iterations,
# but is acceptable to reduce complexity .
break
if seq_group.request_id in request_ids:
# Remove the sequence group from the state queue.
state_queue.remove(seq_group)
for seq in seq_group.get_seqs():
if seq.is_finished():
continue
seq.status = SequenceStatus.FINISHED_ABORTED
self.free_seq(seq)
# Appending aborted group into pending list.
aborted_groups.append(seq_group)
request_ids.remove(seq_group.request_id)
if not request_ids:
return
for aborted_group in aborted_groups:
# Remove the sequence group from the state queue.
state_queue.remove(aborted_group)
for seq in seq_group.get_seqs():
if seq.is_finished():
continue
seq.status = SequenceStatus.FINISHED_ABORTED
self.free_seq(seq)

def has_unfinished_seqs(self) -> bool:
return self.waiting or self.running or self.swapped
Expand Down

0 comments on commit 48cf1e4

Please sign in to comment.