nemo_automodel.components.models.deepseek_v41.dspark
nemo_automodel.components.models.deepseek_v41.dspark
Native DeepSeek V4.1 DSpark draft backbone.
The released draft is stored under mtp.0 through mtp.2 but is not the
autoregressive MTP objective used by earlier DeepSeek models. It is a parallel
five-position drafter whose three blocks use sliding-window MLA, routed MoE and
single-pass mHC. This module implements the trainable, cache-free backbone; the
shared frozen embedding/LM head and anchor sampling remain owned by the generic
DSpark trainer.
Module Contents
Classes
Data
API
Bases: Module
Three-stage native drafter operating on prepared target and noise tensors.
Build the released SWA-128 multi-anchor training mask.
Every query sees the target window ending immediately before its anchor, plus every parallel input in its own draft block. It cannot see another anchor’s block. Invalid padding blocks retain their own in-block keys so no attention row is fully masked; their losses are discarded later.
Parameters:
Integer tensor [batch, num_anchors].
Boolean tensor [batch, num_anchors].
Number of target-context tokens.
Floating dtype of the returned additive mask.
Returns: torch.Tensor
Additive tensor [batch, 1, num_anchors * block_size,
Build official target-context and draft-query positions.
Parameters:
Integer tensor [batch, num_anchors] containing the target token that seeds each draft block.
Number of target-context tokens.
Returns: torch.Tensor
Integer tensor [batch, context_sequence + num_anchors * block_size].
Run the cache-free draft backbone for sampled anchors.
Parameters:
Tensor of shape [batch, draft_sequence, hidden], containing an anchor embedding followed by noise embeddings in each fixed-width block.
Concatenated target features of shape [batch, context_sequence, target_layers * hidden].
Integer tensor of shape [batch, context_sequence + draft_sequence].
Additive tensor of shape [batch, 1, draft_sequence, context_sequence + draft_sequence].
Optional integer tensor of shape [batch, draft_sequence] used by the final Markov head.
Whether the final stage computes confidence.
Whether the confidence head reads detached inputs.
Returns: DeepseekV41DSparkBackboneOutput
Draft backbone output containing normalized states of shape [batch,
Initialize every draft parameter for checkpoint-free training.
Parameters:
Device used by grouped expert initialization. Defaults to the first attention projection’s device.
Native draft states consumed by the released output heads.
Bases: DeepseekV41DSparkBackbone
Model-owned adapter from the native draft to the shared DSpark loss contract.
Expose native MTP stages to the shared AC/FSDP helpers.
Project hidden states through the frozen vocabulary head in FP32.
Parameters:
Tensor of shape [batch, sequence, hidden].
Returns: torch.Tensor
FP32 tensor of shape [batch, sequence, vocab].
Run native V4.1 DSpark training for sampled anchors.
Parameters:
Target-token tensor of shape [batch, sequence].
Concatenated target-feature tensor of shape [batch, sequence, target_layers * hidden].
Supervision tensor of shape [batch, sequence].
Optional frozen target-state tensor of shape [batch, sequence, hidden] used by the probability-distance loss.
Returns: DSparkForwardOutput
Shared DSpark loss inputs. Draft logits have shape [batch,
Copy the target’s embedding and vocabulary projection.
Parameters:
Target embedding with weight of shape [vocab, hidden].
Target output projection with weight of shape [vocab, hidden].
Disable gradients for both copied modules when true.
Set whether the copied embedding and LM head receive gradients.
Bases: DeepseekV41Attention
Cache-free DSpark attention over target context and parallel draft blocks.
Attend draft queries to target context and their own parallel block.
Parameters:
Draft tensor of shape [batch, draft_sequence, hidden].
Projected target tensor of shape [batch, context_sequence, hidden].
Integer tensor of shape [batch, context_sequence + draft_sequence], containing absolute positions for both regions.
Additive tensor broadcastable to shape [batch, heads, draft_sequence, context_sequence + draft_sequence], with zero for visible keys and negative infinity for masked keys.
Returns: torch.Tensor
Tensor of shape [batch, draft_sequence, hidden]. Inputs are not mutated.
Bases: Module
One released DSpark stage with MLA, MoE, mHC and stage-owned heads.
Expose the shared parallelizer’s MoE interface without duplicate registration.
Apply one native DSpark stage.
Parameters:
Tensor of shape [batch, draft_sequence, streams, hidden].
FP32 tensor of shape [batch, draft_sequence, streams].
Tensor of shape [batch, context_sequence, hidden].
Integer tensor of shape [batch, context_sequence + draft_sequence].
Additive tensor of shape [batch, 1, draft_sequence, context_sequence + draft_sequence].
Optional integer tensor of shape [batch, draft_sequence] used by the final Markov head.
Whether the final stage computes confidence.
Whether the confidence head reads
detached inputs, so its loss trains only confidence_head.
Returns: _DeepseekV41DSparkStageOutput
Stage state containing updated streams, target features, and any
Bases: Module
Predict conditional acceptance logits in FP32.
AutoModel-trained drafts feed the final RMSNorm output to this head. Serving these checkpoints must use the same input instead of the released raw residual.
Predict a conditional acceptance logit for every draft position.
Parameters:
Final RMSNorm output of shape […, hidden].
Tensor of shape […, markov_rank] with matching leading dimensions.
Returns: torch.Tensor
FP32 tensor of shape […] containing uncalibrated confidence logits.
Bases: Module
Rank-factorized first-order token-transition bias.
Compute the transition bias and its conditioning embedding.
Parameters:
Integer tensor of shape […] containing preceding tokens.
Returns: torch.Tensor
Transition logits of shape […, vocab] and embeddings of shape
Bases: NamedTuple
Internal stage state kept within each stage’s FSDP forward boundary.