protocol.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from typing import AsyncGenerator, List, Optional, Protocol, runtime_checkable
  2. from transformers import PreTrainedTokenizer
  3. from aphrodite.common.config import DecodingConfig, ModelConfig
  4. from aphrodite.common.outputs import EmbeddingRequestOutput, RequestOutput
  5. from aphrodite.common.pooling_params import PoolingParams
  6. from aphrodite.common.sampling_params import SamplingParams
  7. from aphrodite.inputs.data import PromptType
  8. from aphrodite.lora.request import LoRARequest
  9. from aphrodite.modeling.layers.sampler import SamplerOutput
  10. from aphrodite.processing.scheduler import SchedulerOutputs
  11. from aphrodite.prompt_adapter.request import PromptAdapterRequest
  12. @runtime_checkable
  13. class EngineClient(Protocol):
  14. """Protocol class for Clients to Engine"""
  15. @property
  16. def is_running(self) -> bool:
  17. ...
  18. @property
  19. def is_stopped(self) -> bool:
  20. ...
  21. @property
  22. def errored(self) -> bool:
  23. ...
  24. @property
  25. def dead_error(self) -> BaseException:
  26. ...
  27. def generate(
  28. self,
  29. prompt: PromptType,
  30. sampling_params: SamplingParams,
  31. request_id: str,
  32. lora_request: Optional[LoRARequest] = None,
  33. prompt_adapter_request: Optional[PromptAdapterRequest] = None
  34. ) -> AsyncGenerator[RequestOutput, None]:
  35. """Generates outputs for a request"""
  36. ...
  37. def encode(
  38. self,
  39. prompt: PromptType,
  40. pooling_params: PoolingParams,
  41. request_id: str,
  42. lora_request: Optional[LoRARequest] = None,
  43. ) -> AsyncGenerator[EmbeddingRequestOutput, None]:
  44. """Generate outputs for a request from an embedding model."""
  45. ...
  46. async def abort(self, request_id: str) -> None:
  47. """Abort a request.
  48. Args:
  49. request_id: The unique id of the request.
  50. """
  51. ...
  52. async def get_model_config(self) -> ModelConfig:
  53. """Get the model configuration of the Aphrodite engine."""
  54. ...
  55. async def get_decoding_config(self) -> DecodingConfig:
  56. """Get the decoding configuration of the Aphrodite engine."""
  57. ...
  58. async def get_tokenizer(
  59. self,
  60. lora_request: Optional[LoRARequest] = None,
  61. ) -> PreTrainedTokenizer:
  62. """Get the appropriate Tokenizer for the request"""
  63. ...
  64. async def do_log_stats(
  65. self,
  66. scheduler_outputs: Optional[SchedulerOutputs] = None,
  67. model_output: Optional[List[SamplerOutput]] = None,
  68. ) -> None:
  69. pass
  70. async def check_health(self) -> None:
  71. """Raise if unhealthy"""