main
py 27 lines 991 Bytes
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 from vllm.distributed.kv_events import KVCacheEvent
5 from vllm.v1.core.block_pool import BlockPool
6
7
8 class SharedEventQueueBlockPool(BlockPool):
9 """A pool that publishes into another pool's live KV event queue.
10
11 The owner rebinds its queue on every drain, so this reads it through the
12 owner rather than holding a reference.
13 """
14
15 def __init__(self, *args, event_owner: BlockPool, **kwargs) -> None:
16 self._event_owner = event_owner
17 super().__init__(*args, **kwargs)
18
19 @property
20 def kv_event_queue(self) -> list[KVCacheEvent]:
21 return self._event_owner.kv_event_queue
22
23 @kv_event_queue.setter
24 def kv_event_queue(self, events: list[KVCacheEvent]) -> None:
25 # ``BlockPool.__init__`` seeds an empty queue and ``take_events``
26 # swaps in a fresh one; both belong to the owner, which drains it.
27 assert not events