protocol.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.common.sequence import SamplerOutput
  8. from aphrodite.inputs.data import PromptInputs
  9. from aphrodite.lora.request import LoRARequest
  10. from aphrodite.processing.scheduler import SchedulerOutputs
  11. from aphrodite.prompt_adapter.request import PromptAdapterRequest
  12. @runtime_checkable
  13. class AsyncEngineClient(Protocol):
  14. """Protocol class for Clients to AsyncAphrodite"""
  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. def generate(
  25. self,
  26. inputs: PromptInputs,
  27. sampling_params: SamplingParams,
  28. request_id: str,
  29. lora_request: Optional[LoRARequest] = None,
  30. prompt_adapter_request: Optional[PromptAdapterRequest] = None
  31. ) -> AsyncGenerator[RequestOutput, None]:
  32. """Generates outputs for a request"""
  33. ...
  34. def encode(
  35. self,
  36. inputs: PromptInputs,
  37. pooling_params: PoolingParams,
  38. request_id: str,
  39. lora_request: Optional[LoRARequest] = None,
  40. ) -> AsyncGenerator[EmbeddingRequestOutput, None]:
  41. """Generate outputs for a request from an embedding model."""
  42. ...
  43. async def abort(self, request_id: str) -> None:
  44. """Abort a request.
  45. Args:
  46. request_id: The unique id of the request.
  47. """
  48. ...
  49. async def get_model_config(self) -> ModelConfig:
  50. """Get the model configuration of the Aphrodite engine."""
  51. ...
  52. async def get_decoding_config(self) -> DecodingConfig:
  53. """Get the decoding configuration of the Aphrodite engine."""
  54. ...
  55. async def get_tokenizer(
  56. self,
  57. lora_request: Optional[LoRARequest] = None,
  58. ) -> PreTrainedTokenizer:
  59. """Get the appropriate Tokenizer for the request"""
  60. ...
  61. async def do_log_stats(
  62. self,
  63. scheduler_outputs: Optional[SchedulerOutputs] = None,
  64. model_output: Optional[List[SamplerOutput]] = None,
  65. ) -> None:
  66. pass
  67. async def check_health(self) -> None:
  68. """Raise if unhealthy"""