nemo_automodel.components.models.deepseek_v41.model
nemo_automodel.components.models.deepseek_v41.model
DeepSeek V4.1 text and image backbone for AutoModel training.
Forward contract (reference Transformer.forward of inference/model.py):
- Embed tokens and expand the hidden state into
hc_multresidual streams. - Run the 40 blocks with single-pass mHC: each block receives the input mix produced by the previous block’s FFN site (a one-hot mix reads stream 0 at the start). Engram modules write into the streams before their layer.
- Collapse the streams with the last FFN-site mix, apply the final RMSNorm and
the fp32
lm_head.
Cross-layer CSA2 state (shared compressed KV, index keys, Top-K indices and the
hierarchical candidate pool) lives in per-layer snapshots of
:class:~nemo_automodel.components.models.deepseek_v41.attention.DeepseekV41AttentionState.
Snapshots share tensors and preserve the state needed for activation recomputation.
The optional vision tower inserts projected image patches and learned image
delimiters into the text sequence. Text and image batches use full sequences
with two-dimensional token layouts. DSpark draft layers (mtp.*),
inference-time KV caching, and SWA bounded replay remain out of scope.
Module Contents
Classes
Data
API
Bases: Module
CSA2 and MoE sublayers with the single-pass mHC coefficient handoff.
Expose the shared parallelizer’s MoE interface without duplicate registration.
Execute one block while retaining differentiable shared KV ownership.
Parameters:
Tensor of shape [batch, sequence, streams, hidden].
FP32 tensor of shape [batch, sequence, streams].
Shared CSA2 tensors with layouts documented by DeepseekV41AttentionState; no tensor is mutated.
Integer tensor of shape [batch, sequence].
Optional binary tensor of shape [batch, sequence].
Optional boolean tensor of shape [batch, sequence].
Optional logical memory rows [batch, sequence, hash_heads].
Returns: torch.Tensor
Updated streams [batch, sequence, streams, hidden], the next pre-mix
Bases: HFCheckpointingMixin, PreTrainedModel, MoEFSDPSyncMixin
DeepSeek V4.1 causal LM with optional vision and an fp32 lm_head.
engram_process_group explicitly selects contiguous row owners for the
Engram tables. Distributed models default to WORLD, including a one-rank
WORLD. Without distributed initialization, tables remain local. FSDP’s
shard mesh must match the owner group exactly.
Insert image features and learned delimiters into fresh token embeddings.
Parameters:
Integer tensor of shape [batch, sequence].
Tensor of shape [all_patches, 3, patch_size, patch_size].
Integer tensor of shape [images, 2], containing patch grids.
Integer tensor of shape [batch, sequence], with -1 for text and 0/1/2/3 for image start/content/newline/end.
Returns: torch.Tensor
Tensor of shape [batch, sequence, hidden], retaining text and image
Register owner table DTensors before FSDP records ignored parameters.
Parameters:
One-dimensional shard mesh whose ranks and ordering must match the Engram owner group.
Returns: set[nn.Parameter]
Exact registered parameter identities to exclude from FSDP. Each
Compute full-vocabulary logits or hidden states for the training loss.
Parameters:
Integer tensor of shape [batch, sequence].
Optional binary right-padding tensor [batch, sequence].
Optional integer tensor of shape [batch, sequence].
Optional targets of shape [batch, sequence], with -100 ignored.
Optional image patches [all_patches, 3, patch_size, patch_size].
Optional patch-grid sizes [images, 2].
Optional image/text markers [batch, sequence].
Number of final positions, or integer position indices [kept].
Return final hidden states for the recipe’s loss.
Capture residual streams for numerical comparisons.
Returns: CausalLMOutputWithPast
CausalLMOutputWithPast containing logits [batch, kept_sequence, vocab],
Construct using the NeMo registry’s configuration entry point.
Return the untied token embedding module.
Return the independent vocabulary projection.
Initialize every trainable backbone weight after meta materialization.
Bases: Module
DeepSeek V4.1 decoder stack: embeddings, hyper-connected blocks, final norm.
Compute all positions without inference-only prefill shortcuts.
Parameters:
Integer tensor of shape [batch, sequence], also used for Engram.
Optional integer tensor of shape [batch, sequence].
Optional binary right-padding tensor [batch, sequence].
Optional boolean image-span tensor [batch, sequence].
Optional projected multimodal embeddings [batch, sequence, hidden].
Whether to retain streams before each block.
Returns: torch.Tensor
Final normalized hidden states [batch, sequence, hidden] and optional