> This page is for version Latest.
> For other versions, use one of these documentation indexes:
> - Nightly (default): https://docs.nvidia.com/nemo/automodel/nightly/llms.txt
> - Latest: https://docs.nvidia.com/nemo/automodel/latest/llms.txt
> - 0.7.0 · 26.10: https://docs.nvidia.com/nemo/automodel/v0.7/llms.txt
> - 0.5.0 · 26.06: https://docs.nvidia.com/nemo/automodel/v0.5/llms.txt
> - 0.4.0 · 26.04: https://docs.nvidia.com/nemo/automodel/v0.4/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/automodel/llms.txt.

# nemo_automodel.components.models.deepseek_v41.dfly2_target

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

| Name                                                                                                         | Description                                                                                |
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
| [`_window_key_indices`](#nemo_automodel-components-models-deepseek_v41-dfly2_target-_window_key_indices)     | List each row's sliding-window keys: the last `window` tokens up to and including the row. |
| [`dfly2_target_features`](#nemo_automodel-components-models-deepseek_v41-dfly2_target-dfly2_target_features) | Run the frozen V4.1 target and capture the DFly2 features of the paired layers.            |

### API

```python
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`

```python
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]
) -> nemo_automodel.components.speculative.dfly2.common.DFly2TargetFeatures
```

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.