vllm.v1.attention.backends.rocm_aiter_fa
¶
Attention layer with AiterFlashAttention.
Classes:
-
AiterFlashAttentionBackend– -
AiterFlashAttentionExtendKernel–Warm the AITER varlen kernels that only an extend step reaches.
-
AiterFlashAttentionImpl– -
AiterFlashAttentionMetadataBuilder– -
AsmKvScaleTables–Dense per-slot scale tables the asm decode kernel reads for an fp8 cache.
AiterFlashAttentionBackend
¶
Bases: AttentionBackend
Methods:
-
customize_spec–Validate the block size the ROCm gather kernels require, and under
-
supports_attn_type–ENCODER_DECODER is not supported because the prefill path uses
customize_spec(spec)
classmethod
¶
Validate the block size the ROCm gather kernels require, and under the shuffle layout publish K and V as two head slots.
The shuffle read/write kernels rearrange a whole head_size x
block_size tile per side, so each side needs its own contiguous run
in the page. Packed into the content dim they interleave per token
instead, which no layout can undo.
supports_attn_type(attn_type)
classmethod
¶
ENCODER_DECODER is not supported because the prefill path uses flash_attn_varlen_func with cu_seqlens_k set to decoder query_start_loc (not encoder seq lens) and causal=True, both of which are incorrect for cross-attention layers.
AiterFlashAttentionExtendKernel
¶
Bases: VllmJitKernel['AiterFlashAttentionExtendKernel.CompileKey']
Warm the AITER varlen kernels that only an extend step reaches.
An extend is a prefill over cached tokens: a chunked-prefill continuation
or a prefix-cache hit. AiterFlashAttentionImpl.extend_forward attends the
new tokens causally and each gathered context chunk non-causally, both
returning the LSE so merge_attn_states can combine them. A new prompt
makes one causal call without the LSE, so it never selects these variants.
AITER builds a module per variant on first use, which otherwise stalls the
first request that needs one.
Sliding-window layers are skipped: their extend step runs the same windowed, LSE-free call as a new prompt.
AiterFlashAttentionImpl
¶
Bases: AttentionImpl
Methods:
-
forward–Forward pass with AiterFlashAttention.
forward(layer, query, key, value, kv_cache, attn_metadata, output, output_scale=None, output_block_scale=None)
¶
Forward pass with AiterFlashAttention.
Parameters:
-
(layer¶Module) –The attention layer, providing the q/k/v quantization scales.
-
(query¶Tensor) –shape = [num_tokens, num_heads, head_size]
-
(key¶Tensor | None) –shape = [num_tokens, num_kv_heads, head_size]
-
(value¶Tensor | None) –shape = [num_tokens, num_kv_heads, head_size]
-
(kv_cache¶Tensor) –shape = [num_blocks, 2, block_size, num_kv_heads, head_size]
-
(attn_metadata¶AiterFlashAttentionMetadata) –Metadata for attention.
-
(output¶Tensor) –Tensor that the attention result is written into.
-
(output_scale¶Tensor | None, default:None) –Scale for fused output quantization; not supported by this backend.
-
(output_block_scale¶Tensor | None, default:None) –Block scale for fused output quantization; not supported by this backend.
Returns:
-
Tensor–shape = [num_tokens, num_heads * head_size]
NOTE: FP8 quantization, flash-attn expect the size of {q,k,v}_descale to be (num_sequences, num_kv_heads). We use torch's .expand() to avoid duplicating values
AiterFlashAttentionMetadataBuilder
¶
Bases: AttentionMetadataBuilder[AiterFlashAttentionMetadata]
_build_swa_decode_tables(block_table, seq_lens, num_decodes, max_seq_len)
¶
Trim the decode block table to the sliding window.
Exact: the kernel's window mask drops the leading tokens of the first kept block, and RoPE is already applied in the cache.
AsmKvScaleTables
dataclass
¶
Dense per-slot scale tables the asm decode kernel reads for an fp8 cache.
One table per distinct (device, shape, scale), shared by every layer and every metadata builder in the process, so the target and draft models with equal scales reuse a single allocation. Tables are constants: never write to one in place; a per-token or dynamic scale needs its own buffer.
_uses_fast_verify(vllm_config, kv_cache_dtype)
¶
Whether a layer can use the decode kernels in
vllm.v1.attention.ops.rocm_gqa_verify: gfx950 and an FP8 e4m3 KV cache in the
default (unshuffled) layout. The layer still has to pass supports_layer.