vllm.v1.worker.gpu.attn_utils
¶
Classes:
-
AttentionCGSupportInfo– -
FastPrefillBatchMetadata–Per-step inputs for the KV-sharing fast prefill path.
-
FastPrefillHelper–Decides per step whether to arm the KV-sharing fast prefill path, and
Functions:
-
bind_kv_caches–Bind per-layer KV cache views to the attention layers.
-
get_attn_cg_support–Return the weakest CUDA graph support among the checked layers.
-
get_kv_sharing_fast_prefill_eligible_layers–Trailing run of KV-sharing layers, eligible for fast prefill.
-
get_query_lens_mismatch_unsupported_backend–Name the first backend needing the CPU query lengths to be exact, if any.
-
get_varlen_cudagraph_unsupported_backend–Name the first backend whose FULL cudagraphs cannot replay decode batches
-
init_attn_backend–maps_slot_mapping: the caller maps every slot mapping it builds to
AttentionCGSupportInfo
dataclass
¶
Methods:
-
narrow–Return an info tightened by
supportif it is more restrictive.
Source code in vllm/v1/worker/gpu/attn_utils.py
narrow(support, backend)
¶
Return an info tightened by support if it is more restrictive.
Lets attention groups built outside init_attn_backend (e.g.
encoder-only layers) contribute to the runner's cudagraph decision.
Source code in vllm/v1/worker/gpu/attn_utils.py
FastPrefillBatchMetadata
dataclass
¶
Per-step inputs for the KV-sharing fast prefill path.
Source code in vllm/v1/worker/gpu/attn_utils.py
FastPrefillHelper
¶
Decides per step whether to arm the KV-sharing fast prefill path, and stages the logits indices it runs on.
Source code in vllm/v1/worker/gpu/attn_utils.py
bind_kv_caches(kv_caches, forward_context, kv_cache_config, vllm_config, attn_groups=())
¶
Bind per-layer KV cache views to the attention layers.
Source code in vllm/v1/worker/gpu/attn_utils.py
get_attn_cg_support(attn_groups, vllm_config, checked_layer_names=None)
¶
Return the weakest CUDA graph support among the checked layers.
Source code in vllm/v1/worker/gpu/attn_utils.py
get_kv_sharing_fast_prefill_eligible_layers(vllm_config, draft_layer_names=None)
¶
Trailing run of KV-sharing layers, eligible for fast prefill.
In You Only Cache Once (https://arxiv.org/abs/2405.05254) or other similar KV sharing setups, only the layers that generate KV caches are involved in the prefill phase, enabling prefill to early exit. Layers are registered in execution order, so the eligible layers are the contiguous suffix of KV-sharing layers.
Speculator draft layers register after the target model's layers (and may themselves share KV), so they are excluded from the walk.
Source code in vllm/v1/worker/gpu/attn_utils.py
get_query_lens_mismatch_unsupported_backend(attn_groups, checked_layer_names=None)
¶
Name the first backend needing the CPU query lengths to be exact, if any.
The attention selector already excludes these when adaptive verification is enabled, but models that hard-wire their backend never consult it. See AttentionBackend.supports_device_cpu_query_lens_mismatch().
Source code in vllm/v1/worker/gpu/attn_utils.py
get_varlen_cudagraph_unsupported_backend(attn_groups, vllm_config, max_query_len, checked_layer_names=None)
¶
Name the first backend whose FULL cudagraphs cannot replay decode batches of 1 to max_query_len tokens per request, with its bound, if any.
ALWAYS builders replay any batch; the others need a bound of at least max_query_len. See AttentionMetadataBuilder.get_varlen_cudagraph_max_query_len().
Source code in vllm/v1/worker/gpu/attn_utils.py
init_attn_backend(kv_cache_config, vllm_config, device, active_layer_names=None, draft_layer_names=None, maps_slot_mapping=False, slot_mapped_layers=())
¶
maps_slot_mapping: the caller maps every slot mapping it builds to
kernel blocks (AttentionGroup.map_to_kernel_slot_mapping); or only for the
slot_mapped_layers, which another runner (a speculator) writes.
Source code in vllm/v1/worker/gpu/attn_utils.py
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 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |