vllm.attention.backends.abstract ¶
AttentionBackend ¶
Bases: ABC
Abstract class for attention backends.
Source code in vllm/attention/backends/abstract.py
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_metadata_cls abstractmethod
staticmethod
¶
get_metadata_cls() -> type[AttentionMetadata]
get_supported_kernel_block_size classmethod
¶
get_supported_kernel_block_size() -> list[int | MultipleOf]
make_metadata classmethod
¶
make_metadata(*args, **kwargs) -> AttentionMetadata
AttentionImpl ¶
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 |
|
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
get_supported_kernel_block_size staticmethod
¶
get_supported_kernel_block_size() -> list[int | MultipleOf]
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