nemo_automodel.components.models.qwen3_moe.model
nemo_automodel.components.models.qwen3_moe.model
Module Contents
Classes
Data
API
Bases: Module
Bases: HFCheckpointingMixin, Module, MoEFSDPSyncMixin
Declare only this model’s FA4 THD input path; other backends keep their contracts.
Request framework-owned raw token/label flattening for the FA4 path.
This requests CP1 batch conversion only, not context or pipeline parallelism. TE retains its existing backend-owned preparation.
Compute logits while preserving packed document and padding metadata.
Parameters:
Token IDs of shape [batch, sequence], or [1, tokens] for pre-packed THD input. Pipeline stages after the first receive hidden states of shape [batch, sequence, hidden] in this slot.
Optional document-local positions of shape [batch, sequence], or [1, tokens] for THD input.
Optional tensor of shape [batch, sequence] holding either a padding mask (nonzero at valid tokens) or packed 1-based document IDs with zero at padding, or a dense mask of shape [batch, 1, sequence, sequence] for backends that accept one.
Optional boolean tensor of shape [batch, sequence], true at padding. Native FA4 derives its valid-token mask from it when attention_mask is None and some token is padding; all-valid batches use dense FA4.
Number of trailing positions to project, or position indices of shape [selected_tokens].
Whether to include final hidden states.
Backend metadata. Native FA4 packing passes int64 packed_token_indices of shape [batch, sequence] (row-local token indices, -1 at padding), int32 cu_seqlens of shape [batch, max_documents + 1] (row-local offsets, -1 at unused entries) and an integer max_seqlen. The model-entry hook flattens them to indices of shape [tokens] into the flattened [batch * sequence] axis and offsets of shape [documents + 1]; already flattened metadata passes through unchanged.
Returns: CausalLMOutputWithPast
CausalLMOutputWithPast whose logits have shape [batch, sequence,
Bases: Module
Run decoder layers, preparing private FA4 THD metadata once per model call.
Parameters:
Token IDs of shape [batch, sequence] or physical THD token IDs of shape [1, tokens], squeezed to [tokens] for the layers. Pipeline stages after the first receive hidden states of shape [batch, sequence, hidden] or [1, tokens, hidden] in this slot.
Optional positions with the token layout of input_ids.
Optional [batch, sequence] padding mask or packed document IDs, or a [batch, 1, sequence, sequence] dense mask. None for THD.
Optional bool mask with the token layout of input_ids, True at padding, including physical THD padding between documents.
Backend metadata. THD supplies int32 cu_seqlens and cu_seqlens_padded of shape [documents + 1]. For FA4 THD this adds private compact offsets of shape [documents + 1] and int64 packed_token_indices of shape [valid_tokens] into the physical [tokens] axis, shared by every layer. Inputs are not mutated.
Returns: torch.Tensor
Hidden states of shape [batch, sequence, hidden], or [1, tokens, hidden] for THD input.