request.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import warnings
  2. from dataclasses import dataclass, field
  3. from typing import Optional
  4. from aphrodite.adapter_commons.request import AdapterRequest
  5. @dataclass
  6. class LoRARequest:
  7. """
  8. Request for a LoRA adapter.
  9. Note that this class should be be used internally. For online
  10. serving, it is recommended to not allow users to use this class but
  11. instead provide another layer of abstraction to prevent users from
  12. accessing unauthorized LoRA adapters.
  13. lora_int_id must be globally unique for a given adapter.
  14. This is currently not enforced in Aphrodite.
  15. """
  16. lora_name: str
  17. lora_int_id: int
  18. lora_path: str = ""
  19. lora_local_path: Optional[str] = field(default=None, repr=False)
  20. long_lora_max_len: Optional[int] = None
  21. __hash__ = AdapterRequest.__hash__
  22. def __post_init__(self):
  23. if 'lora_local_path' in self.__dict__:
  24. warnings.warn(
  25. "The 'lora_local_path' attribute is deprecated "
  26. "and will be removed in a future version. "
  27. "Please use 'lora_path' instead.",
  28. DeprecationWarning,
  29. stacklevel=2)
  30. if not self.lora_path:
  31. self.lora_path = self.lora_local_path or ""
  32. # Ensure lora_path is not empty
  33. assert self.lora_path, "lora_path cannot be empty"
  34. @property
  35. def adapter_id(self):
  36. return self.lora_int_id
  37. @property
  38. def name(self):
  39. return self.lora_name
  40. @property
  41. def path(self):
  42. return self.lora_path
  43. @property
  44. def local_path(self):
  45. warnings.warn(
  46. "The 'local_path' attribute is deprecated "
  47. "and will be removed in a future version. "
  48. "Please use 'path' instead.",
  49. DeprecationWarning,
  50. stacklevel=2)
  51. return self.lora_path
  52. @local_path.setter
  53. def local_path(self, value):
  54. warnings.warn(
  55. "The 'local_path' attribute is deprecated "
  56. "and will be removed in a future version. "
  57. "Please use 'path' instead.",
  58. DeprecationWarning,
  59. stacklevel=2)
  60. self.lora_path = value