Bases: ABC
Abstract class for attention backends.
Source code in vllm/attention/backends/abstract.py
  classmethod  ¶
    abstractmethod staticmethod  ¶
    abstractmethod staticmethod  ¶
 get_impl_cls() -> type[AttentionImpl]
 abstractmethod staticmethod  ¶
    staticmethod  ¶
    abstractmethod staticmethod  ¶
 get_metadata_cls() -> type[AttentionMetadata]
 classmethod  ¶
 get_supported_kernel_block_size() -> list[int | MultipleOf]
 classmethod  ¶
 make_metadata(*args, **kwargs) -> AttentionMetadata
 
 Source code in vllm/attention/backends/abstract.py
 | 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 |  | 
 class-attribute instance-attribute  ¶
 can_return_lse_for_decode: bool = False
 class-attribute instance-attribute  ¶
 need_to_return_lse_for_decode: bool = False
 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
  
  Source code in vllm/attention/backends/abstract.py
  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(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
  staticmethod  ¶
 get_supported_kernel_block_size() -> list[int | MultipleOf]
 
 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
  
  Bases: Protocol
Source code in vllm/attention/backends/abstract.py
  
   
 Attention type. Use string to be compatible with torch.compile.
Source code in vllm/attention/backends/abstract.py
  class-attribute instance-attribute  ¶
  Decoder attention between previous layer Q/K/V.
 class-attribute instance-attribute  ¶
  Encoder attention between previous layer Q/K/V for encoder-decoder.
 class-attribute instance-attribute  ¶
  Attention between dec. Q and enc. K/V for encoder-decoder.
 class-attribute instance-attribute  ¶
  Encoder attention between previous layer Q/K/V.
 
  Bases: AttentionImpl[T], Generic[T]
Source code in vllm/attention/backends/abstract.py
  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
  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