Skip to content

vllm_omni.diffusion.attention.backends.abstract

T module-attribute

T = TypeVar('T', bound=AttentionMetadata)

AttentionBackend

Bases: ABC

Abstract class for diffusion attention backends.

accept_output_buffer class-attribute instance-attribute

accept_output_buffer: bool = False

supported_platforms class-attribute instance-attribute

supported_platforms: tuple[str, ...] | None = None

supports_paged_kv class-attribute instance-attribute

supports_paged_kv: bool = False

supports_piecewise_spans class-attribute instance-attribute

supports_piecewise_spans: bool = False

supports_prefix_kv_slicing class-attribute instance-attribute

supports_prefix_kv_slicing: bool = False

get_builder_cls abstractmethod staticmethod

get_builder_cls()

get_impl_cls abstractmethod staticmethod

get_impl_cls() -> type[AttentionImpl]

get_metadata_cls abstractmethod staticmethod

get_metadata_cls() -> type[AttentionMetadata]

get_name abstractmethod staticmethod

get_name() -> str

get_supported_head_sizes abstractmethod staticmethod

get_supported_head_sizes() -> list[int]

Get the list of supported head sizes for this backend.

indexes_kv_by_block_stride classmethod

indexes_kv_by_block_stride() -> bool

Whether this backend reads K/V pages by the runtime block stride.

Returning True means the physical cache layout has num_blocks as its outer stride, so native vLLM may safely use page-size padding when it unifies cache layouts across layers. Dense diffusion backends conservatively keep the default False; a paged backend should override this only when its kernel actually follows that layout.

Since vLLM 0.29 this no longer rides on AttentionSpec. It selects the block-outermost physical layout pinned on CacheConfig.kv_cache_layout -- see vllm_omni.diffusion.diffusion_kv.layout -- whose is_block_outermost is what upstream reads when it sizes KVCacheTensor regions.

supports_attention_mask classmethod

supports_attention_mask(
    attention_spec: object | None = None,
) -> bool

Return whether this backend can consume a nontrivial attn_mask.

attention_spec is the resolved per-role config when the user picked a backend explicitly. Implementations that depend on kernel variant (for example FlashInfer cute-dsl vs fa2) must consult it so capability probes match a runnable configuration.

supports_head_size classmethod

supports_head_size(head_size: int) -> bool

supports_multi_doc_packed_varlen classmethod

supports_multi_doc_packed_varlen() -> bool

Whether this backend keeps N-document packed boundaries isolated.

When True, the backend consumes AttentionMetadata.extra cu_seqlens as a genuine block-diagonal attention plan (a dedicated varlen kernel, not a padding-mask rebuild), so a caller may pack multiple real requests into one forward without attention crossing document boundaries. When False, callers packing more than one real document must run one forward per document; otherwise a backend that only supports a [real, pad] two-document contract, or that ignores cu_seqlens outright, will silently attend across request boundaries. Backends whose kernel selection is platform-dependent must consult current_omni_platform.

supports_packed_mask_free classmethod

supports_packed_mask_free() -> bool

Whether [real, pad] packed layouts can run without attn_mask.

When True, models that pack a [real, pad] two-document layout and provide AttentionMetadata.packed_padding alongside the packed cu_seqlens/max_seqlen metadata may skip constructing the padding mask entirely. Backends whose mask-free behavior is platform-dependent must check current_omni_platform.

validate_available classmethod

validate_available() -> None

Raise if this backend's optional dependencies are missing.

Called during platform resolution, i.e. before model construction, so a backend that probes its kernel package lazily still reports the problem while the user can still act on it.

AttentionImpl

Bases: ABC, Generic[T]

forward

forward(
    query: Tensor,
    key: Tensor,
    value: Tensor,
    attn_metadata: T | None = None,
) -> Tensor

Dispatch to platform-specific forward implementation.

forward_cuda

forward_cuda(
    query: Tensor,
    key: Tensor,
    value: Tensor,
    attn_metadata: T | None = None,
) -> Tensor

