vllm.attention.backends.abstract ¶
AttentionBackend ¶
Bases: ABC
Abstract class for attention backends.
Source code in vllm/attention/backends/abstract.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 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 | |
supported_kernel_block_sizes class-attribute ¶
supported_kernel_block_sizes: list[int | MultipleOf] = [
MultipleOf(1)
]
full_cls_name classmethod ¶
get_builder_cls abstractmethod staticmethod ¶
get_impl_cls abstractmethod staticmethod ¶
get_impl_cls() -> type[AttentionImpl]
get_kv_cache_shape abstractmethod staticmethod ¶
get_kv_cache_stride_order staticmethod ¶
get_required_kv_cache_layout classmethod ¶
get_required_kv_cache_layout() -> KVCacheLayoutType | None
get_supported_head_sizes classmethod ¶
supports_block_size classmethod ¶
Source code in vllm/attention/backends/abstract.py
supports_combination classmethod ¶
supports_combination(
head_size: int,
dtype: dtype,
kv_cache_dtype: CacheDType | None,
block_size: int | None,
use_mla: bool,
has_sink: bool,
use_sparse: bool,
device_capability: DeviceCapability,
) -> str | None
Source code in vllm/attention/backends/abstract.py
supports_compute_capability classmethod ¶
supports_compute_capability(
capability: DeviceCapability,
) -> bool
supports_dtype classmethod ¶
supports_head_size classmethod ¶
supports_kv_cache_dtype classmethod ¶
supports_kv_cache_dtype(
kv_cache_dtype: CacheDType | None,
) -> bool
Source code in vllm/attention/backends/abstract.py
validate_configuration classmethod ¶
validate_configuration(
head_size: int,
dtype: dtype,
kv_cache_dtype: CacheDType | None,
block_size: int | None,
use_mla: bool,
has_sink: bool,
use_sparse: bool,
device_capability: DeviceCapability,
) -> list[str]
Source code in vllm/attention/backends/abstract.py
AttentionImpl ¶
Source code in vllm/attention/backends/abstract.py
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 | |
can_return_lse_for_decode class-attribute instance-attribute ¶
can_return_lse_for_decode: bool = False
need_to_return_lse_for_decode class-attribute instance-attribute ¶
need_to_return_lse_for_decode: bool = False
__init__ abstractmethod ¶
__init__(
num_heads: int,
head_size: int,
scale: float,
num_kv_heads: int | None = None,
alibi_slopes: list[float] | None = None,
sliding_window: int | None = None,
kv_cache_dtype: str = "auto",
logits_soft_cap: float | None = None,
attn_type: str = DECODER,
kv_sharing_target_layer_name: str | None = None,
) -> None
Source code in vllm/attention/backends/abstract.py
__new__ ¶
Source code in vllm/attention/backends/abstract.py
forward abstractmethod ¶
forward(
layer: AttentionLayer,
query: Tensor,
key: Tensor,
value: Tensor,
kv_cache: Tensor,
attn_metadata: T,
output: Tensor | None = None,
output_scale: Tensor | None = None,
output_block_scale: Tensor | None = None,
) -> Tensor
Source code in vllm/attention/backends/abstract.py
fused_output_quant_supported ¶
fused_output_quant_supported(quant_key: QuantKey)
Does this attention implementation support fused output quantization. This is used by the AttnFusionPass to only fuse output quantization onto implementations that support it.
:param quant_key: QuantKey object that describes the quantization op :return: is fusion supported for this type of quantization
Source code in vllm/attention/backends/abstract.py
supports_quant_query_input ¶
supports_quant_query_input() -> bool
Check if this attention implementation supports pre-quantized query input.
When True, the attention layer will quantize queries before passing them to this backend, allowing torch.compile to fuse the quantization with previous operations. This is typically supported when using FP8 KV cache with compatible attention kernels (e.g., TRT-LLM). TODO add support to more backends: https://github.com/vllm-project/vllm/issues/25584
Returns:
| Name | Type | Description |
|---|---|---|
bool | bool | True if the implementation can accept pre-quantized queries. |
Source code in vllm/attention/backends/abstract.py
AttentionLayer ¶
Bases: Protocol
Source code in vllm/attention/backends/abstract.py
AttentionMetadata ¶
AttentionType ¶
Attention type. Use string to be compatible with torch.compile.
Source code in vllm/attention/backends/abstract.py
DECODER class-attribute instance-attribute ¶
Decoder attention between previous layer Q/K/V.
ENCODER class-attribute instance-attribute ¶
Encoder attention between previous layer Q/K/V for encoder-decoder.
ENCODER_DECODER class-attribute instance-attribute ¶
Attention between dec. Q and enc. K/V for encoder-decoder.
ENCODER_ONLY class-attribute instance-attribute ¶
Encoder attention between previous layer Q/K/V.
MLAAttentionImpl ¶
Bases: AttentionImpl[T], Generic[T]
Source code in vllm/attention/backends/abstract.py
__init__ abstractmethod ¶
__init__(
num_heads: int,
head_size: int,
scale: float,
num_kv_heads: int,
alibi_slopes: list[float] | None,
sliding_window: int | None,
kv_cache_dtype: str,
logits_soft_cap: float | None,
attn_type: str,
kv_sharing_target_layer_name: str | None,
q_lora_rank: int | None,
kv_lora_rank: int,
qk_nope_head_dim: int,
qk_rope_head_dim: int,
qk_head_dim: int,
v_head_dim: int,
kv_b_proj: ColumnParallelLinear,
indexer: object | None = None,
) -> None
Source code in vllm/attention/backends/abstract.py
forward abstractmethod ¶
forward(
layer: AttentionLayer,
hidden_states_or_cq: Tensor,
kv_c_normed: Tensor,
k_pe: Tensor,
kv_cache: Tensor,
attn_metadata: T,
output: Tensor | None = None,
output_scale: Tensor | None = None,
output_block_scale: Tensor | None = None,
) -> Tensor