vllm.v1.worker.kv_connector_model_runner_mixin ¶
Define KV connector functionality mixin for model runners.
KVConnectorModelRunnerMixin ¶
Source code in vllm/v1/worker/kv_connector_model_runner_mixin.py
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 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 308 309 | |
_get_kv_connector_output staticmethod ¶
_get_kv_connector_output(
scheduler_output: SchedulerOutput,
wait_for_save: bool = True,
) -> Generator[KVConnectorOutput, None, None]
Source code in vllm/v1/worker/kv_connector_model_runner_mixin.py
allocate_uniform_kv_caches staticmethod ¶
allocate_uniform_kv_caches(
kv_cache_config: KVCacheConfig,
attn_groups: list[list[AttentionGroup]],
cache_dtype: CacheDType,
device: device,
kernel_block_sizes: list[int],
) -> tuple[
dict[str, Tensor], Tensor, type[AttentionBackend]
]
Initializes and reshapes KV caches for the simple case where all layers have the same layout.
This function assumes use_uniform_kv_cache() returned True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kv_cache_config | KVCacheConfig | The KV cache config | required |
attn_groups | list[list[AttentionGroup]] | The list of attention groups for this model | required |
cache_dtype | CacheDType | The KV cache dtype | required |
device | device | The torch device to allocate on. | required |
kernel_block_sizes | list[int] | The kernel block sizes for each KV cache group. | required |
Returns: A tuple (kv_caches, cross_layers_kv_cache, attn_backend) where: kv_caches is a dict mapping between layer names to their corresponding memory buffer for KV cache. cross_layers_kv_cache is the cross layers kv cache tensor attn_backend is the attention backend matching this tensor
Source code in vllm/v1/worker/kv_connector_model_runner_mixin.py
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 308 309 | |
ensure_kv_transfer_shutdown staticmethod ¶
Source code in vllm/v1/worker/kv_connector_model_runner_mixin.py
get_finished_kv_transfers staticmethod ¶
get_finished_kv_transfers(
scheduler_output: SchedulerOutput,
) -> tuple[set[str] | None, set[str] | None]
Source code in vllm/v1/worker/kv_connector_model_runner_mixin.py
get_kv_connector_stats staticmethod ¶
get_kv_connector_stats() -> KVConnectorStats | None
kv_connector_no_forward staticmethod ¶
kv_connector_no_forward(
scheduler_output: SchedulerOutput,
vllm_config: VllmConfig,
) -> ModelRunnerOutput
Source code in vllm/v1/worker/kv_connector_model_runner_mixin.py
maybe_get_kv_connector_output staticmethod ¶
maybe_get_kv_connector_output(
scheduler_output: SchedulerOutput,
) -> AbstractContextManager[KVConnectorOutput | None]
Source code in vllm/v1/worker/kv_connector_model_runner_mixin.py
maybe_setup_kv_connector staticmethod ¶
maybe_setup_kv_connector(scheduler_output: SchedulerOutput)
Source code in vllm/v1/worker/kv_connector_model_runner_mixin.py
maybe_wait_for_kv_save staticmethod ¶
use_uniform_kv_cache staticmethod ¶
use_uniform_kv_cache(
attn_groups: list[list[AttentionGroup]],
cache_dtype: CacheDType,
) -> bool
Determines whether a uniform KV layout should be used. A uniform layout means all layers KV caches will share the same underlying tensor, where for a given block number, the respective KV data for all layers will be contiguous. This will allow efficient KV transfer of per-block KV data for all layers at once. Note this layout will only be applied given 3 conditions: 1. The KV Cache config contains just a single group where all layers have the same page size. 2. A KV connector is configured, and the KV connector instance prefers to use this layout (prefer_cross_layer_blocks() returns True) 2. The flash attention backend supports this layout (get_kv_cache_stride_order(True) includes a placement for a num_layers dimension)
Note that the actual placement of the num_layers dimensions in the unified layers tensors will be determined by the attention backend. Thus, the layers KV data may still not be contiguous per block if the attention backend does not support it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attn_groups | list[list[AttentionGroup]] | The list of attention groups for this model | required |
cache_dtype | CacheDType | The KV cache dtype | required |
Returns: True if we should use a uniform KV cache layout.