__init__.py 2.43 KB
Newer Older
1
2
# SPDX-License-Identifier: Apache-2.0

3
4
import enum
from dataclasses import dataclass
5
from typing import TYPE_CHECKING, List, Optional, Union
6
7
8

import msgspec

9
10
from vllm.v1.metrics.stats import SchedulerStats

11
12
13
14
15
if TYPE_CHECKING:
    from vllm.lora.request import LoRARequest
    from vllm.multimodal import MultiModalKwargs
    from vllm.multimodal.inputs import PlaceholderRange
    from vllm.sampling_params import SamplingParams
16
17


18
19
@dataclass
class EngineCoreRequest:
20
21
22
23
24
25

    # NOTE: prompt and prompt_token_ids should be DecoderOnlyInput,
    # but this object is currently not playing well with msgspec
    # due to circular imports and typing we have in data.py

    request_id: str
26
27
    # NOTE(ywang96): original text prompt is needed when a request is added to
    # Detokenizer, but set to None when it is added to EngineCoreClient.
28
29
    prompt: Optional[str]
    prompt_token_ids: List[int]
30
    mm_inputs: Optional[List[Optional["MultiModalKwargs"]]]
31
    mm_hashes: Optional[List[str]]
32
33
    mm_placeholders: Optional[List["PlaceholderRange"]]
    sampling_params: "SamplingParams"
34
35
    eos_token_id: Optional[int]
    arrival_time: float
36
    lora_request: Optional["LoRARequest"]
37
38


39
40
41
42
43
class EngineCoreOutput(
        msgspec.Struct,
        array_like=True,  # type: ignore[call-arg]
        omit_defaults=True,  # type: ignore[call-arg]
        gc=False):  # type: ignore[call-arg]
44
45
46
47
48
49
50
51

    request_id: str
    new_token_ids: List[int]
    finished: bool
    finish_reason: Optional[str] = None
    stop_reason: Union[int, str, None] = None


52
53
54
55
56
class EngineCoreOutputs(
        msgspec.Struct,
        array_like=True,  # type: ignore[call-arg]
        omit_defaults=True,  # type: ignore[call-arg]
        gc=False):  # type: ignore[call-arg]
57
58
59
60
61
62

    #NOTE(Nick): We could consider ways to make this more compact,
    # e.g. columnwise layout and using an int enum for finish/stop reason

    # [num_reqs]
    outputs: List[EngineCoreOutput]
63
    scheduler_stats: SchedulerStats
64
65


66
67
68
69
70
@dataclass
class EngineCoreProfile:
    is_start: bool


71
72
73
74
75
@dataclass
class EngineCoreResetPrefixCache:
    pass


76
77
78
79
80
81
82
class EngineCoreRequestType(enum.Enum):
    """
    Request types defined as hex byte strings, so it can be sent over sockets
    without separate encoding step.
    """
    ADD = b'\x00'
    ABORT = b'\x01'
83
    PROFILE = b'\x02'
84
    RESET_PREFIX_CACHE = b'\x03'
85
86


87
88
EngineCoreRequestUnion = Union[EngineCoreRequest, EngineCoreProfile,
                               EngineCoreResetPrefixCache, List[str]]