nemo_automodel.components.models.glm5_next.layers
nemo_automodel.components.models.glm5_next.layers
Native GLM-5.3 text layers.
The released model alternates Kimi Delta Attention (KDA) and GLM-style KPool-compressed Dynamic Sparse Attention (DSA), with manifold-constrained Hyper-Connections (mHC) around both sublayers. FLA owns the production KDA kernel; small pure-Torch fallbacks keep CPU construction and unit tests useful.
Module Contents
Classes
Functions
Data
API
Bases: Module
One mHC decoder block with KDA/DSA and dense/MoE feed-forward.
Transform residual streams [batch, local_sequence, hc_mult, hidden].
Initialize all decoder children.
Update the correction bias for this layer’s learned MoE router.
Bases: Module
Manifold-constrained mixer for hc_mult residual streams.
hidden_streams is [batch, sequence, hc_mult, hidden]. The returned
tensors are post [batch, sequence, hc_mult], comb [batch, sequence, hc_mult, hc_mult] and collapsed [batch, sequence, hidden].
Expose the checkpoint’s flat mHC base parameter.
Expose the checkpoint’s flat mHC scale parameter.
Build Sinkhorn mixing weights and collapse streams for one sublayer.
Initialize mHC parameters on buffer_device.
Bases: Module
Own mHC parameters that must remain fp32 under FSDP mixed precision.
Build FP32 mHC weights while this holder’s FSDP unit is unsharded.
Bases: Module
Own recurrent-decay parameters that must remain fp32 under FSDP.
Return log-decay gates [batch, sequence, heads, head_dim].
Bases: Module
KPool-compressed DSA indexer for training without a KV cache.
Prepare one document and select indices for a query chunk.
full_hidden is [1, keys, hidden]; query tensors are [1, queries, ...] and positions are document-local [queries].
Returns [1, queries, index_topk + kpool - 1] int32 indices.
Initialize indexer projections and KPool parameters.
Compress one document’s keys into KPool candidates.
Parameters:
Hidden states with shape [1, keys, hidden] for one
unpadded document.
Returns: torch.Tensor
Pool keys with shape [complete_pools, index_head_dim] and raw
Select raw key indices for one query chunk.
Parameters:
Hidden states with shape [1, queries, hidden].
Low-rank query states with shape
[1, queries, q_lora_rank].
Document-local positions with shape [queries].
Prepared KPool keys with shape
[complete_pools, index_head_dim].
Prepared raw token indices with shape
[complete_pools, index_kpool].
Number of tokens in the unpadded document.
Returns: torch.Tensor
Int32 raw indices with shape
Bases: Module
Kimi Delta Attention with released GLM-5.3 checkpoint parameter names.
Expose the checkpoint’s flat A_log parameter name.
Expose the checkpoint’s flat dt_bias parameter name.
Project and execute KDA for one packed row or a regular batch.
Run KDA over [batch, local_sequence, hidden] without crossing documents.
Initialize KDA while preserving fp32 recurrent parameters.
Attach the one-dimensional contiguous CP mesh.
Bases: Module
RMSNorm with fp32 variance accumulation.
Input and output have shape [batch, sequence, hidden]; the leading axes
may be replaced by any token layout as long as hidden is last.
Normalize [..., hidden] and preserve the input dtype.
Bases: Module
NoPE MLA whose visibility is selected by the GLM KPool indexer.
Execute sparse attention for a local query interval of one full document.
Parameters:
Unpadded document states with shape [1, key_tokens, hidden].
Inclusive document-local index of the first local query.
Exclusive document-local index of the final local query.
Returns: torch.Tensor
Projected attention output with shape
Run absorbed latent attention through FlashMLA/cuDNN for one document.
Parameters:
Unpadded document states with shape [1, key_tokens, hidden].
Normalized shared latent K/V with shape
[1, key_tokens, 512].
KPool-compressed index keys with shape
[complete_pools, index_head_dim].
Document-local token indices with shape
[complete_pools, index_kpool].
Inclusive document-local index of the first local query.
Exclusive document-local index of the final local query.
Returns: torch.Tensor
Projected attention output with shape
Run document-isolated sparse attention on [batch, local_sequence, hidden].
Initialize MLA and indexer parameters.
Attach the CP mesh used for differentiable full-sequence gathering.
Bases: Module
Parameter-free fp32 RMS normalization used by mHC.
Normalize [..., hc_streams * hidden] without a learned weight.
Bases: Glm5NextRMSNorm
CPU fallback for FLA’s gated per-head RMSNorm.
Normalize [batch, sequence, heads, head_dim] then sigmoid-gate it.
Bases: Module
Depthwise causal Conv1d matching FLA ShortConvolution state keys.
Convolve [batch, sequence, channels] and reset at packed boundaries.
Differentiable reference KDA for CPU/small tensors.
All q/k/v/g tensors are [batch, sequence, heads, head_dim] and beta is
[batch, sequence, heads]. Packed boundaries reset the recurrent state.