embedding_model_block_manager.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from typing import List, Tuple
  2. from aphrodite.processing.interfaces import AllocStatus, BlockSpaceManager
  3. from aphrodite.common.sequence import Sequence, SequenceGroup
  4. class EmbeddingModelBlockSpaceManager(BlockSpaceManager):
  5. """An embedding version of BlockSpaceManager for use in environments
  6. with embedding models where block management is not required.
  7. This class provides the same interface as BlockSpaceManager, but its
  8. methods perform no actions or return simple values like True in specific
  9. actions. It's designed to be used in scenarios where the overhead of
  10. block management is unnecessary, such as in an embedding environment.
  11. """
  12. def __init__(
  13. self,
  14. **kwargs,
  15. ) -> None:
  16. pass
  17. def can_allocate(self, seq_group: SequenceGroup) -> AllocStatus:
  18. # Always return OK for dummy purposes
  19. return AllocStatus.OK
  20. def allocate(self, seq_group: SequenceGroup) -> None:
  21. # No actual allocation logic needed
  22. pass
  23. def can_append_slots(self, seq_group: SequenceGroup,
  24. num_lookahead_slots: int) -> bool:
  25. return True
  26. def append_slots(
  27. self,
  28. seq: Sequence,
  29. num_lookahead_slots: int,
  30. ) -> List[Tuple[int, int]]:
  31. return None # type: ignore
  32. def fork(self, parent_seq: Sequence, child_seq: Sequence) -> None:
  33. pass
  34. def can_swap_in(self, seq_group: SequenceGroup,
  35. num_lookahead_slots: int) -> AllocStatus:
  36. return AllocStatus.OK
  37. def swap_in(self, seq_group: SequenceGroup) -> List[Tuple[int, int]]:
  38. return None # type: ignore
  39. def can_swap_out(self, seq_group: SequenceGroup) -> bool:
  40. return True
  41. def swap_out(self, seq_group: SequenceGroup) -> List[Tuple[int, int]]:
  42. return None # type: ignore
  43. def free(self, seq: Sequence) -> None:
  44. # No operation on free
  45. return
  46. def get_block_table(self, seq: Sequence) -> List[int]:
  47. return None # type: ignore
  48. def get_num_free_gpu_blocks(self) -> int:
  49. return 1
  50. def get_num_free_cpu_blocks(self) -> int:
  51. return 1
  52. def access_all_blocks_in_seq(
  53. self,
  54. seq: Sequence,
  55. access_time: float,
  56. ) -> None:
  57. pass
  58. def get_common_computed_block_ids(self,
  59. seq_group: SequenceGroup) -> List[int]:
  60. return None # type: ignore
  61. def mark_blocks_as_computed(self, seq_group: SequenceGroup):
  62. pass