Skip to content

vllm.config.attention

Classes:

AttentionConfig

Configuration for attention mechanisms in vLLM.

Methods:

Attributes:

backend = None class-attribute instance-attribute

Attention backend to use. Use "auto" or None for automatic selection. TORCH_SDPA is reserved for multi-modal encoder attention.

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 multiple of 16 and divisible by flex_attn_block_n. If None, uses the KV cache block size for paged KV attention and 128 for encoder-only attention.

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 and 128 for encoder-only attention.

hisparse_config = None class-attribute instance-attribute

HiSparse host-resident KV configuration. Setting this enables experimental Model Runner V2-only HiSparse DSA and QSA decode hot-buffering. It is inferred with defaults when HiSparseConnector is configured (directly or via MultiConnector); set it explicitly only to tune its fields.

indexer_decode_cp = False class-attribute instance-attribute

Split the sparse-attention indexer's decode scoring across the tensor-parallel ranks by context instead of by index head: each rank scores a 1/TP slice of the index-K pages for every head and the ranks exchange their local top-k, so each reads 1/TP of the index-K cache per sparse layer. The index-K cache stays replicated, so this is unrelated to --decode-context-parallel-size, which shards the KV cache itself; the two cannot be combined. Implemented for the MiniMax M3 NVFP4 indexer, which needs indexer_kv_dtype="nvfp4" and TP 4 (one index head per rank); it is ignored with a warning where it does not apply. It pays off from about 4 concurrent decodes at 128K context and grows with batch and context.

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, mxfp4 for DeepSeek-V4 on ROCm CDNA4 with aiter). Quantized formats (fp8, mxfp4, nvfp4) require indexer kernel support in the backend; MiniMax M3 supports nvfp4 on SM100/SM103/SM107 with at most 8 decode queries per request.

indexer_logits_dtype = 'auto' class-attribute instance-attribute

Output dtype of DeepGEMM's dense MQA-logits kernels in the DeepSeek sparse-attention indexer, also used by Kimi K3. "auto" (default) picks the model's default: "bfloat16" for DeepSeek-V3.2 and DeepSeek-V4 on SM100, "float32" otherwise (Kimi K3 included). "float32" reduces the head-weighted scores in FP32 and feeds them to the top-k as is. "bfloat16" halves the logits memory; on SM100 it also reduces in BF16 with BF16 head weights and lets the top-k kernels that take BF16 rank the logits directly (DeepSelect; in decode also the cooperative and persistent kernels), while the others read an FP32 copy. The sparse MQA-logits path (indexer_sparse_logits) emits BF16 on SM100 and FP32 on SM90 and ROCm, independently of this setting.

indexer_sparse_logits = None class-attribute instance-attribute

Score only candidate blocks in the DeepSeek V4.1 two-level indexer. None (default) enables it on SM90 and supported SM100 configurations; True forces it; False uses dense scoring. Requires no context parallelism. SM90 uses CuTe DSL with FP8 cache and dense fallback for short prefills. Unsupported cache, model geometry or microbatching raises at initialization, including with the default None. SM100 requires DeepGEMM >= 2.8 and DeepSelect (FP8/MXFP4 cache). ROCm gfx950 uses aiter with MXFP4 cache and remains opt-in.

minimax_m3_indexer_cp = False class-attribute instance-attribute

MiniMax M3 on ROCm with tensor_parallel_size > 1: score the sparse indexer context-parallel at decode. Each rank reads 1/TP of the index cache, scores every index head on it, and per-head top-k candidates are exchanged and merged, so the selected blocks match the default path. indexer_kv_dtype picks the kernels that do it: a bf16 index cache ("auto" or "bf16") runs the Triton CP indexer, an fp8 e4m3 one the AITER MSA CP indexer on gfx950. This shards indexer work and not the KV cache, so it is not decode_context_parallel_size and requires that to be 1.

minimax_m3_msa_decode_backend = 'cutlass' class-attribute instance-attribute

