__init__.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from dataclasses import dataclass
  2. from enum import Enum
  3. from typing import List, Mapping, Optional, Union
  4. from aphrodite import PoolingParams
  5. from aphrodite.common.outputs import RequestOutput
  6. from aphrodite.common.sampling_params import SamplingParams
  7. from aphrodite.inputs import PromptType
  8. from aphrodite.lora.request import LoRARequest
  9. from aphrodite.prompt_adapter.request import PromptAdapterRequest
  10. APHRODITE_RPC_SUCCESS_STR = "SUCCESS"
  11. IPC_INPUT_EXT = "_input_socket"
  12. IPC_OUTPUT_EXT = "_output_socket"
  13. IPC_HEALTH_EXT = "_health_socket"
  14. IPC_DATA_EXT = "_data_socket"
  15. class MQEngineDeadError(RuntimeError):
  16. pass
  17. @dataclass
  18. class RPCProcessRequest:
  19. prompt: PromptType
  20. params: Union[SamplingParams, PoolingParams]
  21. request_id: str
  22. lora_request: Optional[LoRARequest] = None
  23. trace_headers: Optional[Mapping[str, str]] = None
  24. prompt_adapter_request: Optional[PromptAdapterRequest] = None
  25. @dataclass
  26. class RPCError:
  27. request_id: Optional[str]
  28. is_engine_errored: bool
  29. exception: BaseException
  30. @dataclass
  31. class RPCAbortRequest:
  32. request_id: str
  33. class RPCHealthRequest:
  34. pass
  35. class RPCStartupRequest(Enum):
  36. IS_SERVER_READY = 1
  37. @dataclass
  38. class RPCStartupResponse:
  39. tracing_enabled: bool
  40. @dataclass
  41. class RPCShutdownRequest:
  42. pass
  43. RPC_REQUEST_T = Union[
  44. RPCProcessRequest,
  45. RPCAbortRequest,
  46. RPCHealthRequest,
  47. RPCStartupRequest,
  48. RPCShutdownRequest,
  49. ]
  50. REQUEST_OUTPUTS_T = Union[List[RequestOutput], RPCError]
  51. def ENGINE_DEAD_ERROR(
  52. error: Optional[BaseException] = None) -> MQEngineDeadError:
  53. if error is None:
  54. return MQEngineDeadError(
  55. "Engine loop is not running. Inspect the stacktrace to "
  56. "find the original error")
  57. return MQEngineDeadError(
  58. "Engine loop is not running. Inspect the stacktrace to "
  59. f"find the original error: {repr(error)}.")