forward_hip

forward_hip(
    query: Tensor,
    key: Tensor,
    value: Tensor,
    attn_metadata: T | None = None,
) -> Tensor

forward_musa

forward_musa(
    query: Tensor,
    key: Tensor,
    value: Tensor,
    attn_metadata: T | None = None,
) -> Tensor

forward_npu

forward_npu(
    query: Tensor,
    key: Tensor,
    value: Tensor,
    attn_metadata: T | None = None,
) -> Tensor

forward_paged

forward_paged(paged_kv_context: Any) -> Tensor

Execute one Worker-prepared paged-KV attention call.

The context is intentionally opaque to the common attention layer. Backends opt in by setting supports_paged_kv on their backend class and implementing this method. Dense callers continue to use forward unchanged.

forward_xpu

forward_xpu(
    query: Tensor,
    key: Tensor,
    value: Tensor,
    attn_metadata: T | None = None,
) -> Tensor

supports_kv_cache_dtype classmethod

supports_kv_cache_dtype(
    kv_cache_dtype: str | None, platform_key: str
) -> bool

AttentionMetadata dataclass

attn_mask class-attribute instance-attribute

attn_mask: Tensor | None = None

extra class-attribute instance-attribute

extra: dict[str, Any] = field(default_factory=dict)

full_attn_spans class-attribute instance-attribute

full_attn_spans: list[list[tuple[int, int]]] | None = None

joint_attn_mask class-attribute instance-attribute

joint_attn_mask: Tensor | None = None

joint_key class-attribute instance-attribute

joint_key: Tensor | None = None

joint_query class-attribute instance-attribute

joint_query: Tensor | None = None

joint_strategy class-attribute instance-attribute

joint_strategy: str = 'front'

joint_value class-attribute instance-attribute

joint_value: Tensor | None = None

packed_padding class-attribute instance-attribute

packed_padding: PackedPaddingMetadata | None = None

query_ranges class-attribute instance-attribute

query_ranges: tuple[QueryRange, ...] | None = None

video_layout class-attribute instance-attribute

video_layout: VideoTokenLayout | None = None

PackedPaddingMetadata dataclass

Producer-validated mask-free view of padding in a [real, pad] packing.

The cumulative-length tensors are canonical two-element [0, length] views. Consumers may use them without reading device scalars because the producer owns the packing.

cu_seqlens_k instance-attribute

cu_seqlens_k: Tensor

cu_seqlens_q instance-attribute

cu_seqlens_q: Tensor

kv_length instance-attribute

kv_length: int

q_length instance-attribute

q_length: int

QueryRange dataclass

global_start instance-attribute

global_start: int

local_end instance-attribute

local_end: int

local_start instance-attribute

local_start: int

VideoTokenLayout dataclass

Video-grid slices in a packed multimodal sequence.

A model that packs its sequence as [prefix | t*h*w video rows | padding] publishes this so backends can recover spatiotemporal locality; the prefix holds everything that is not video (text, visual conditions, audio). Publishing it also asserts that any attn_mask masks only the trailing padding, so prefix_len + t*h*w is the used length of the sequence.

prefix_len/latent_grid retain the original one-tail contract. A Ref2VA layout instead publishes used_len and every physical video span, so audio and image rows between videos remain dense.

Plain ints, so reading it never forces a device-to-host sync.

latent_grid class-attribute instance-attribute

latent_grid: tuple[int, int, int] | None = None

prefix_len class-attribute instance-attribute

prefix_len: int | None = None

used_len class-attribute instance-attribute

used_len: int | None = None

video_spans class-attribute instance-attribute

video_spans: tuple[VideoTokenSpan, ...] = ()

VideoTokenSpan dataclass

One physical video-grid slice in packed document 0.

latent_grid instance-attribute

latent_grid: tuple[int, int, int]

length property

length: int

role instance-attribute

role: Literal['reference', 'target']

start instance-attribute

start: int