| 1 | # Attention Backend Feature Support |
| 2 | |
| 3 | The priority and feature tables on this page are auto-generated from the |
| 4 | attention backend registry by |
| 5 | `docs/mkdocs/gen_files/generate_attention_backends.py`, based on the checks in |
| 6 | `AttentionBackend.validate_configuration()`. |
| 7 | |
| 8 | ## Setting the Attention Backend |
| 9 | |
| 10 | ### Command Line |
| 11 | |
| 12 | There are two ways to specify the backend from the command line: |
| 13 | |
| 14 | **Option 1: Using `--attention-backend` (simple)** |
| 15 | |
| 16 | ```bash |
| 17 | vllm serve <model> --attention-backend FLASH_ATTN |
| 18 | ``` |
| 19 | |
| 20 | **Option 2: Using `--attention-config.backend` / `-ac.backend` (structured config)** |
| 21 | |
| 22 | ```bash |
| 23 | # Dot notation |
| 24 | vllm serve <model> --attention-config.backend FLASH_ATTN |
| 25 | vllm serve <model> -ac.backend FLASH_ATTN |
| 26 | |
| 27 | # JSON format |
| 28 | vllm serve <model> --attention-config '{"backend": "FLASH_ATTN"}' |
| 29 | vllm serve <model> -ac '{"backend": "FLASH_ATTN"}' |
| 30 | ``` |
| 31 | |
| 32 | > **Note:** `--attention-backend` and `--attention-config.backend` are mutually |
| 33 | > exclusive. Use one or the other, not both. |
| 34 | |
| 35 | ### Python API |
| 36 | |
| 37 | Use `AttentionConfig` with the `LLM` class: |
| 38 | |
| 39 | ```python |
| 40 | from vllm import LLM |
| 41 | from vllm.config import AttentionConfig |
| 42 | from vllm.v1.attention.backends.registry import AttentionBackendEnum |
| 43 | |
| 44 | # Method 1: Using AttentionConfig with enum |
| 45 | llm = LLM( |
| 46 | model="Qwen/Qwen3-0.6B", |
| 47 | attention_config=AttentionConfig(backend=AttentionBackendEnum.FLASH_ATTN), |
| 48 | ) |
| 49 | |
| 50 | # Method 2: Using attention_backend parameter with string |
| 51 | llm = LLM( |
| 52 | model="Qwen/Qwen3-0.6B", |
| 53 | attention_backend="FLASH_ATTN", |
| 54 | ) |
| 55 | ``` |
| 56 | |
| 57 | ## Backend Selection Behavior |
| 58 | |
| 59 | ### Triton/FlashAttention Composite |
| 60 | |
| 61 | On Hopper, `TRITON_FLASH_ATTN` is preferred for compatible multimodal-prefix |
| 62 | configurations. It uses Triton when the current queries need bidirectional |
| 63 | image attention and FlashAttention for causal text prefills and decode, with a |
| 64 | shared KV cache. The causal child must resolve to FA4. This happens |
| 65 | automatically for FA4-only shapes such as head size 512 and models whose |
| 66 | version policy promotes all layers to FA4, including Gemma 4. A standalone |
| 67 | head-size-256 configuration whose version policy selects FA3 falls back to |
| 68 | Triton for the whole layer. |
| 69 | |
| 70 | No attention override is needed for supported multimodal models: |
| 71 | |
| 72 | ```bash |
| 73 | vllm serve google/gemma-4-31B-it |
| 74 | ``` |
| 75 | |
| 76 | ### Triton/FlashInfer Composite |
| 77 | |
| 78 | On Blackwell, `TRITON_FLASHINFER` is preferred for compatible |
| 79 | multimodal-prefix configurations, including Gemma 4 with BF16 or FP8 KV cache. It uses |
| 80 | Triton when a batch's current queries require bidirectional image attention, |
| 81 | and FlashInfer for causal text prefills and decode. Historical image tokens |
| 82 | alone do not select Triton. |
| 83 | |
| 84 | This instantiates `create_composite_attention_backend` from |
| 85 | `vllm/v1/attention/backends/composite.py` with Triton, |
| 86 | FlashInfer, and `MMPrefixAttentionRouting`. The reusable factory owns child |
| 87 | implementations, metadata dispatch, compatible cache requirements, and workspace |
| 88 | sharing. The routing policy selects the child and defines graph-capture safety. |
| 89 | Other combinations can reuse the same machinery. |
| 90 | |
| 91 | The backend supports head dimensions 256/512, FP16/BF16 and FP8 KV cache, |
| 92 | and 64-token kernel pages with a head-major cache layout. TRTLLM handles causal |
| 93 | attention at both head dimensions; its hdim512 kernels do not support 128-token |
| 94 | pages. |
| 95 | For Gemma 4, full CUDA graphs cover single-token batches; multi-token batches |
| 96 | use the non-full-graph execution path. Models whose image masks extend beyond |
| 97 | the sliding window cannot use full attention graphs with this composite. |
| 98 | Context parallelism, R-SWA, attention sinks, |
| 99 | and adaptive verification are not supported by this composite. |
| 100 | |
| 101 | It can also be selected explicitly: |
| 102 | |
| 103 | ```bash |
| 104 | vllm serve google/gemma-4-31B-it \ |
| 105 | --attention-backend TRITON_FLASHINFER |
| 106 | ``` |
| 107 | |
| 108 | ### Manual Selection |
| 109 | |
| 110 | When you explicitly set a backend via `--attention-backend` or `AttentionConfig`: |
| 111 | |
| 112 | 1. The backend is **validated** against your configuration (model dtype, head |
| 113 | size, compute capability, etc.) |
| 114 | 2. If the backend **doesn't support** your configuration, an error is raised |
| 115 | with the specific reason |
| 116 | 3. If valid, the backend is used |
| 117 | |
| 118 | Example error when selecting an incompatible backend: |
| 119 | |
| 120 | ```text |
| 121 | ValueError: Selected backend FLASHMLA is not valid for this configuration. |
| 122 | Reason: ['compute capability not supported'] |
| 123 | ``` |
| 124 | |
| 125 | ### Automatic Selection |
| 126 | |
| 127 | When no backend is specified (the default): |
| 128 | |
| 129 | 1. vLLM iterates through backends in **priority order** (see tables below) |
| 130 | 2. Each backend is validated against your configuration |
| 131 | 3. The **first compatible backend** is selected |
| 132 | 4. If no backend is compatible, an error is raised listing all backends and |
| 133 | their incompatibility reasons |
| 134 | |
| 135 | ## Backend Priority (CUDA) |
| 136 | |
| 137 | When no backend is explicitly selected, vLLM chooses the first |
| 138 | compatible backend from these priority-ordered lists. |
| 139 | |
| 140 | Priority is **1 = highest** (tried first). |
| 141 | |
| 142 | ### Standard Attention (MHA, MQA, GQA) |
| 143 | |
| 144 | --8<-- "gen:priority-standard" |
| 145 | |
| 146 | ### MLA Attention (DeepSeek-style) |
| 147 | |
| 148 | --8<-- "gen:priority-mla" |
| 149 | |
| 150 | > **\*** For sparse MLA, FP8 KV cache always prefers `FLASHINFER_MLA_SPARSE`. With BF16 KV cache, `FLASHINFER_MLA_SPARSE` is preferred for low query-head counts (<= 16), while `FLASHMLA_SPARSE` is preferred otherwise. |
| 151 | > |
| 152 | > **Note:** ROCm and CPU platforms have their own selection logic. See the platform-specific documentation for details. |
| 153 | |
| 154 | ## Legend |
| 155 | |
| 156 | | Column | Description | |
| 157 | | ------ | ----------- | |
| 158 | | **Dtypes** | Supported model data types (fp16, bf16, fp32) | |
| 159 | | **KV Dtypes** | Supported KV cache data types (`auto`, `fp8`, `fp8_e4m3`, etc.) | |
| 160 | | **Block Sizes** | Supported KV cache block sizes (%N means multiples of N) | |
| 161 | | **Head Sizes** | Supported attention head sizes | |
| 162 | | **Sink** | Attention sink support (for StreamingLLM) | |
| 163 | | **Non-Causal** | Non-causal (bidirectional) attention support for decoder models | |
| 164 | | **Sparse** | Sparse attention support (MLA only) | |
| 165 | | **MM Prefix** | Multimodal prefix full attention support | |
| 166 | | **DCP** | Decode Context Parallelism support (`--decode-context-parallel-size`) | |
| 167 | | **Attention Types** | Supported attention patterns (Decoder, Encoder, Enc-Dec) | |
| 168 | | **Compute Cap.** | Required CUDA compute capability (N/A for non-CUDA backends) | |
| 169 | |
| 170 | **Symbols:** ✅ = Supported, ❌ = Not supported |
| 171 | |
| 172 | ## Standard Attention (MHA, MQA, GQA) Backends |
| 173 | |
| 174 | --8<-- "gen:table-standard" |
| 175 | |
| 176 | > **†** FlashInfer Native is the regular FlashInfer path. XQA is the SM90 decode path exposed through FlashInfer's TRTLLM decode API. trtllm-gen is used on SM100 and supports sinks. Disable XQA/trtllm-gen via `--attention-config.use_trtllm_attention=0`. |
| 177 | > |
| 178 | > **\*** Specify the FlashAttention version via `--attention-config.flash_attn_version=2`, `3`, or `4`. Default is FA4 on SM100+ (Blackwell), FA3 on SM90 (Hopper), FA2 otherwise. |
| 179 | > |
| 180 | > On Blackwell, when the FlashAttention backend is selected, `head_size=256` is served |
| 181 | > by a dedicated FA4 kernel that requires a KV cache block size of 128 (advertised |
| 182 | > automatically, so it is picked as long as `--block-size` is not pinned) and does not |
| 183 | > support logit soft capping, attention sinks, mm_prefix/R-SWA masking, DCP, or windowed |
| 184 | > encoder attention. Those configurations transparently fall back to FA2. A pinned |
| 185 | > `--block-size` that is not a multiple of 128 instead makes FlashAttention ineligible |
| 186 | > for such models, which is an error if the backend was requested explicitly. |
| 187 | |
| 188 | ### b12x |
| 189 | |
| 190 | The optional [b12x](https://pypi.org/project/b12x/) backend supports causal |
| 191 | decoder attention on NVIDIA SM120 and SM121 GPUs. Install and select it with: |
| 192 | |
| 193 | ```bash |
| 194 | uv pip install "vllm[b12x]" |
| 195 | vllm serve <model> --attention-backend b12x |
| 196 | ``` |
| 197 | |
| 198 | ## MiniMax M3 Sparse Attention Backends |
| 199 | |
| 200 | Block-sparse GQA backend used by MiniMax M3 sparse ("lightning indexer") |
| 201 | layers. It is wired in directly by the model and is not part of the |
| 202 | automatic priority lists above. A lightning indexer scores KV blocks, the |
| 203 | top-k blocks (plus fixed init/local blocks) are selected, and attention |
| 204 | attends only to those blocks; index keys live in a separate side cache. |
| 205 | |
| 206 | --8<-- "gen:table-minimax" |
| 207 | |
| 208 | ## MLA (Multi-head Latent Attention) Backends |
| 209 | |
| 210 | MLA uses separate backends for prefill and decode phases. |
| 211 | |
| 212 | ### Prefill Backends |
| 213 | |
| 214 | To explicitly select a prefill backend, use |
| 215 | `-ac.mla_prefill_backend=<BACKEND>` (e.g., `FLASH_ATTN`, `FLASHINFER`). |
| 216 | Otherwise, the prefill backend is selected automatically at runtime based on |
| 217 | hardware and configuration. |
| 218 | |
| 219 | --8<-- "gen:table-mla-prefill" |
| 220 | |
| 221 | > **‡** Automatic selection tries FlashAttention first. On Blackwell |
| 222 | > (SM100), the fallback order is TRT-LLM Ragged, FlashInfer, then |
| 223 | > TokenSpeed MLA; for (qk_nope_head_dim=192, qk_rope_head_dim=64, |
| 224 | > v_head_dim=256) TRT-LLM Ragged is tried before FlashAttention. On other |
| 225 | > GPUs, only FlashAttention is considered. |
| 226 | |
| 227 | ### Decode Backends |
| 228 | |
| 229 | MLA decode backends are selected using the standard |
| 230 | `-ac.backend=<BACKEND>` argument (e.g., `FLASHMLA`, `TRITON_MLA`). |
| 231 | |
| 232 | --8<-- "gen:table-mla-decode" |
| 233 | |
| 234 | ### DeepSeek V4 Decode Backends |
| 235 | |
| 236 | DeepSeek V4 sparse MLA uses its own decode backends, selected via |
| 237 | `--attention-backend=<BACKEND>` (e.g., `FLASHMLA_SPARSE_DSV4`, |
| 238 | `FLASHINFER_MLA_SPARSE_DSV4`). They share the V4 sparse-index |
| 239 | pipeline (compressor + SWA + indexer, 256-token blocks, head 512); |
| 240 | default on NVIDIA is `FLASHINFER_MLA_SPARSE_DSV4` on SM12x and |
| 241 | `FLASHMLA_SPARSE_DSV4` on other supported CUDA architectures. |
| 242 | |
| 243 | --8<-- "gen:table-mla-v4-decode" |