Skip to content

vllm.model_executor.layers.lightning_attn

Functions:

_linear_attn_decode_kernel(q_ptr, k_ptr, v_ptr, kv_cache_ptr, slope_rate, slot_idx, output_ptr, D, qkv_b_stride, qkv_h_stride, cache_b_stride, cache_h_stride, cache_d0_stride, cache_d1_stride, pad_slot_id, BLOCK_SIZE)

Kernel for linear attention decoding with KV cache.

This kernel computes attention for a single token using the KV cache.

lightning_attention(q, k, v, ed, block_size=256, kv_history=None)

Apply lightning attention algorithm to compute attention efficiently.

Parameters:

  • q

    (Tensor) –

    Query tensor of shape [batch, heads, seq_len, dim]

  • k

    (Tensor) –

    Key tensor of shape [batch, heads, seq_len, dim]

  • v

    (Tensor) –

    Value tensor of shape [batch, heads, seq_len, dim_v]

  • ed

    (Tensor) –

    Decay rate tensor of shape [heads]

  • block_size

    (int, default: 256 ) –

    Size of blocks for block-sparse attention

  • kv_history

    (Tensor | None, default: None ) –

    Optional key-value history from previous computations

Returns:

  • output ( Tensor ) –

    Attention output

  • kv ( Tensor ) –

    Updated key-value history

linear_decode_forward_triton(q, k, v, kv_caches, slope_rate, slot_idx, BLOCK_SIZE=32)

Perform linear attention decoding using Triton kernels.

Parameters:

  • q

    (Tensor) –

    Query tensor of shape [B, H, 1, D]

  • k

    (Tensor) –

    Key tensor of shape [B, H, 1, D]

  • v

    (Tensor) –

    Value tensor of shape [B, H, 1, D]

  • kv_caches

    (Tensor) –

    Key-value cache tensor

  • slope_rate

    (Tensor) –

    Decay rate tensor

  • slot_idx

    (Tensor) –

    Slot indices for batches

  • BLOCK_SIZE

    (int, default: 32 ) –

    Size of blocks for processing

Returns:

  • output ( Tensor ) –

    Attention output tensor