request.py 1.72 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

4

5
6
import msgspec

7

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

    lora_int_id must be globally unique for a given adapter.
    This is currently not enforced in vLLM.
    """
19

20
21
    lora_name: str
    lora_int_id: int
22
    lora_path: str = ""
23
24
25
    long_lora_max_len: int | None = None
    base_model_name: str | None = msgspec.field(default=None)
    tensorizer_config_dict: dict | None = None
26

27
    def __post_init__(self):
28
29
        if self.lora_int_id < 1:
            raise ValueError(f"id must be > 0, got {self.lora_int_id}")
30
31
32
33

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

34
35
36
    @property
    def adapter_id(self):
        return self.lora_int_id
37

38
39
40
    @property
    def name(self):
        return self.lora_name
41

42
43
44
45
    @property
    def path(self):
        return self.lora_path

46
47
48
49
50
51
    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.
        """
52
        return isinstance(value, self.__class__) and self.lora_name == value.lora_name
53
54
55
56
57
58
59
60
61

    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)