abstract.py 1.92 KB
Newer Older
1
from abc import ABC, abstractmethod
2
from typing import Type
3
4

from vllm.config import VllmConfig
5
from vllm.v1.kv_cache_interface import KVCacheConfig, KVCacheSpec
6
7
8
9
10
11
from vllm.v1.outputs import ModelRunnerOutput


class Executor(ABC):
    """Abstract class for executors."""

12
13
14
15
16
17
    @staticmethod
    def get_class(vllm_config: VllmConfig) -> Type["Executor"]:
        executor_class: Type[Executor]
        distributed_executor_backend = (
            vllm_config.parallel_config.distributed_executor_backend)
        if distributed_executor_backend == "ray":
18
19
20
            from vllm.executor.ray_distributed_executor import (  # noqa
                RayDistributedExecutor)
            executor_class = RayDistributedExecutor
21
22
23
24
25
26
27
28
29
        elif distributed_executor_backend == "mp":
            from vllm.v1.executor.multiproc_executor import MultiprocExecutor
            executor_class = MultiprocExecutor
        else:
            assert (distributed_executor_backend is None)
            from vllm.v1.executor.uniproc_executor import UniprocExecutor
            executor_class = UniprocExecutor
        return executor_class

30
31
32
33
34
    @abstractmethod
    def __init__(self, vllm_config: VllmConfig) -> None:
        raise NotImplementedError

    @abstractmethod
35
    def initialize(self, kv_cache_config: KVCacheConfig) -> None:
36
37
38
        raise NotImplementedError

    @abstractmethod
39
40
41
42
43
    def determine_available_memory(self) -> int:  # in bytes
        raise NotImplementedError

    @abstractmethod
    def get_kv_cache_spec(self) -> KVCacheSpec:
44
45
46
47
48
49
50
51
52
53
        raise NotImplementedError

    @abstractmethod
    def execute_model(
        self,
        scheduler_output,
    ) -> ModelRunnerOutput:
        raise NotImplementedError

    @abstractmethod
54
    def profile(self, is_start: bool = True):
55
56
57
58
59
60
61
62
63
        raise NotImplementedError

    @abstractmethod
    def shutdown(self):
        pass

    @abstractmethod
    def check_health(self) -> None:
        raise NotImplementedError