mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2026-03-23 22:43:41 +08:00
- **Add SPDX license headers to python source files**
- **Check for SPDX headers using pre-commit**
commit 9d7ef44c3cfb72ca4c32e1c677d99259d10d4745
Author: Russell Bryant <rbryant@redhat.com>
Date: Fri Jan 31 14:18:24 2025 -0500
Add SPDX license headers to python source files
This commit adds SPDX license headers to python source files as
recommended to
the project by the Linux Foundation. These headers provide a concise way
that is
both human and machine readable for communicating license information
for each
source file. It helps avoid any ambiguity about the license of the code
and can
also be easily used by tools to help manage license compliance.
The Linux Foundation runs license scans against the codebase to help
ensure
we are in compliance with the licenses of the code we use, including
dependencies. Having these headers in place helps that tool do its job.
More information can be found on the SPDX site:
- https://spdx.dev/learn/handling-license-info/
Signed-off-by: Russell Bryant <rbryant@redhat.com>
commit 5a1cf1cb3b80759131c73f6a9dddebccac039dea
Author: Russell Bryant <rbryant@redhat.com>
Date: Fri Jan 31 14:36:32 2025 -0500
Check for SPDX headers using pre-commit
Signed-off-by: Russell Bryant <rbryant@redhat.com>
---------
Signed-off-by: Russell Bryant <rbryant@redhat.com>
135 lines
3.5 KiB
Python
135 lines
3.5 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
import enum
|
|
from abc import ABC, abstractmethod
|
|
from typing import List
|
|
from typing import Sequence as GenericSequence
|
|
from typing import Tuple
|
|
|
|
from vllm.sequence import Sequence, SequenceGroup
|
|
from vllm.utils import Device
|
|
|
|
|
|
class AllocStatus(enum.Enum):
|
|
"""Result for BlockSpaceManager.can_allocate
|
|
|
|
1. Ok: seq_group can be allocated now.
|
|
2. Later: seq_group cannot be allocated.
|
|
The capacity of allocator is larger than seq_group required.
|
|
3. Never: seq_group can never be allocated.
|
|
The seq_group is too large to allocated in GPU.
|
|
"""
|
|
OK = enum.auto()
|
|
LATER = enum.auto()
|
|
NEVER = enum.auto()
|
|
|
|
|
|
class BlockSpaceManager(ABC):
|
|
|
|
@staticmethod
|
|
def get_block_space_manager_class(version: str):
|
|
version = version.lower()
|
|
|
|
if version == "selfattn":
|
|
from vllm.core.block_manager import SelfAttnBlockSpaceManager
|
|
return SelfAttnBlockSpaceManager
|
|
|
|
if version == "placeholder":
|
|
from vllm.core.placeholder_block_space_manager import (
|
|
PlaceholderBlockSpaceManager)
|
|
return PlaceholderBlockSpaceManager
|
|
|
|
raise ValueError(f"Unknown version {version=}")
|
|
|
|
@abstractmethod
|
|
def can_allocate(self,
|
|
seq_group: SequenceGroup,
|
|
num_lookahead_slots: int = 0) -> AllocStatus:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def allocate(self, seq_group: SequenceGroup) -> None:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def can_append_slots(self, seq_group: SequenceGroup,
|
|
num_lookahead_slots: int) -> bool:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def append_slots(
|
|
self,
|
|
seq: Sequence,
|
|
num_lookahead_slots: int,
|
|
) -> List[Tuple[int, int]]:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def fork(self, parent_seq: Sequence, child_seq: Sequence) -> None:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def can_swap_in(self, seq_group: SequenceGroup,
|
|
num_lookahead_slots: int) -> AllocStatus:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def swap_in(self, seq_group: SequenceGroup) -> List[Tuple[int, int]]:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def can_swap_out(self, seq_group: SequenceGroup) -> bool:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def swap_out(self, seq_group: SequenceGroup) -> List[Tuple[int, int]]:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def free(self, seq: Sequence) -> None:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_block_table(self, seq: Sequence) -> List[int]:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_num_free_gpu_blocks(self) -> int:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_num_free_cpu_blocks(self) -> int:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def access_all_blocks_in_seq(
|
|
self,
|
|
seq: Sequence,
|
|
access_time: float,
|
|
) -> None:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_common_computed_block_ids(
|
|
self, seqs: List[Sequence]) -> GenericSequence[int]:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def mark_blocks_as_computed(self, seq_group: SequenceGroup,
|
|
token_chunk_size: int):
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_prefix_cache_hit_rate(self, device: Device) -> float:
|
|
"""Prefix cache hit rate. -1 means not supported or disabled."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def reset_prefix_cache(self) -> bool:
|
|
"""Reset prefix cache for all devices."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_num_cached_tokens(self, seq: Sequence) -> int:
|
|
pass
|