Return valid engine block IDs and their LMCache object token offset. Args: object_idx: Index of the LMCache object/chunk being processed. block_id_list: Full ordered engine block ids for the transfer. blocks_per_object: Number of blocks represented by one LMCache object.
(
object_idx: int,
block_id_list: list[int],
blocks_per_object: int,
block_size: int,
skip_prefix_n_blocks: int,
)
| 1231 | |
| 1232 | |
| 1233 | def _valid_block_range( |
| 1234 | object_idx: int, |
| 1235 | block_id_list: list[int], |
| 1236 | blocks_per_object: int, |
| 1237 | block_size: int, |
| 1238 | skip_prefix_n_blocks: int, |
| 1239 | ) -> tuple[list[int], int] | None: |
| 1240 | """Return valid engine block IDs and their LMCache object token offset. |
| 1241 | |
| 1242 | Args: |
| 1243 | object_idx: Index of the LMCache object/chunk being processed. |
| 1244 | block_id_list: Full ordered engine block ids for the transfer. |
| 1245 | blocks_per_object: Number of blocks represented by one LMCache object. |
| 1246 | block_size: Number of tokens per block. |
| 1247 | skip_prefix_n_blocks: Number of leading flat block positions to skip. |
| 1248 | |
| 1249 | Returns: |
| 1250 | ``None`` if this object has no valid blocks after skip handling. |
| 1251 | Otherwise, a tuple of valid engine block ids and the token offset |
| 1252 | within this LMCache object where those blocks start. |
| 1253 | """ |
| 1254 | object_flat_start = object_idx * blocks_per_object |
| 1255 | valid_flat_start = max(object_flat_start, skip_prefix_n_blocks) |
| 1256 | valid_flat_end = min(object_flat_start + blocks_per_object, len(block_id_list)) |
| 1257 | if valid_flat_start >= valid_flat_end: |
| 1258 | return None |
| 1259 | offset_in_object = (valid_flat_start - object_flat_start) * block_size |
| 1260 | return block_id_list[valid_flat_start:valid_flat_end], offset_in_object |
| 1261 | |
| 1262 | |
| 1263 | def _valid_block_range_indices( |
nothing calls this directly
no outgoing calls
no test coverage detected