[Core][Bugfix]Refactor block manager for better testability (#3492)
This commit is contained in:
+20
-7
@@ -4,7 +4,7 @@ from collections import deque
|
||||
from typing import Deque, Dict, Iterable, List, Optional, Set, Tuple, Union
|
||||
|
||||
from vllm.config import CacheConfig, LoRAConfig, SchedulerConfig
|
||||
from vllm.core.block_manager import AllocStatus, BlockSpaceManager
|
||||
from vllm.core.interfaces import AllocStatus, BlockSpaceManager
|
||||
from vllm.core.policy import PolicyFactory
|
||||
from vllm.logger import init_logger
|
||||
from vllm.lora.request import LoRARequest
|
||||
@@ -88,8 +88,13 @@ class Scheduler:
|
||||
|
||||
# Instantiate the scheduling policy.
|
||||
self.policy = PolicyFactory.get_policy(policy_name="fcfs")
|
||||
|
||||
BlockSpaceManagerImpl = BlockSpaceManager.get_block_space_manager_class(
|
||||
version="v2" if self.scheduler_config.
|
||||
use_v2_block_manager else "v1")
|
||||
|
||||
# Create the block space manager.
|
||||
self.block_manager = BlockSpaceManager(
|
||||
self.block_manager = BlockSpaceManagerImpl(
|
||||
block_size=self.cache_config.block_size,
|
||||
num_gpu_blocks=self.cache_config.num_gpu_blocks,
|
||||
num_cpu_blocks=self.cache_config.num_cpu_blocks,
|
||||
@@ -378,6 +383,10 @@ class Scheduler:
|
||||
block_tables[seq_id] = self.block_manager.get_block_table(seq)
|
||||
self.block_manager.access_all_blocks_in_seq(seq, now)
|
||||
|
||||
common_computed_block_nums = (
|
||||
self.block_manager.get_common_computed_block_ids(
|
||||
seq_group.get_seqs(status=SequenceStatus.RUNNING)))
|
||||
|
||||
seq_group_metadata = SequenceGroupMetadata(
|
||||
request_id=seq_group.request_id,
|
||||
is_prompt=scheduler_outputs.prompt_run,
|
||||
@@ -385,8 +394,7 @@ class Scheduler:
|
||||
sampling_params=seq_group.sampling_params,
|
||||
block_tables=block_tables,
|
||||
lora_request=seq_group.lora_request,
|
||||
computed_block_nums=self.block_manager.
|
||||
get_common_computed_block_ids(seq_group),
|
||||
computed_block_nums=common_computed_block_nums,
|
||||
state=seq_group.state,
|
||||
# `multi_modal_data` will only be present for the 1st comm
|
||||
# between engine and worker.
|
||||
@@ -396,6 +404,14 @@ class Scheduler:
|
||||
if scheduler_outputs.prompt_run else None,
|
||||
)
|
||||
seq_group_metadata_list.append(seq_group_metadata)
|
||||
|
||||
# Now that the batch has been created, we can assume all blocks in the
|
||||
# batch will have been computed before the next scheduling invocation.
|
||||
# This is because the engine assumes that a failure in model execution
|
||||
# will crash the vLLM instance / will not retry.
|
||||
for seq_group in scheduler_outputs.scheduled_seq_groups:
|
||||
self.block_manager.mark_blocks_as_computed(seq_group)
|
||||
|
||||
return seq_group_metadata_list, scheduler_outputs
|
||||
|
||||
def fork_seq(self, parent_seq: Sequence, child_seq: Sequence) -> None:
|
||||
@@ -503,9 +519,6 @@ class Scheduler:
|
||||
for seq in seq_group.get_seqs(status=SequenceStatus.RUNNING):
|
||||
seq.status = SequenceStatus.SWAPPED
|
||||
|
||||
def mark_blocks_as_computed(self, seq_group: SequenceGroup):
|
||||
self.block_manager.mark_blocks_as_computed(seq_group)
|
||||
|
||||
def _passed_delay(self, now: float) -> bool:
|
||||
if self.prev_prompt:
|
||||
self.last_prompt_latency = now - self.prev_time
|
||||
|
||||
Reference in New Issue
Block a user