nemo_automodel.components.models.step5.layers
nemo_automodel.components.models.step5.layers
Trainable Step-5 decoder layers and context-parallel attention.
Module Contents
Classes
Functions
Data
API
Bases: Module
GQA with windowed or CSA-selected keys and contiguous query-shard CP.
Select once or replay integer routes during activation recomputation.
Parameters:
Local normalized states [batch, local_queries, hidden].
Int64 local document positions [batch, local_queries].
Int64 global document positions [batch, global_keys].
Boolean global padding flags [batch, global_keys].
Physical start of the local query shard.
Layer-independent global/local region layout.
Returns: RegionSelection
Integer-only region selection; no projected K/V or activations are
Attend local queries to valid global keys, preserving document boundaries.
Parameters:
Tensor of shape [batch, local_sequence, hidden].
Tensor of shape [batch, local_sequence], document-local positions.
Boolean tensor of shape [batch, local_sequence], true for padding.
Int tensor [batch, global_sequence], gathered once per model call.
Boolean tensor [batch, global_sequence], true for padding.
Returns: torch.Tensor
Tensor of shape [batch, local_sequence, hidden].
Attach the CP group through AutoModel’s model-owned attention hook.
Bases: Module
Pre-norm decoder with FP32 residual accumulation and optional shared MoE.
Apply attention and feed-forward residual branches.
Parameters:
FP32 tensor of shape [batch, local_sequence, hidden].
Tensor of shape [batch, local_sequence].
Boolean tensor of shape [batch, local_sequence], true for padding.
Int tensor [batch, global_sequence], gathered once per model call.
Boolean tensor [batch, global_sequence], true for padding.
Activation dtype from the completed embedding projection.
Shared global region layout and local query metadata.
Returns: torch.Tensor
FP32 tensor of shape [batch, local_sequence, hidden].
Compose the native AC context with one integer-route log per call.
Parameters:
Existing plain/selective checkpoint context factory.
Returns: Callable[[], tuple[AbstractContextManager, AbstractContextManager]] | None
A factory with a distinct recorder for each live pipeline microbatch,
Bases: Module
SwiGLU with separate gate/up projections and FP32 asymmetric clamping.
Evaluate the dense or shared feed-forward block.
Parameters:
Tensor of shape [batch, sequence, hidden].
Returns: torch.Tensor
Tensor of shape [batch, sequence, hidden] in the input dtype.
Bases: Step3p5RMSNorm
Fuse the main-stream norm while retaining FP32 additive scale parameters.
Indexer normalization deliberately uses its separate implementation: its checkpoint requires rounding the scale to the activation dtype first.
Parameters:
Normalized feature width.
Additive variance epsilon.
Enable the compiled CUDA core. CPU always uses eager math.
Run the compiled CUDA norm on […, hidden_size] and restore the input shape.
Normalize […, hidden_size] before the optional projection-input cast.
Parameters:
Activations […, hidden_size] with arbitrary leading axes. Grouped queries use [batch, sequence, groups, heads_per_group, hidden_size] and may be a strided slice of interleaved QKV. Decoder residual inputs remain FP32 through normalization.
Final output dtype; defaults to the input dtype.
Returns: torch.Tensor
Normalized activations with the input shape. The learned FP32 scale
Normalize grouped query rows without copying interleaved QKV gaps.
Parameters:
Query tensor [token_groups, heads_per_group, channels], where token_groups flattens batch, sequence and KV group. The outer stride includes the interleaved K/V rows, and channels has unit stride.
FP32 additive scale [channels].
Additive variance epsilon.
Final normalized activation dtype.
Returns: torch.Tensor
Normalized query [token_groups, heads_per_group, channels] and FP32
Normalize […, width] in FP32 before rounding once to the output dtype.
Normalize in FP32 and retain the row statistic needed by backward.
Fuse FP32 SwiGLU and its derivative without FP32 activation temporaries.
Parameters:
Projection tensor [batch, sequence, intermediate].
Projection tensor with the same shape and dtype.
Positive clamp bound; non-positive values disable clamping.
Returns: torch.Tensor
Tensor with the same shape and dtype as gate.
Run the shared compiled FlexAttention kernel without a dense token mask.
Parameters:
CUDA tensor [batch, local_queries, query_heads, head_dim].
CUDA tensor [batch, global_keys, kv_heads, head_dim].
CUDA tensor with the same shape and dtype as key.
Document-local positions [batch, local_queries].
Document-local positions [batch, global_keys].
Boolean tensor [batch, global_keys], true for padding.
Document ids [batch, global_keys].
Global offset of the contiguous query shard.
Sliding window size, or None for CSA layers.
Compact sorted CSA region ids, or None for sliding attention.
Returns: torch.Tensor
Attention output [batch, local_queries, query_heads, head_dim].