nemo_automodel.components.models.inkling.text
nemo_automodel.components.models.inkling.text
Native Inkling text backbone, attention, masks, and decoding cache.
Module Contents
Classes
Functions
Data
API
Bases: Module
Inkling grouped-query attention with learned relative logits.
Apply self-attention.
Parameters:
Tensor of shape [batch, sequence, hidden].
Additive tensor of shape [batch, 1, query, key].
Optional boolean tensor of shape [batch, sequence] where
True marks a valid token.
Optional model-owned decoding cache.
Backend-compatible attention arguments; currently ignored by eager attention.
Returns: torch.Tensor
A pair containing the output tensor of shape [batch, sequence, hidden]
Initialize projections, norms, relative logits, and convolution weights.
Bases: Module
One native Inkling decoder layer.
Apply attention and feed-forward residual blocks.
Parameters:
Tensor of shape [batch, sequence, hidden].
Additive tensor of shape [batch, 1, query, key].
Optional boolean tensor of shape [batch, sequence] where
True marks a valid token.
Optional model-owned decoding cache.
Additional eager-attention arguments.
Returns: torch.Tensor
Tensor of shape [batch, sequence, hidden].
Initialize all parameters owned by the decoder layer.
Model-owned dynamic cache for Inkling attention and short convolutions.
Return the key/value length and absolute offset for a decoder layer.
Return the absolute starting position of the next query.
Return the number of tokens observed at a decoder layer.
Return whether one short-convolution cache has been populated.
Reorder every layer cache during beam search.
Parameters:
Long tensor of shape [new_batch] indexing the old batch axis.
Append key/value states at one decoder layer.
Parameters:
Tensor of shape [batch, key_value_heads, sequence, head_dim].
Tensor of shape [batch, key_value_heads, sequence, head_dim].
Decoder-layer index.
Returns: tuple[torch.Tensor, torch.Tensor | None]
A pair of tensors with shape [batch, key_value_heads, visible_sequence, head_dim].
Append and cache inputs for one short convolution.
Parameters:
Tensor of shape [batch, hidden, sequence].
Decoder-layer index.
Convolution index inside that layer.
Number of trailing tokens retained.
Returns: torch.Tensor
Tensor of shape [batch, hidden, cached_sequence + sequence].
Bases: Module
RMS normalization with fp32 variance accumulation.
Normalize the final hidden axis.
Parameters:
Tensor of shape [..., hidden] with arbitrary leading dimensions.
Returns: torch.Tensor
Tensor with the same shape and dtype as hidden_states.
Initialize the learned scale to one.
Bases: Module
Project token-conditioned relative-position profiles into attention bias.
Materialize the relative-position bias.
Parameters:
Tensor of shape [batch, query, heads, relative_dim].
Long tensor of shape [query] containing absolute positions.
Long tensor of shape [key] containing absolute positions.
Returns: torch.Tensor
Tensor of shape [batch, heads, query, key].
Initialize the relative-position profile bank.
Bases: Module
Native Inkling text backbone with pipeline-stage support.
Run the text backbone.
Parameters:
Optional tensor of shape [batch, sequence]. Pipeline stages
without embeddings may instead receive floating hidden states of shape
[batch, sequence, hidden] through this argument.
Optional padding tensor of shape [batch, total_sequence]
or a mapping from attention type to additive masks of shape
[batch, 1, query, key].
Optional long tensor of shape [batch, sequence].
Optional model-owned decoding cache.
Optional tensor of shape [batch, sequence, hidden].
Whether to allocate and return a decoding cache.
Additional eager-attention arguments.
Returns: BaseModelOutputWithPast
A model output whose last_hidden_state has shape [batch, sequence, hidden].
Return the token-embedding module.
Initialize the text backbone for checkpoint-free construction.
Replace the token-embedding module.
Dynamic key/value and short-convolution state for one decoder layer.
Return key/value length and absolute offset before appending a query.
Return the number of tokens observed by this layer.
Return whether a convolution state has seen at least one token.
Reorder cached batch entries during beam search.
Parameters:
Long tensor of shape [new_batch] indexing the old batch axis.
Append key/value states and return the states visible to this query.
Parameters:
Tensor of shape [batch, key_value_heads, sequence, head_dim].
Tensor of shape [batch, key_value_heads, sequence, head_dim].
Returns: tuple[torch.Tensor, torch.Tensor]
A pair of tensors with shape [batch, key_value_heads, visible_sequence, head_dim].
Append short-convolution inputs and update the fixed-size cache.
Parameters:
Tensor of shape [batch, hidden, sequence].
Index of one of the four convolution states owned by the layer.
Number of trailing tokens retained in the cache.
Returns: torch.Tensor
Tensor of shape [batch, hidden, cached_sequence + sequence] used by
Build an additive causal mask for Inkling eager attention.
Parameters:
Tensor of shape [batch, query, hidden].
Optional tensor of shape [batch, total_sequence] where nonzero
entries are valid keys, or a prepared tensor of shape [batch, 1, query, key].
Optional model-owned decoding cache.
Decoder-layer index used to size a hybrid cache.
Optional number of visible tokens for local attention.
Returns: torch.Tensor
Additive tensor of shape [batch, 1, query, key] in inputs_embeds.dtype.
Extract a local two-dimensional padding mask for short convolutions.
Parameters:
Optional tensor of shape [batch, total_sequence].
Length of the current local sequence.
Returns: torch.Tensor | None
Optional boolean tensor of shape [batch, query_length] where True
Repeat grouped key/value heads to match query heads.
Parameters:
Tensor of shape [batch, key_value_heads, sequence, head_dim].
Number of query heads sharing each key/value head.
Returns: torch.Tensor
Tensor of shape [batch, key_value_heads * repeats, sequence, head_dim].