request.py 2.3 KB

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