|
1 | | -from collections import defaultdict |
2 | | -from typing import Dict, Iterable, List, Optional, Protocol |
| 1 | +from typing import Dict, Iterable, List, Optional, Protocol, Tuple |
3 | 2 |
|
4 | 3 | from vllm.core.block.interfaces import Block, BlockAllocator |
5 | 4 |
|
@@ -111,7 +110,7 @@ def __init__( |
111 | 110 | refcounter: RefCounterProtocol, |
112 | 111 | allocator: BlockAllocator, |
113 | 112 | ): |
114 | | - self._copy_on_writes: Dict[BlockId, List[BlockId]] = defaultdict(list) |
| 113 | + self._copy_on_writes: List[Tuple[BlockId, BlockId]] = [] |
115 | 114 | self._refcounter = refcounter |
116 | 115 | self._allocator = allocator |
117 | 116 |
|
@@ -152,25 +151,25 @@ def cow_block_if_not_appendable(self, block: Block) -> Optional[BlockId]: |
152 | 151 | # Track src/dst copy. |
153 | 152 | assert src_block_id is not None |
154 | 153 | assert block_id is not None |
155 | | - self._copy_on_writes[src_block_id].append(block_id) |
| 154 | + self._copy_on_writes.append((src_block_id, block_id)) |
156 | 155 |
|
157 | 156 | return block_id |
158 | 157 |
|
159 | | - def clear_cows(self) -> Dict[BlockId, List[BlockId]]: |
| 158 | + def clear_cows(self) -> List[Tuple[BlockId, BlockId]]: |
160 | 159 | """Clears the copy-on-write tracking information and returns the current |
161 | 160 | state. |
162 | 161 |
|
163 | | - This method returns a dictionary mapping source block indices to lists |
164 | | - of destination block indices for the current copy-on-write operations. |
| 162 | + This method returns a list mapping source block indices to |
| 163 | + destination block indices for the current copy-on-write operations. |
165 | 164 | It then clears the internal tracking information. |
166 | 165 |
|
167 | 166 | Returns: |
168 | | - Dict[BlockId, List[BlockId]]: A dictionary mapping source |
169 | | - block indices to lists of destination block indices for the |
| 167 | + List[Tuple[BlockId, BlockId]]: A list mapping source |
| 168 | + block indices to destination block indices for the |
170 | 169 | current copy-on-write operations. |
171 | 170 | """ |
172 | | - cows = dict(self._copy_on_writes) |
173 | | - self._copy_on_writes.clear() |
| 171 | + cows = self._copy_on_writes |
| 172 | + self._copy_on_writes = [] |
174 | 173 | return cows |
175 | 174 |
|
176 | 175 |
|
|
0 commit comments