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:
-
compute_mm_prefix_ranges–Compute PrefixLM bidirectional ranges for multimodal tokens.
-
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.
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
compute_mm_prefix_ranges(req_ids, mm_features, sliding_window=None) ¶
Compute PrefixLM bidirectional ranges for multimodal tokens.
Ranges exceeding sliding_window are skipped to prevent early tokens from attending across the entire image span.
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().