__init__.py 2.13 KB
Newer Older
1
2
import enum
from dataclasses import dataclass
3
from typing import List, Optional, Union
4
5
6
7

import msgspec

from vllm.lora.request import LoRARequest
8
from vllm.multimodal import MultiModalKwargs, MultiModalPlaceholderDict
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from vllm.sampling_params import RequestOutputKind, SamplingParams


@dataclass
class DetokenizerRequest:

    request_id: str
    prompt: Optional[str]
    prompt_token_ids: List[int]
    skip_special_tokens: bool
    spaces_between_special_tokens: bool
    output_kind: RequestOutputKind

    stop: List[str]
    include_stop_str_in_output: bool


26
27
@dataclass
class EngineCoreRequest:
28
29
30
31
32
33
34
35
36
37

    # 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
    #NOTE(Nick): I don't think we need to pass prompt here since it should
    # always be tokenized?
    prompt: Optional[str]
    prompt_token_ids: List[int]
38
    mm_inputs: Optional[List[MultiModalKwargs]]
39
    mm_placeholders: Optional[MultiModalPlaceholderDict]
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    sampling_params: SamplingParams
    eos_token_id: Optional[int]
    arrival_time: float
    lora_request: Optional[LoRARequest]


class EngineCoreOutput(msgspec.Struct,
                       array_like=True,
                       omit_defaults=True,
                       gc=False):

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


class EngineCoreOutputs(msgspec.Struct,
                        array_like=True,
                        omit_defaults=True,
                        gc=False):

    #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]


70
71
72
73
74
@dataclass
class EngineCoreProfile:
    is_start: bool


75
76
77
78
79
80
81
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'
82
    PROFILE = b'\x02'