Sparse decode kernel used by the MiniMax M3 MSA backend. "cutlass" falls back to Triton where the CUTLASS kernel does not support the platform, KV cache dtype, or head layout.

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; on ROCm, ROCM_AITER_FA and ROCM_AITER_FLYDSL_FP8. ROCM_AITER_FLYDSL_FP8 is opt-in (gfx950, bf16 models): it quantizes Q/K/V to FP8 per tensor at runtime and falls back to ROCM_AITER_FA for inputs the FlyDSL kernel cannot take.

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.

sparse_mla_prefill_workspace_factor = Field(default=None, ge=2) class-attribute instance-attribute

Sparse MLA prefill workspace size, in multiples of max_model_len. FlashMLA sparse gathers a prefill step's context KV into this workspace and runs attention in more chunks when the step holds more. The sparse indexer's prefill K buffer is sized to fit in the same memory. Lower values return memory to the KV cache at long max_model_len; the minimum of 2 leaves room for a full-length request's context-parallel shard. If None, 5 when max_model_len is at most 256K tokens, else 2.

sparse_mla_shard_q = True class-attribute instance-attribute

Under tensor parallelism, shard sparse-MLA (DSA) prefill by token instead of by head: each TP rank runs the indexer and the sparse attention for its slice of the tokens with all heads, and all-to-all exchanges move the query and the attention output between the layouts. Applies to steps with at least sparse_mla_shard_q_min_tokens prefill tokens on the FlashInfer sparse MLA backend, or on FlashMLA sparse with an FP8 DeepSeek KV cache, without PCP or HiSparse. Under DCP (on FlashInfer and SM100, with the DCP group equal to the TP group), each rank attends a gathered copy of its tokens' context instead of the DCP-local cache. A mixed step's decode tokens stay sharded by head (on the DCP path under DCP). On ROCm, models that opt in (currently HY4) shard on ROCM_AITER_MLA_SPARSE with an fp8_ds_mla KV cache or VLLM_ROCM_USE_AITER_TRITON_SPARSE_MLA=1, and only with fewer than 16 local heads (e.g. HY4 at TP8). DeepSeek-V4.1 on ROCm shards only its indexer prefill this way and all-gathers the top-k back, with its attention sharded by head.

sparse_mla_shard_q_min_tokens = Field(default=1024, ge=1) class-attribute instance-attribute

Minimum number of tokens after a step's decodes (requests of at most 1 + num_speculative_tokens tokens) for sparse_mla_shard_q to apply. Below it the all-to-all exchanges can cost more than they save.

tokenspeed_mla_min_split_kv = Field(default=1, ge=1, le=256) class-attribute instance-attribute

Minimum KV splits for TokenSpeed MLA decode. The default of 1 preserves automatic scheduling. Larger values request a split floor and may increase workspace memory. Only applies to the TokenSpeed MLA backend.

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.

trtllm_ragged_backend = 'trtllm-gen' class-attribute instance-attribute

Kernel backend for cached-context TRTLLM_RAGGED MLA prefill. CuTe DSL requires FP8 queries for head dimension 192 and does not support head dimension 256. New-token prefill always uses TRTLLM.

use_non_causal = False class-attribute instance-attribute

Whether to use non-causal (bidirectional) attention.

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.

compile_factors()

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.

resolve_indexer_kv_dtype(default)

Resolve indexer_kv_dtype, substituting default for "auto".

resolve_indexer_logits_dtype(default)

Resolve indexer_logits_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.

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).

validate_mla_prefill_backend_before(value) classmethod

Enable parsing of the mla_prefill_backend enum type from string.

HiSparseConfig

Configuration for HiSparse DSA and QSA KV offloading.

Attributes:

device_buffer_size = Field(default=None, gt=0) class-attribute instance-attribute

Total per-request GPU hot-buffer rows, including the newest-token slot.

Defaults to one top-k per decode query plus one top-k of LRU slack. The physical allocation is rounded up to the GPU cache block size selected from the active backends.

eager_host_mirror = True class-attribute instance-attribute

Mirror decode-written KV rows to the host pool during the forward so page spills complete without moving data. When disabled, decode rows stay resident-only and evicted pages are copied to host at spill time. Prefill rows are always mirrored during the forward.