placeholder_block_space_manager.py 2.5 KB

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