[Core][Optimization] change python dict to pytorch tensor (#4607)
This commit is contained in:
+20
-21
@@ -13,7 +13,6 @@ from vllm.logger import init_logger
|
||||
from vllm.lora.request import LoRARequest
|
||||
from vllm.sequence import (Sequence, SequenceData, SequenceGroup,
|
||||
SequenceGroupMetadata, SequenceStatus)
|
||||
from vllm.utils import merge_dicts
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
@@ -122,8 +121,8 @@ class SchedulerOutputs:
|
||||
blocks_to_swap_in: Dict[int, int]
|
||||
# Blocks to swap out. Dict of GPU -> CPU block number.
|
||||
blocks_to_swap_out: Dict[int, int]
|
||||
# Blocks to copy. Source to a list of dest blocks.
|
||||
blocks_to_copy: Dict[int, List[int]]
|
||||
# Blocks to copy. Source to dest block.
|
||||
blocks_to_copy: List[Tuple[int, int]]
|
||||
# Sequence groups that are going to be ignored.
|
||||
ignored_seq_groups: List[SequenceGroup]
|
||||
# The number of slots for lookahead decoding.
|
||||
@@ -177,7 +176,7 @@ class SchedulerRunningOutputs:
|
||||
# The blocks to swap out.
|
||||
blocks_to_swap_out: Dict[int, int]
|
||||
# The blocks to copy.
|
||||
blocks_to_copy: Dict[int, List[int]]
|
||||
blocks_to_copy: List[Tuple[int, int]]
|
||||
# The number of slots for lookahead decoding.
|
||||
num_lookahead_slots: int
|
||||
|
||||
@@ -189,7 +188,7 @@ class SchedulerRunningOutputs:
|
||||
preempted=[],
|
||||
swapped_out=[],
|
||||
blocks_to_swap_out={},
|
||||
blocks_to_copy={},
|
||||
blocks_to_copy=[],
|
||||
num_lookahead_slots=0,
|
||||
)
|
||||
|
||||
@@ -209,7 +208,7 @@ class SchedulerSwappedInOutputs:
|
||||
# The blocks to swap in.
|
||||
blocks_to_swap_in: Dict[int, int]
|
||||
# The blocks to copy.
|
||||
blocks_to_copy: Dict[int, List[int]]
|
||||
blocks_to_copy: List[Tuple[int, int]]
|
||||
# The number of slots for lookahead decoding.
|
||||
num_lookahead_slots: int
|
||||
# Infeasible sequence groups.
|
||||
@@ -221,7 +220,7 @@ class SchedulerSwappedInOutputs:
|
||||
decode_seq_groups=[],
|
||||
prefill_seq_groups=[],
|
||||
blocks_to_swap_in={},
|
||||
blocks_to_copy={},
|
||||
blocks_to_copy=[],
|
||||
num_lookahead_slots=0,
|
||||
infeasible_seq_groups=[],
|
||||
)
|
||||
@@ -394,7 +393,7 @@ class Scheduler:
|
||||
"""
|
||||
# Blocks that need to be swapped or copied before model execution.
|
||||
blocks_to_swap_out: Dict[int, int] = {}
|
||||
blocks_to_copy: Dict[int, List[int]] = {}
|
||||
blocks_to_copy: List[Tuple[int, int]] = []
|
||||
|
||||
decode_seq_groups: List[ScheduledSequenceGroup] = []
|
||||
prefill_seq_groups: List[ScheduledSequenceGroup] = []
|
||||
@@ -511,7 +510,7 @@ class Scheduler:
|
||||
"""
|
||||
# Blocks that need to be swapped or copied before model execution.
|
||||
blocks_to_swap_in: Dict[int, int] = {}
|
||||
blocks_to_copy: Dict[int, List[int]] = {}
|
||||
blocks_to_copy: List[Tuple[int, int]] = []
|
||||
decode_seq_groups: List[ScheduledSequenceGroup] = []
|
||||
prefill_seq_groups: List[ScheduledSequenceGroup] = []
|
||||
now = time.time()
|
||||
@@ -794,8 +793,8 @@ class Scheduler:
|
||||
num_batched_tokens=budget.num_batched_tokens,
|
||||
blocks_to_swap_in=swapped_in.blocks_to_swap_in,
|
||||
blocks_to_swap_out=running_scheduled.blocks_to_swap_out,
|
||||
blocks_to_copy=merge_dicts(running_scheduled.blocks_to_copy,
|
||||
swapped_in.blocks_to_copy),
|
||||
blocks_to_copy=running_scheduled.blocks_to_copy +
|
||||
swapped_in.blocks_to_copy,
|
||||
ignored_seq_groups=prefills.ignored_seq_groups +
|
||||
swapped_in.infeasible_seq_groups,
|
||||
num_lookahead_slots=running_scheduled.num_lookahead_slots,
|
||||
@@ -882,8 +881,8 @@ class Scheduler:
|
||||
num_batched_tokens=budget.num_batched_tokens,
|
||||
blocks_to_swap_in=swapped_in.blocks_to_swap_in,
|
||||
blocks_to_swap_out=running_scheduled.blocks_to_swap_out,
|
||||
blocks_to_copy=merge_dicts(running_scheduled.blocks_to_copy,
|
||||
swapped_in.blocks_to_copy),
|
||||
blocks_to_copy=running_scheduled.blocks_to_copy +
|
||||
swapped_in.blocks_to_copy,
|
||||
ignored_seq_groups=prefills.ignored_seq_groups,
|
||||
num_lookahead_slots=running_scheduled.num_lookahead_slots,
|
||||
running_queue_size=len(self.running),
|
||||
@@ -1011,17 +1010,18 @@ class Scheduler:
|
||||
def _append_slots(
|
||||
self,
|
||||
seq_group: SequenceGroup,
|
||||
blocks_to_copy: Dict[int, List[int]],
|
||||
blocks_to_copy: List[Tuple[int, int]],
|
||||
) -> None:
|
||||
"""Appends new slots to the sequences in the given sequence group.
|
||||
|
||||
Args:
|
||||
seq_group (SequenceGroup): The sequence group containing the
|
||||
sequences to append slots to.
|
||||
blocks_to_copy (Dict[int, List[int]]): A dictionary mapping source
|
||||
block indices to lists of destination block indices. This
|
||||
dictionary is updated with the new source and destination block
|
||||
indices for the appended slots.
|
||||
blocks_to_copy (List[Tuple[int, int]]): A list of tuple of two
|
||||
ints, the first int is the source block index, and the second
|
||||
int is the destination block index. This list is updated with
|
||||
the new source and destination block indices for the appended
|
||||
slots.
|
||||
"""
|
||||
num_lookahead_slots = self._get_num_lookahead_slots(is_prefill=False)
|
||||
|
||||
@@ -1029,9 +1029,8 @@ class Scheduler:
|
||||
cows = self.block_manager.append_slots(seq, num_lookahead_slots)
|
||||
|
||||
for src, dests in cows.items():
|
||||
if src not in blocks_to_copy:
|
||||
blocks_to_copy[src] = []
|
||||
blocks_to_copy[src].extend(dests)
|
||||
for dest in dests:
|
||||
blocks_to_copy.append((src, dest))
|
||||
|
||||
def _preempt(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user