request.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. __hash__ = AdapterRequest.__hash__
  25. def __post_init__(self):
  26. if 'lora_local_path' in self.__struct_fields__:
  27. warnings.warn(
  28. "The 'lora_local_path' attribute is deprecated "
  29. "and will be removed in a future version. "
  30. "Please use 'lora_path' instead.",
  31. DeprecationWarning,
  32. stacklevel=2)
  33. if not self.lora_path:
  34. self.lora_path = self.lora_local_path or ""
  35. # Ensure lora_path is not empty
  36. assert self.lora_path, "lora_path cannot be empty"
  37. @property
  38. def adapter_id(self):
  39. return self.lora_int_id
  40. @property
  41. def name(self):
  42. return self.lora_name
  43. @property
  44. def path(self):
  45. return self.lora_path
  46. @property
  47. def local_path(self):
  48. warnings.warn(
  49. "The 'local_path' attribute is deprecated "
  50. "and will be removed in a future version. "
  51. "Please use 'path' instead.",
  52. DeprecationWarning,
  53. stacklevel=2)
  54. return self.lora_path
  55. @local_path.setter
  56. def local_path(self, value):
  57. warnings.warn(
  58. "The 'local_path' attribute is deprecated "
  59. "and will be removed in a future version. "
  60. "Please use 'path' instead.",
  61. DeprecationWarning,
  62. stacklevel=2)
  63. self.lora_path = value