nemo_automodel.components.models.mistral_large4.model
nemo_automodel.components.models.mistral_large4.model
Mistral Large 4 text model with expert, pipeline and context parallelism.
Module Contents
Classes
Functions
API
Bases: Module
Pre-normalized MLA followed by dense or routed/shared SwiGLU.
Run one block with immutable sharing inputs, safe for recomputation.
Parameters:
Unsharded [tokens, hidden] activations.
FP32 cosine/sine pair [tokens, rotary_dim / 2].
Positions, document IDs and validity [tokens].
Optional latent [tokens, latent_dim], rotated keys [tokens, rotary_dim] (zero final dimension for NoPE).
Optional preceding int64 [tokens, min(topk, tokens)] selection.
Returns: torch.Tensor
Hidden [tokens, hidden], KV pair and selected indices in input layouts.
Bases: MistralLarge4PipelineMixin, HFCheckpointingMixin, PreTrainedModel, MoEFSDPSyncMixin
Text model; source FP8 weights are reconstructed on load.
Training runs in floating point: serving FP8 indexer/KV-cache execution and DSpark drafting are not implemented. DSA parameters remain frozen pending a training specification.
Run causal or document-packed text with capped logits and optional shifted CE.
Parameters:
Integer [batch, sequence], or packed [tokens] with thd format. Under CP, text-only PP1 takes pre-sharded local IDs; stage zero of PP takes global IDs and shards after embedding.
Non-first PP boundary tensors in the layouts
documented by _pipeline_boundary_metas. input_ids then holds
compute-dtype residual [batch, sequence, hidden].
Floating [batch, sequence, hidden] or packed [tokens, hidden], replacing IDs with the same CP ownership.
Nonnegative integer positions [batch, local_sequence] under CP, otherwise matching the input token axes.
Binary keep mask or nonnegative packed document IDs, matching input token axes. CP stage zero receives a global mask and shards it alongside embeddings; later stages use transported layout.
Optional bool padding mask; true excludes a token. CP sharder supplies [batch, local_sequence], including CP padding.
Optional integer targets, same token shape; -100 ignored. This HF-style path shifts labels once, excluding padding/document edges.
Zero for all, positive tail length, or int64 [kept_positions]. Labels require all positions. Index selection applies to the sequence axis.
Return final [batch, sequence, hidden] activations.
SDPA THD requires integer offsets [documents + 1] strictly partitioning flattened storage. Prepared THD receives padded global offsets [1, documents + 1] from its sharder; its local document IDs and padding mask preserve inter-document padding.
Optional real document lengths [batch, documents], with -1000 padding, retained by the packed sharder for document-count validation.
bshd or thd (packed output has a leading batch dimension of one).
Must be false; incremental generation caches are not supported.
Model-prepared integer [batch, local_sequence] document identity for prepared THD. Each microbatch contains one packed row.
Returns: CausalLMOutputWithPast | torch.Tensor | tuple[torch.Tensor, ...]
CausalLMOutputWithPast with capped logits [batch, kept_sequence, vocab],
Construct the registered model through AutoModel’s existing interface.
Return the untied input embedding.
Return the untied language head.
Initialize materialized parameters in their resident storage dtype.
Initialize in place without temporarily promoting the entire pretrained base to FP32. Protected modules own separate FP32 FSDP units and must never pass through the broad body-dtype cast.
Parameters:
Device on which the caller materialized parameters.
Optional final body storage dtype; sensitive modules remain FP32.
Prepare CP-local targets and positions with the model-owned sharder.
Parameters:
Global IDs/masks [batch, sequence] or embeddings [batch, sequence, hidden], with optional complete image payloads. THD requires IDs [microbatches, packed_sequence] plus seq_lens/seq_lens_padded [microbatches, documents].
Number of PP microbatches along the batch dimension.
Returns: dict[str, ContextParallelSharder]
Sharder mapping using prepare_cp_inputs’ tensor contract. PP keeps
Per-forward state; never retained on a module or detached.
Optional int64 [tokens, min(index_topk, tokens)] selected keys.
Source-layer IDs mapped to latent [tokens, latent_dim] and rotated key [tokens, rotary_dim] tensors; NoPE keys have width zero.
FP32 cosine/sine tensors, each [tokens, rotary_dim / 2].
Bases: Module
Text backbone; each forward owns the lifetime of its shared source activations.
Run owned layers with explicit, per-microbatch shared state.
Parameters:
Unsharded compute-dtype activations [tokens, hidden].
Positions, document IDs and validity, each [tokens].
Optional received FP32 tables [tokens, rotary_dim / 2], KV pairs [tokens, latent_dim] / [tokens, rotary_width], and int64 selections [tokens, min(index_topk, tokens)]. Never mutated.
Returns: torch.Tensor
Activations [tokens, hidden], normalized only on the final stage,
Use the existing PP hooks and tuple transport without replicated parameters.
Emit capped final logits or fresh tensors for the next stage.
Parameters:
Compute-dtype residual [batch, sequence, hidden].
Flattened integer positions/documents and bool validity [tokens].
FP32 cosine/sine [tokens, rotary_dim / 2], live KV pairs [tokens, latent_dim] / [tokens, rotary_width], and selected int64 keys [tokens, min(index_topk, tokens)].
Returns: torch.Tensor | tuple[torch.Tensor, ...]
Final FP32 logits [batch, sequence, vocab], or compute-dtype hidden
Identify trimmed stages from their actual module ownership.
Describe residual, rotary, layout and live sharing tensors at one cut.
Returns: torch.Tensor
Meta tensors: residual [batch, sequence, hidden] in compute dtype;
Return original, contiguous decoder indices after the shared splitter.
Select produced KV sources still needed at or after a decoder boundary.
Decode the prior stage’s tensors without detaching differentiable state.
Parameters:
Compute-dtype residual [batch, sequence, hidden].
Remaining boundary tensors in _pipeline_boundary_metas
order; no tensor aliases are mutated.
Returns: SequenceLayout
Layout with flattened [tokens] position/document/validity fields,
Assign the single learnable LeRoPE module to stage zero.
Parameters:
Generated module FQNs in forward stage order.
Decoder parent prefix, required to be model..
Resolved backbone supplied by the generic splitter.
Returns: list[list[str]]
Independent FQN lists with LeRoPE exclusively on the first stage.
Provide exact tuple metadata to the existing PyTorch PP schedule.
Parameters:
Whether this is the first logical stage.
Number of documents in one pipeline microbatch.
Global nonpacked sequence length before CP padding.
Body compute dtype; rotary transport always remains FP32.
Returns: tuple[torch.Tensor, ...]
Input/output meta tuples using _pipeline_boundary_metas’ layouts.
Preserve Mistral’s BF16 SiLU and product rounding before the down GEMM.
Parameters:
BF16 or FP32 tensor [routed_tokens, 2*intermediate], gate then up. May be noncontiguous. No input is modified.
All-one activation weights [routed_tokens, 1]; actual FP32 routing weights are applied by the expert backend after down.
Returns: torch.Tensor
Independent tensor [routed_tokens, intermediate] in projections.dtype.