[Model][Misc] Add e5-mistral-7b-instruct and Embedding API (#3734)
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
from typing import List, Tuple
|
||||
|
||||
from vllm.core.interfaces import AllocStatus, BlockSpaceManager
|
||||
from vllm.sequence import Sequence, SequenceGroup
|
||||
|
||||
|
||||
class EmbeddingModelBlockSpaceManager(BlockSpaceManager):
|
||||
"""An embedding version of BlockSpaceManager for use in environments
|
||||
with embedding models where block management is not required.
|
||||
|
||||
This class provides the same interface as BlockSpaceManager, but its
|
||||
methods perform no actions or return simple values like True in specific
|
||||
actions. It's designed to be used in scenarios where the overhead of
|
||||
block management is unnecessary, such as in an embedding environment.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
pass
|
||||
|
||||
def can_allocate(self, seq_group: SequenceGroup) -> AllocStatus:
|
||||
# Always return OK for dummy purposes
|
||||
return AllocStatus.OK
|
||||
|
||||
def allocate(self, seq_group: SequenceGroup) -> None:
|
||||
# No actual allocation logic needed
|
||||
pass
|
||||
|
||||
def can_append_slots(self, seq_group: SequenceGroup,
|
||||
num_lookahead_slots: int) -> bool:
|
||||
return True
|
||||
|
||||
def append_slots(
|
||||
self,
|
||||
seq: Sequence,
|
||||
num_lookahead_slots: int,
|
||||
) -> List[Tuple[int, int]]:
|
||||
return None # type: ignore
|
||||
|
||||
def fork(self, parent_seq: Sequence, child_seq: Sequence) -> None:
|
||||
pass
|
||||
|
||||
def can_swap_in(self, seq_group: SequenceGroup,
|
||||
num_lookahead_slots: int) -> AllocStatus:
|
||||
return AllocStatus.OK
|
||||
|
||||
def swap_in(self, seq_group: SequenceGroup,
|
||||
num_lookahead_slots: int) -> List[Tuple[int, int]]:
|
||||
return None # type: ignore
|
||||
|
||||
def can_swap_out(self, seq_group: SequenceGroup) -> bool:
|
||||
return True
|
||||
|
||||
def swap_out(self, seq_group: SequenceGroup) -> List[Tuple[int, int]]:
|
||||
return None # type: ignore
|
||||
|
||||
def free(self, seq: Sequence) -> None:
|
||||
# No operation on free
|
||||
return
|
||||
|
||||
def get_block_table(self, seq: Sequence) -> List[int]:
|
||||
return None # type: ignore
|
||||
|
||||
def get_num_free_gpu_blocks(self) -> int:
|
||||
return 1
|
||||
|
||||
def get_num_free_cpu_blocks(self) -> int:
|
||||
return 1
|
||||
|
||||
def access_all_blocks_in_seq(
|
||||
self,
|
||||
seq: Sequence,
|
||||
access_time: float,
|
||||
) -> None:
|
||||
pass
|
||||
|
||||
def get_common_computed_block_ids(self,
|
||||
seq_group: SequenceGroup) -> List[int]:
|
||||
return None # type: ignore
|
||||
|
||||
def mark_blocks_as_computed(self, seq_group: SequenceGroup):
|
||||
pass
|
||||
@@ -35,6 +35,11 @@ class BlockSpaceManager(ABC):
|
||||
from vllm.core.block_manager_v2 import BlockSpaceManagerV2
|
||||
return BlockSpaceManagerV2
|
||||
|
||||
if version == "embedding":
|
||||
from vllm.core.embedding_model_block_manager import (
|
||||
EmbeddingModelBlockSpaceManager)
|
||||
return EmbeddingModelBlockSpaceManager
|
||||
|
||||
raise ValueError(f"Unknown version {version=}")
|
||||
|
||||
@abstractmethod
|
||||
|
||||
@@ -270,9 +270,14 @@ class Scheduler:
|
||||
self.scheduler_config.max_model_len,
|
||||
self.scheduler_config.max_num_batched_tokens)
|
||||
|
||||
version = "v1"
|
||||
if self.scheduler_config.use_v2_block_manager:
|
||||
version = "v2"
|
||||
if self.scheduler_config.embedding_mode:
|
||||
version = "embedding"
|
||||
|
||||
BlockSpaceManagerImpl = BlockSpaceManager.get_block_space_manager_class(
|
||||
version="v2" if self.scheduler_config.
|
||||
use_v2_block_manager else "v1")
|
||||
version)
|
||||
|
||||
# Create the block space manager.
|
||||
self.block_manager = BlockSpaceManagerImpl(
|
||||
@@ -968,6 +973,7 @@ class Scheduler:
|
||||
sampling_params=seq_group.sampling_params,
|
||||
block_tables=block_tables,
|
||||
do_sample=do_sample,
|
||||
pooling_params=seq_group.pooling_params,
|
||||
token_chunk_size=token_chunk_size,
|
||||
lora_request=seq_group.lora_request,
|
||||
computed_block_nums=common_computed_block_nums,
|
||||
|
||||
Reference in New Issue
Block a user