vllm.distributed.kv_transfer.kv_connector.utils ¶
KV cache helper for store.
KVOutputAggregator ¶
Utility class to aggregate the output of all workers into a single output corresponding to Rank 0 for scheduler.
Source code in vllm/distributed/kv_transfer/kv_connector/utils.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
__init__ ¶
__init__(expected_finished_count: int)
Source code in vllm/distributed/kv_transfer/kv_connector/utils.py
aggregate ¶
aggregate(
outputs: list[ModelRunnerOutput | None],
output_rank: int = 0,
) -> ModelRunnerOutput | None
Source code in vllm/distributed/kv_transfer/kv_connector/utils.py
from_connector classmethod ¶
from_connector(connector: KVConnectorBase, world_size: int)
TpKVTopology dataclass ¶
Helper class for tensor parallel and KV topology information for mapping between local and remote TP workers.
Source code in vllm/distributed/kv_transfer/kv_connector/utils.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
__init__ ¶
__init__(
tp_rank: int,
remote_tp_size: dict[str, int],
is_mla: bool,
total_num_kv_heads: int,
attn_backend: type[AttentionBackend],
engine_id: str,
remote_block_size: dict[str, int],
) -> None
__post_init__ ¶
Source code in vllm/distributed/kv_transfer/kv_connector/utils.py
block_size_ratio ¶
Calculate the block size ratio between local and remote TP.
Source code in vllm/distributed/kv_transfer/kv_connector/utils.py
block_size_ratio_from_engine_id ¶
get_target_remote_rank ¶
Get the remote TP rank (on P) that the current local TP rank (on D) will read from.
Source code in vllm/distributed/kv_transfer/kv_connector/utils.py
get_target_remote_rank_from_engine_id ¶
is_kv_replicated ¶
Whether the KV cache is replicated across TP workers due to the number of TP workers being greater than the number of KV heads.
Source code in vllm/distributed/kv_transfer/kv_connector/utils.py
replicates_kv_cache ¶
tp_ratio ¶
Calculate the tensor parallel ratio between local and remote TP. We can think of it as the number of local TP workers-per-remote TP workers. Local workers will read from the same remote TP worker in groups of size tp_ratio.
Source code in vllm/distributed/kv_transfer/kv_connector/utils.py
tp_ratio_from_engine_id ¶
_make_src_and_dst_indices ¶
_make_src_and_dst_indices(
src_block_ids: list[int],
dst_block_ids: list[int],
src_device: device | str,
dst_device: device | str,
) -> tuple[Tensor, Tensor]
Source code in vllm/distributed/kv_transfer/kv_connector/utils.py
copy_kv_blocks ¶
copy_kv_blocks(
src_kv_caches: dict[str, Tensor],
dst_kv_caches: dict[str, Tensor],
src_block_ids: list[int],
dst_block_ids: list[int],
direction: Literal["h2d", "d2h"],
) -> None
Copy kv blocks between different buffers.