vllm.v1.attention.backends.rocm_attn
¶
Attention layer with PagedAttention and Triton prefix prefill.
Classes:
RocmAttentionBackend
¶
Bases: AttentionBackend
Methods:
-
customize_spec–K and V as two head groups so the native HIP kernels address each side
-
supports_attn_type–ENCODER_DECODER is not supported because
customize_spec(spec)
classmethod
¶
K and V as two head groups so the native HIP kernels address each side as one contiguous region (x-packed interior applied in split_kv_cache).
supports_attn_type(attn_type)
classmethod
¶
ENCODER_DECODER is not supported because chunked_prefill_paged_decode's prefill kernel (context_attention_fwd) assumes self-attention semantics: it treats passed K/V as new tokens to mix with cached K/V. For cross-attention layers the encoder K/V are already fully cached, so mixing them again produces incorrect results when max_query_len > 1 (e.g. beam search).
RocmAttentionImpl
¶
Bases: AttentionImpl
Methods:
-
forward–Forward pass with FlashAttention.
_forward_encoder_attention(query, key, value, output, attn_metadata, layer)
¶
Forward pass for encoder attention without KV cache.
Parameters:
-
(query¶Tensor) –shape = [num_encoder_tokens, num_heads, head_size]
-
(key¶Tensor) –shape = [num_encoder_tokens, num_kv_heads, head_size]
-
(value¶Tensor) –shape = [num_encoder_tokens, num_kv_heads, head_size]
-
(output¶Tensor) –shape = [num_encoder_tokens, num_heads, head_size]
-
(attn_metadata¶RocmAttentionMetadata) –Encoder attention metadata
-
(layer¶Module) –The attention layer
forward(layer, query, key, value, kv_cache, attn_metadata, output, output_scale=None, output_block_scale=None)
¶
Forward pass with FlashAttention.
Parameters:
-
(layer¶Module) –The attention layer, providing the q/k/v quantization scales.
-
(query¶Tensor) –shape = [num_tokens, num_heads, head_size]
-
(key¶Tensor) –shape = [num_tokens, num_kv_heads, head_size]
-
(value¶Tensor) –shape = [num_tokens, num_kv_heads, head_size]
-
(kv_cache¶Tensor) –logical [num_blocks, 2, block_size, num_kv_heads * head_size] under LHBNC (physically K/V-group-first)
-
(attn_metadata¶RocmAttentionMetadata) –Metadata for attention.
-
(output¶Tensor) –Tensor that the attention result is written into.
-
(output_scale¶Tensor | None, default:None) –Scale for fused output quantization.
-
(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]