request.py 2.25 KB
Newer Older
1
import warnings
2
from typing import Optional
3

4
5
import msgspec

6
7
from vllm.adapter_commons.request import AdapterRequest

8

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

16
    Note that this class should be used internally. For online
17
18
19
20
21
22
23
    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.
    """
24
    __metaclass__ = AdapterRequest
25
26
27

    lora_name: str
    lora_int_id: int
28
    lora_path: str = ""
29
    lora_local_path: Optional[str] = msgspec.field(default=None)
30
    long_lora_max_len: Optional[int] = None
31
    __hash__ = AdapterRequest.__hash__
32

33
    def __post_init__(self):
34
        if 'lora_local_path' in self.__struct_fields__:
35
36
37
38
39
40
41
42
43
44
45
46
            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"

47
48
49
    @property
    def adapter_id(self):
        return self.lora_int_id
50

51
52
53
    @property
    def name(self):
        return self.lora_name
54

55
56
57
58
    @property
    def path(self):
        return self.lora_path

59
60
    @property
    def local_path(self):
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        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