Skip to content

vllm.v1.attention.backends.flash_attn_diffkv

Attention layer with FlashAttention.

Classes:

FlashAttentionDiffKVBackend

Bases: FlashAttentionBackend

Methods:

is_supported_on_current_device(head_size, head_size_v, has_sinks) classmethod

Check whether FA3/4 with this DiffKV config is usable here.

DiffKV (hdim_qk != hdim_v) requires FA3 or FA4

FlashAttentionDiffKVImpl

Bases: FlashAttentionImpl

Methods:

  • forward –

    Forward pass with FlashAttention.

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_v]

  • kv_cache

    (Tensor) –

    shape = [num_blocks, block_size, num_kv_heads, head_size + head_size_v]

  • attn_metadata

    (FlashAttentionMetadata) –

    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_v]

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