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
AttentionCGSupportInfo
dataclass
¶
FastPrefillBatchMetadata
dataclass
¶
Per-step inputs for the KV-sharing fast prefill path.
FastPrefillHelper
¶
Decides per step whether to arm the KV-sharing fast prefill path, and stages the logits indices it runs on.
bind_kv_caches(kv_caches, forward_context, kv_cache_config, vllm_config, attn_groups=())
¶
Bind per-layer KV cache views to the attention layers.
get_attn_cg_support(attn_groups, vllm_config, checked_layer_names=None)
¶
Return the weakest CUDA graph support among the checked layers.
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.
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().
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().