nemo_automodel.components.attention.utils
nemo_automodel.components.attention.utils
Module Contents
Functions
API
Initialize an attention backend module and callable.
Postprocess attention output based on attn_impl requirements.
Preprocess attention inputs based on backend requirements.
Parameters:
Query tensor of shape [batch, sequence, heads, head_dim] or [tokens, heads, head_dim] for THD input.
Key tensor of shape [batch, sequence, kv_heads, head_dim] or [tokens, kv_heads, head_dim] for THD input.
Value tensor with the same leading layout as k and an optional
distinct value head dimension.
Optional tensor of shape [batch, sequence] for padding or indexed packing, or [batch, 1, sequence, sequence] for an explicit dense mask. TE accepts only a binary [batch, sequence] padding mask (1/True for valid tokens, 0/False for padding). Packed TE inputs require None and THD sequence metadata instead.
Attention backend name.
Backend metadata. Packed FA4 accepts cu_seqlens of shape
[documents + 1] and packed_token_indices of shape [tokens].
For SDPA and FA4, a positive left window_size counts visible
keys including the current token; negative/None means unbounded.
The legacy TE branch forwards its backend-specific distances unchanged.
Packed TE accepts cu_seqlens of shape [documents + 1] and
optional cu_seqlens_padded with the same shape, both int32,
together with an integer max_seqlen.
Returns: torch.Tensor
Query, key, and value tensors in the backend layout plus its keyword
Raises:
ValueError: If the selected backend cannot consume the input layout.