nemo_automodel.components.models.laguna.model
nemo_automodel.components.models.laguna.model
Module Contents
Classes
Functions
Data
API
Bases: Module
Laguna attention: explicit per-layer heads, QK RMSNorm, and output gating.
Run Laguna attention for one decoder layer.
Parameters:
Tensor of shape [batch, sequence, hidden].
Tuple of cosine and sine RoPE tensors, each of shape [batch, sequence, rotary_dim].
Optional additive mask broadcastable to [batch, heads, sequence, key_sequence].
Additional attention backend arguments.
Returns: torch.Tensor
Tuple of attention output [batch, sequence, hidden] and optional attention weights
Bases: Module
Decoder block that uses dense MLP for configured layers and MoE otherwise.
Run a decoder block.
Parameters:
Tensor of shape [batch, sequence, hidden].
Optional additive attention mask broadcastable to [batch, heads, sequence, key_sequence].
Tuple of cosine and sine RoPE tensors, each of shape [batch, sequence, rotary_dim].
Optional bool tensor of shape [batch, sequence], where True marks padding.
Additional attention backend arguments.
Returns: torch.Tensor
Tensor of shape [batch, sequence, hidden].
Bases: HFCheckpointingMixin, Module, MoEFSDPSyncMixin
Causal LM wrapper for Laguna with Automodel checkpoint adapters.
Run the Laguna causal language model.
Parameters:
Optional token IDs of shape [batch, sequence].
Optional embeddings of shape [batch, sequence, hidden].
Optional position IDs of shape [batch, sequence].
Optional 2D bool/int mask of shape [batch, sequence], a 4D additive mask, or a mapping with per-attention-type masks keyed by “full_attention” and “sliding_attention”.
Optional bool tensor of shape [batch, sequence], where True marks tokens excluded from MoE routing.
Unsupported KV-cache state.
Unsupported cache flag.
If 0, compute logits for all sequence positions. If an int or tensor, compute logits only for the selected trailing positions.
When true, include final hidden states in the output.
Additional attention backend arguments.
Returns: CausalLMOutputWithPast
Causal LM output with logits and optional hidden states.
Bases: Module
Backbone model for Laguna SFT.
Build additive attention masks for full and sliding Laguna layers.
Parameters:
Input embedding tensor of shape [batch, sequence, hidden].
Optional sequence mask of shape [batch, sequence], 4D bool/additive mask, or mapping with masks keyed by “full_attention” and “sliding_attention”.
Position tensor of shape [batch, sequence].
Returns: dict[str, torch.Tensor]
Mapping from attention type to additive masks of shape
Run the Laguna decoder stack.
Parameters:
Optional token IDs of shape [batch, sequence].
Optional embeddings of shape [batch, sequence, hidden].
Optional position IDs of shape [batch, sequence].
Optional 2D bool/int mask of shape [batch, sequence], a 4D additive mask, or a mapping with per-attention-type masks keyed by “full_attention” and “sliding_attention”.
Optional bool tensor of shape [batch, sequence], where True marks tokens excluded from MoE routing.
Additional attention backend arguments.
Returns: torch.Tensor
Final hidden states of shape [batch, sequence, hidden].
Bases: Module
RMSNorm with fp32 variance, matching the Laguna reference implementation.
Apply RMS normalization while computing variance in fp32.
Parameters:
Tensor of shape […, hidden].
Returns: torch.Tensor
Tensor of shape […, hidden].
Bases: Module
Rotary embedding with Laguna’s nested full-attention/SWA RoPE support.
Compute RoPE cosine and sine tables.
Parameters:
Activation tensor of shape [batch, sequence, hidden], used for device and dtype.
Position tensor of shape [batch, sequence].
Returns: tuple[torch.Tensor, torch.Tensor]
Tuple of cosine and sine tensors, each of shape [batch, sequence, rotary_dim].
Apply RoPE to query and key states.
Parameters:
Query tensor of shape [batch, heads, sequence, head_dim].
Key tensor of shape [batch, key_value_heads, sequence, head_dim].
Cosine tensor of shape [batch, sequence, rotary_dim].
Sine tensor of shape [batch, sequence, rotary_dim].
Returns: tuple[torch.Tensor, torch.Tensor]
Tuple of rotated query and key tensors with the same shapes as q and k.
Convert a bool 4D attention mask to additive attention-mask layout.
Parameters:
Tensor of shape [batch, heads_or_one, sequence, key_sequence]. Bool masks use True for visible entries; non-bool masks are already additive.
Floating-point dtype for the additive mask.
Returns: torch.Tensor
Additive mask tensor with the same shape, or the original non-bool mask.
Derive an MoE padding mask from a sequence or attention mask.
Parameters:
Tensor of shape [batch, sequence] with nonzero valid tokens, or [batch, heads_or_one, sequence, key_sequence] in bool or additive mask layout.
Returns: torch.Tensor
Bool tensor of shape [batch, sequence], where True marks padding.
Run eager attention over projected query/key/value states.
Parameters:
Attention module carrying head-repeat metadata.
Query tensor of shape [batch, heads, sequence, head_dim].
Key tensor of shape [batch, key_value_heads, key_sequence, head_dim].
Value tensor of shape [batch, key_value_heads, key_sequence, head_dim].
Optional additive mask broadcastable to [batch, heads, sequence, key_sequence].
Multiplicative scale for attention logits.
Attention dropout probability.
Ignored attention backend arguments.
Returns: torch.Tensor
Tuple of context tensor [batch, sequence, heads, head_dim] and attention weights
Normalize an optional precomputed mask into additive layout.
Parameters:
Optional attention mask of shape [batch, heads_or_one, sequence, key_sequence]. Bool masks use True for visible entries; additive masks are passed through.
Batch size used when mask is absent.
Query and key sequence length used when mask is absent.
Floating-point dtype for the additive mask.
Device for the additive mask.
Optional sequence mask of shape [batch, sequence] with nonzero valid tokens.
Optional sliding-window size for local attention.
Returns: torch.Tensor
Additive mask tensor of shape [batch, heads_or_one, sequence, key_sequence].
Build a causal additive attention mask.
Parameters:
Batch size for the returned mask.
Query and key sequence length.
Floating-point dtype for the additive mask.
Device for the returned mask.
Optional sequence mask of shape [batch, sequence] with nonzero valid tokens.
Optional sliding-window size for local attention.
Returns: torch.Tensor
Additive mask tensor of shape [batch, 1, sequence, sequence].
Repeat key/value heads for grouped-query attention.
Parameters:
Tensor of shape [batch, key_value_heads, sequence, head_dim].
Number of repeats per key/value head.
Returns: torch.Tensor
Tensor of shape [batch, key_value_heads * n_rep, sequence, head_dim].
Rotate the two halves of the RoPE feature axis.
Parameters:
Tensor of shape […, rotary_dim], where rotary_dim is even.
Returns: torch.Tensor
Tensor of shape […, rotary_dim].
Run SDPA attention over projected query/key/value states.
Parameters:
Attention module carrying head-repeat metadata.
Query tensor of shape [batch, heads, sequence, head_dim].
Key tensor of shape [batch, key_value_heads, key_sequence, head_dim].
Value tensor of shape [batch, key_value_heads, key_sequence, head_dim].
Optional additive mask broadcastable to [batch, heads, sequence, key_sequence].
Ignored because SDPA applies its own scale.
Attention dropout probability.
Ignored attention backend arguments.
Returns: tuple[torch.Tensor, None]
Tuple of context tensor [batch, sequence, heads, head_dim] and None for weights.