request.py 2.13 KB
Newer Older
1
2
import warnings
from dataclasses import dataclass, field
3
from typing import Optional
4

5
6
from vllm.adapter_commons.request import AdapterRequest

7
8

@dataclass
9
class LoRARequest(AdapterRequest):
10
11
12
    """
    Request for a LoRA adapter.

13
    Note that this class should be used internally. For online
14
15
16
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.
    """

    lora_name: str
    lora_int_id: int
24
25
    lora_path: str = ""
    lora_local_path: Optional[str] = field(default=None, repr=False)
26
    long_lora_max_len: Optional[int] = None
27
    __hash__ = AdapterRequest.__hash__
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
    def __post_init__(self):
        if 'lora_local_path' in self.__dict__:
            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"

43
44
45
    @property
    def adapter_id(self):
        return self.lora_int_id
46

47
48
49
    @property
    def name(self):
        return self.lora_name
50

51
52
53
54
    @property
    def path(self):
        return self.lora_path

55
56
    @property
    def local_path(self):
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
        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