protocol.py 2.9 KB
Newer Older
1
from typing import (AsyncGenerator, List, Mapping, Optional, Protocol,
2
3
4
5
                    runtime_checkable)

from vllm.config import DecodingConfig, ModelConfig
from vllm.core.scheduler import SchedulerOutputs
6
from vllm.inputs.data import PromptType
7
from vllm.lora.request import LoRARequest
8
from vllm.model_executor.layers.sampler import SamplerOutput
9
10
11
12
from vllm.outputs import EmbeddingRequestOutput, RequestOutput
from vllm.pooling_params import PoolingParams
from vllm.prompt_adapter.request import PromptAdapterRequest
from vllm.sampling_params import SamplingParams
13
from vllm.transformers_utils.tokenizer import AnyTokenizer
14
15
16


@runtime_checkable
17
18
class EngineClient(Protocol):
    """Protocol class for Clients to Engine"""
19
20
21
22
23
24
25
26
27
28
29
30
31

    @property
    def is_running(self) -> bool:
        ...

    @property
    def is_stopped(self) -> bool:
        ...

    @property
    def errored(self) -> bool:
        ...

32
    @property
33
34
    def dead_error(self) -> BaseException:
        ...
35

36
    def generate(
37
        self,
38
        prompt: PromptType,
39
40
41
42
        sampling_params: SamplingParams,
        request_id: str,
        lora_request: Optional[LoRARequest] = None,
        trace_headers: Optional[Mapping[str, str]] = None,
43
44
        prompt_adapter_request: Optional[PromptAdapterRequest] = None,
        priority: int = 0,
45
    ) -> AsyncGenerator[RequestOutput, None]:
46
        """Generate outputs for a request."""
47
        ...
48

49
    def encode(
50
        self,
51
        prompt: PromptType,
52
53
54
55
        pooling_params: PoolingParams,
        request_id: str,
        lora_request: Optional[LoRARequest] = None,
        trace_headers: Optional[Mapping[str, str]] = None,
56
        priority: int = 0,
57
    ) -> AsyncGenerator[EmbeddingRequestOutput, None]:
58
        """Generate outputs for a request from an embedding model."""
59
        ...
60
61
62
63
64
65
66
67
68
69

    async def abort(self, request_id: str) -> None:
        """Abort a request.

        Args:
            request_id: The unique id of the request.
        """

    async def get_model_config(self) -> ModelConfig:
        """Get the model configuration of the vLLM engine."""
70
        ...
71
72

    async def get_decoding_config(self) -> DecodingConfig:
73
        ...
74
75
76
77
78
        """Get the decoding configuration of the vLLM engine."""

    async def get_tokenizer(
        self,
        lora_request: Optional[LoRARequest] = None,
79
80
81
    ) -> AnyTokenizer:
        """Get the appropriate tokenizer for the request"""
        ...
82
83

    async def is_tracing_enabled(self) -> bool:
84
        ...
85
86
87
88
89
90

    async def do_log_stats(
        self,
        scheduler_outputs: Optional[SchedulerOutputs] = None,
        model_output: Optional[List[SamplerOutput]] = None,
    ) -> None:
91
        ...
92
93
94

    async def check_health(self) -> None:
        """Raise if unhealthy"""
95
        ...
96
97
98
99
100
101
102
103

    async def start_profile(self) -> None:
        """Start profiling the engine"""
        ...

    async def stop_profile(self) -> None:
        """Start profiling the engine"""
        ...