vllm.config.attention ¶
Classes:
-
AttentionConfig–Configuration for attention mechanisms in vLLM.
AttentionConfig ¶
Configuration for attention mechanisms in vLLM.
Methods:
-
compute_hash–Provide a hash that uniquely identifies all the configs
-
resolve_indexer_kv_dtype–Resolve
indexer_kv_dtype, substitutingdefaultfor "auto". -
validate_backend_before–Enable parsing of the
backendenum type from string. -
validate_backend_per_kind_before–Parse the
backend_per_kindmap from strings. -
validate_mla_prefill_backend_before–Enable parsing of the
mla_prefill_backendenum type from string.
Attributes:
-
backend(AttentionBackendEnum | None) –Attention backend to use. Use "auto" or None for automatic selection.
-
backend_per_kind(dict[str, AttentionBackendEnum]) –Per-KV-cache-group attention backend overrides, keyed by
-
disable_flashinfer_q_quantization(bool) –If set, when using fp8 kv, do not quantize Q to fp8.
-
flash_attn_max_num_splits_for_cuda_graph(int) –Flash Attention max number splits for cuda graph decode.
-
flash_attn_version(Literal[2, 3, 4] | None) –Force vllm to use a specific flash-attention version (2, 3, or 4).
-
flex_attn_block_m(int | None) –Triton kernel BLOCK_M tile size for flex attention.
-
flex_attn_block_n(int | None) –Triton kernel BLOCK_N tile size for flex attention.
-
flex_attn_kv_block_size(int | None) –Logical KV block size for the flex attention block mask.
-
flex_attn_q_block_size(int | None) –Logical Q block size for the flex attention block mask.
-
indexer_kv_dtype(IndexerKVDType) –Data type for the sparse-attention indexer K cache. "auto" picks the
-
minimax_m3_msa_decode_backend(MiniMaxM3MSADecodeBackend) –Sparse decode kernel used by the MiniMax M3 MSA backend.
-
mla_prefill_backend(MLAPrefillBackendEnum | None) –MLA prefill backend to use. If None, will be selected automatically.
-
sparse_mla_force_mqa(bool) –Force sparse MLA to use forward_mqa for all requests, including prefill.
-
tq_max_kv_splits_for_cuda_graph(int) –TurboQuant max NUM_KV_SPLITS for cuda graph decode.
-
use_fp4_indexer_cache(bool | None) –Deprecated alias for
indexer_kv_dtype; use that instead. True maps to -
use_non_causal(bool) –Whether to use non-causal (bidirectional) attention.
-
use_prefill_decode_attention(bool) –Use separate prefill and decode kernels for attention instead of
-
use_prefill_query_quantization(bool) –If set, quantize query for attention in prefill.
-
use_trtllm_attention(bool | None) –If set to True/False, use or don't use the TRTLLM attention backend
Source code in vllm/config/attention.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 | |
backend = None class-attribute instance-attribute ¶
Attention backend to use. Use "auto" or None for automatic selection.
backend_per_kind = field(default_factory=dict) class-attribute instance-attribute ¶
Per-KV-cache-group attention backend overrides, keyed by KVCacheSpecKind (e.g. {"mla_attention": "FLASHINFER_MLA", "sliding_window_mla": "TRITON_MLA"}). This lets a model that splits its layers across multiple KV-cache groups (e.g. interleaved full and sliding-window attention) use a different backend per group.
An entry overrides backend for layers of the matching kind; kinds not listed fall back to backend (or automatic selection). A selected backend that is invalid for that kind raises at startup.
disable_flashinfer_q_quantization = False class-attribute instance-attribute ¶
If set, when using fp8 kv, do not quantize Q to fp8.
flash_attn_max_num_splits_for_cuda_graph = 32 class-attribute instance-attribute ¶
Flash Attention max number splits for cuda graph decode.
flash_attn_version = None class-attribute instance-attribute ¶
Force vllm to use a specific flash-attention version (2, 3, or 4). Only valid when using the flash-attention backend.
flex_attn_block_m = None class-attribute instance-attribute ¶
Triton kernel BLOCK_M tile size for flex attention. Must be a power of 2 >= 16. If None and VLLM_BATCH_INVARIANT=1, defaults to 16.
flex_attn_block_n = None class-attribute instance-attribute ¶
Triton kernel BLOCK_N tile size for flex attention. Must be a power of 2 >= 16. If None and VLLM_BATCH_INVARIANT=1, defaults to 16.
flex_attn_kv_block_size = None class-attribute instance-attribute ¶
Logical KV block size for the flex attention block mask. Must be a power of 2 and divisible by flex_attn_block_n. If None, uses the KV cache block size for paged KV attention on PyTorch >= 2.9, and 128 for encoder-only attention or older PyTorch versions.
flex_attn_q_block_size = None class-attribute instance-attribute ¶
Logical Q block size for the flex attention block mask. Must be a power of 2 and divisible by flex_attn_block_m. If None, uses 16 for paged KV attention on PyTorch >= 2.9, and 128 for encoder-only attention or older PyTorch versions.
indexer_kv_dtype = 'auto' class-attribute instance-attribute ¶
Data type for the sparse-attention indexer K cache. "auto" picks the model's default (bf16 for MiniMax M3, fp8 for the DeepSeek sparse indexer). Quantized formats (fp8, mxfp4, nvfp4) require indexer kernel support in the backend.
minimax_m3_msa_decode_backend = 'triton' class-attribute instance-attribute ¶
Sparse decode kernel used by the MiniMax M3 MSA backend.
mla_prefill_backend = None class-attribute instance-attribute ¶
MLA prefill backend to use. If None, will be selected automatically. Valid options: FLASH_ATTN (FA3/FA4), FLASHINFER, TRTLLM_RAGGED.
sparse_mla_force_mqa = False class-attribute instance-attribute ¶
Force sparse MLA to use forward_mqa for all requests, including prefill. When False (default), pure prefill batches use forward_mha when implemented. Set to True to always use the MQA path.
tq_max_kv_splits_for_cuda_graph = 32 class-attribute instance-attribute ¶
TurboQuant max NUM_KV_SPLITS for cuda graph decode. Fixes the split count so grid dimensions are constant across captures, and buffers can be pre-allocated to avoid inflating the memory estimate.
use_fp4_indexer_cache = None class-attribute instance-attribute ¶
Deprecated alias for indexer_kv_dtype; use that instead. True maps to mxfp4, False is a no-op (it selected the model default already).
use_non_causal = False class-attribute instance-attribute ¶
Whether to use non-causal (bidirectional) attention.
use_prefill_decode_attention = False class-attribute instance-attribute ¶
Use separate prefill and decode kernels for attention instead of the unified triton kernel.
use_prefill_query_quantization = False class-attribute instance-attribute ¶
If set, quantize query for attention in prefill.
use_trtllm_attention = None class-attribute instance-attribute ¶
If set to True/False, use or don't use the TRTLLM attention backend in flashinfer. If None, auto-detect the attention backend in flashinfer.
compute_hash() ¶
Provide a hash that uniquely identifies all the configs that affect the structure of the computation graph from input ids/embeddings to the final hidden states, excluding anything before input ids/embeddings and after the final hidden states.
Source code in vllm/config/attention.py
resolve_indexer_kv_dtype(default) ¶
Resolve indexer_kv_dtype, substituting default for "auto".
validate_backend_before(value) classmethod ¶
Enable parsing of the backend enum type from string.
The special value "auto" is treated as None, which triggers automatic backend selection.
Source code in vllm/config/attention.py
validate_backend_per_kind_before(value) classmethod ¶
Parse the backend_per_kind map from strings.
Keys must be valid KVCacheSpecKind values; values are parsed like backend (enum name, case-insensitive).
Source code in vllm/config/attention.py
validate_mla_prefill_backend_before(value) classmethod ¶
Enable parsing of the mla_prefill_backend enum type from string.