"tests/entrypoints/serve/instrumentator/test_basic.py" did not exist on "83004020fd2400f56df2686e8c55df3d9fc79b7b"
request.py 3.1 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

4
import warnings
5
from typing import Optional
6

7
8
import msgspec

9
10
from vllm.adapter_commons.request import AdapterRequest

11

12
13
14
15
class LoRARequest(
        msgspec.Struct,
        omit_defaults=True,  # type: ignore[call-arg]
        array_like=True):  # type: ignore[call-arg]
16
17
18
    """
    Request for a LoRA adapter.

19
    Note that this class should be used internally. For online
20
21
22
23
24
25
26
    serving, it is recommended to not allow users to use this class but
    instead provide another layer of abstraction to prevent users from
    accessing unauthorized LoRA adapters.

    lora_int_id must be globally unique for a given adapter.
    This is currently not enforced in vLLM.
    """
27
    __metaclass__ = AdapterRequest
28
29
30

    lora_name: str
    lora_int_id: int
31
    lora_path: str = ""
32
    lora_local_path: Optional[str] = msgspec.field(default=None)
33
    long_lora_max_len: Optional[int] = None
34
    base_model_name: Optional[str] = msgspec.field(default=None)
35
    tensorizer_config_dict: Optional[dict] = None
36

37
    def __post_init__(self):
38
        if self.lora_local_path:
39
40
41
42
43
44
45
46
47
48
49
50
            warnings.warn(
                "The 'lora_local_path' attribute is deprecated "
                "and will be removed in a future version. "
                "Please use 'lora_path' instead.",
                DeprecationWarning,
                stacklevel=2)
            if not self.lora_path:
                self.lora_path = self.lora_local_path or ""

        # Ensure lora_path is not empty
        assert self.lora_path, "lora_path cannot be empty"

51
52
53
    @property
    def adapter_id(self):
        return self.lora_int_id
54

55
56
57
    @property
    def name(self):
        return self.lora_name
58

59
60
61
62
    @property
    def path(self):
        return self.lora_path

63
64
    @property
    def local_path(self):
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
        warnings.warn(
            "The 'local_path' attribute is deprecated "
            "and will be removed in a future version. "
            "Please use 'path' instead.",
            DeprecationWarning,
            stacklevel=2)
        return self.lora_path

    @local_path.setter
    def local_path(self, value):
        warnings.warn(
            "The 'local_path' attribute is deprecated "
            "and will be removed in a future version. "
            "Please use 'path' instead.",
            DeprecationWarning,
            stacklevel=2)
        self.lora_path = value
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

    def __eq__(self, value: object) -> bool:
        """
        Overrides the equality method to compare LoRARequest
        instances based on lora_name. This allows for identification
        and comparison lora adapter across engines.
        """
        return isinstance(value,
                          self.__class__) and self.lora_name == value.lora_name

    def __hash__(self) -> int:
        """
        Overrides the hash method to hash LoRARequest instances
        based on lora_name. This ensures that LoRARequest instances
        can be used in hash-based collections such as sets and dictionaries,
        identified by their names across engines.
        """
        return hash(self.lora_name)