Skip to navigation
ReferenceFull Library ReferenceNemo AutomodelNemo AutomodelComponentsModelsDeepseek V41nemo_automodel.components.models.deepseek_v41.dfly2_target

nemo_automodel.components.models.deepseek_v41.dfly2_target

View as MarkdownOpen in Claude

DFly2 target features of DeepSeek V4.1: the paired layers’ keys and key lists.

A ratio-1 CSA2 layer attends over [its FP8 sliding-window KV | the shared 1:1 compressed KV]: row r reads the window keys r - 127 .. r and the compressed rows its indexer selected, offset past the window keys. The draft layer paired with it reads exactly those keys, so this capture returns, per paired layer, that concatenated key tensor and every row’s key list in the same layout.

The keys are taken during the frozen forward by a hook on each paired attention module, while its parameters are still gathered under FSDP: the window keys are recomputed from the layer’s input with the layer’s own projections (bitwise the values the layer used), and the compressed KV and selection are read from the attention state it publishes.

Module Contents

Functions

NameDescription
_window_key_indicesList each row’s sliding-window keys: the last window tokens up to and including the row.
dfly2_target_featuresRun the frozen V4.1 target and capture the DFly2 features of the paired layers.

API

nemo_automodel.components.models.deepseek_v41.dfly2_target._window_key_indices(
valid: torch.Tensor,
window: int
) -> torch.Tensor

List each row’s sliding-window keys: the last window tokens up to and including the row.

Parameters:

valid
torch.Tensor

Boolean tensor of shape [batch, sequence], false at right padding.

window
int

Window width.

Returns: torch.Tensor

Long tensor of shape [batch, sequence, min(window, sequence)] of token rows, -1

nemo_automodel.components.models.deepseek_v41.dfly2_target.dfly2_target_features(
model: torch.nn.Module,
input_ids: torch.Tensor,
attention_mask: torch.Tensor,
layer_ids: collections.abc.Sequence[int]

Run the frozen V4.1 target and capture the DFly2 features of the paired layers.

Parameters:

model
nn.Module

DeepseekV41ForCausalLM target, text only, without context parallelism.

input_ids
torch.Tensor

Integer tensor of shape [batch, sequence].

attention_mask
torch.Tensor

Binary right-padding tensor of shape [batch, sequence].

layer_ids
Sequence[int]

Paired ratio-1 layers, in draft-layer order.

Returns: DFly2TargetFeatures

Features whose context_keys[i] has shape [batch, 2 * sequence, head_dim] (the

Raises:

  • ValueError: A paired layer is not a ratio-1 layer.