nemo_automodel.components.models.glm_moe_dsa.model
nemo_automodel.components.models.glm_moe_dsa.model
Module Contents
Classes
Functions
Data
API
Bases: Module
Run the block and return (hidden_states, topk_indices).
topk_indices is this layer’s DSA selection — freshly computed on “full” layers,
or prev_topk_indices passed through on “shared” layers — so the caller can thread
it to subsequent shared layers (GLM IndexShare).
Bases: HFCheckpointingMixin, Module, MoEFSDPSyncMixin
True when this module is a trimmed pipeline-parallel stage (not the whole model).
Forward pass.
Single process (no pipeline parallelism): returns
:class:~transformers.modeling_outputs.CausalLMOutputWithPast, threading the IndexShare
top-k internally (seeded None).
Pipeline parallelism: input_ids is the upstream hidden state on non-first stages.
IndexShare models additionally use *carry for the previous stage’s running top-k
selection. Non-last stages return the declared pipeline outputs and the last stage returns
the logits tensor.
Parameters:
Token-ID tensor of shape [batch, sequence] (BSHD) or [1, tokens]
(packed THD) on the first stage. On later stages, the upstream hidden-state
tensor has shape [batch, sequence, hidden] or [tokens, hidden].
Optional top-k tensor carried from the previous pipeline stage. Optimized
THD backends use float32 [tokens, 1, index_topk]; dense BSHD uses float32
[batch, sequence, min(index_topk, sequence)].
Optional position-ID tensor of shape [batch, sequence] or
[1, tokens] for packed THD.
Optional key-mask tensor of shape [batch, sequence] or additive
mask of shape [batch, 1, sequence, sequence].
Optional padding-mask tensor of shape [batch, sequence] or
[1, tokens] for packed THD.
If 0, project all positions; else only the last logits_to_keep.
A tensor value contains the one-dimensional token indices to project.
When set (single-process), carry final hidden states on the output.
Additional attention metadata forwarded to the base model. Packed THD
uses an int32 cu_seqlens tensor of shape [sequences + 1] and
qkv_format="thd".
Returns: CausalLMOutputWithPast | tuple[torch.Tensor, ...] | torch.Tensor
Single-process execution returns a causal-LM output whose logits tensor has shape
Declare PP inter-stage I/O metas, adding a top-k carry only for IndexShare models.
IndexShare models additionally receive and emit the previous “full” layer’s top-k selection so a stage that begins with a “shared” layer has the indices it needs. Models with all-full indexers need only the hidden-state channel.
Parameters:
Whether this module is the first pipeline stage.
Number of sequences in the pipeline microbatch.
Sequence or packed-token length represented by the metadata.
Hidden-state and logits dtype.
Returns: tuple[torch.Tensor, ...]
Pair of input and output metadata tuples. Optimized THD stages use hidden-state
Attach GLM DSA’s packed THD context-parallel batch sharder.
Parameters:
The batch dict.
Number of chunks for load-balanced CP sharding.
Return whether validation must use the optimized packed THD layout.
Delegate the noaux router correction-bias update to the inner model.
Bases: Module
Run the decoder stack, returning (hidden_states, topk_indices).
Parameters:
Token IDs with shape [batch, sequence] (or packed
[tokens]), or previous-stage hidden states with the matching token
axes plus [hidden] when this pipeline stage has no embedding.
Optional integer positions with the same token axes as
input_ids. Packed THD callers supply shape [tokens].
Optional token mask with shape [batch, sequence] or
additive attention mask broadcastable to [batch, heads, query, key].
Optional boolean mask with the input token axes; True
marks padding. Packed THD callers supply shape [tokens].
Optional previous pipeline stage’s IndexShare selection,
shaped [batch, sequence, K] or packed [tokens, 1, K]. Packed
values are global THD padded-storage K/V coordinates.
Attention layout metadata. Packed THD uses cu_seqlens
and optional cu_seqlens_padded of shape [sequences + 1], plus
optional glm_dsa_cp_query_indices of shape [tokens] containing
global padded-storage query coordinates.
Returns: torch.Tensor
Hidden states with the input token axes plus [hidden], and the latest
Update the noaux router correction bias of each local MoE layer; dense layers and disabled gates are skipped.
Return whether the model has layers that reuse another layer’s DSA indices.