nemo_automodel.components.models.mistral_large4.attention
nemo_automodel.components.models.mistral_large4.attention
Floating DSA/MLA baseline with explicit, differentiable per-forward KV sharing.
Module Contents
Classes
Functions
Data
API
Bases: Module
Direct-query MLA; KV consumers retain their source’s autograd graph.
Absorb KV-B into queries/outputs and gather compressed KV for sparse MLA.
Parameters:
Local [tokens, heads, head_dim] rotated/scaled queries.
Local [tokens, 512] normalized KV, possibly shared from another layer.
Local [tokens, 64] rotated keys, or [tokens, 0] for NoPE.
Integer [tokens, selected_keys] global KV indices with -1 padding.
Local/global document, position and validity metadata as documented by SequenceLayout. Global keys use CP-rank concatenation order.
Returns: torch.Tensor
Local [tokens, heads, value_dim] attention outputs. KV-B effective weights
Run selected sparse MLA or the expanded-KV SDPA reference (including LoRA).
Parameters:
Floating tensor [tokens, hidden].
FP32 cosine/sine pair, each [tokens, rotary_dim / 2].
Local positions/document IDs/validity [tokens], optional global CP key metadata.
Optional source latent [tokens, latent_dim] and rotated keys [tokens, rotary_dim], or [tokens, 0] for NoPE. Never detached.
Optional preceding full indexer’s int64 selected keys [tokens, min(topk, tokens)], with -1 padding.
Returns: torch.Tensor
Output [tokens, hidden], latent/rotary pair in shared_kv layouts,
Bases: Module
Frozen hard DSA selector; an indexer training objective has not been specified.
Select valid causal keys with stable ascending-key tie breaking.
Parameters:
Floating tensor [tokens, hidden].
FP32 cosine/sine pair, each [tokens, rotary_dim / 2].
Local positions/document IDs/validity [tokens], optional global CP key metadata.
Returns: torch.Tensor
Independent int64 indices [tokens, min(topk, tokens)], with -1 for
Local token metadata plus optional CP-global keys, all flattened in rank order.
Return an independent bool [query_tokens, key_tokens] causal document mask.
Run sparse MLA on local packed queries and gathered latent KV.
Parameters:
Contiguous CUDA BF16 [local_tokens, heads, 576] absorbed queries. The last 64 coordinates are rotary keys, or zeros in NoPE layers.
CUDA BF16 [global_tokens, 576] latent/rotary KV in CP-rank order.
Integer [local_tokens, selected_keys] global KV coordinates; -1 denotes invalid slots. Caller enforces document/causal boundaries.
BF16 [heads, value_dim, 512] differentiable KV-B value weight.
Original Mistral head-dimension attention scale.
Returns: torch.Tensor
BF16 [local_tokens, heads, value_dim]. Empty query rows are zero and