> This page is for version 0.7.0 · 26.10.
> 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.speculative.dfly2.target

Model-owned contracts and the frozen-target wrapper for DFly2 training.

DFly2 reads the target's own attention state, whose layout is architecture specific, so
the target model produces it (`DFly2TargetFeatureProvider`) and the target config
builds the matching draft (`ModelOwnedDFly2Provider`). This module only names those
contracts and runs the frozen forward.

## Module Contents

### Classes

| Name                                                                                                           | Description                                                                       |
| -------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| [`DFly2TargetBatch`](#nemo_automodel-components-speculative-dfly2-target-DFly2TargetBatch)                     | Target features and the batch tensors the DFly2 trainer reads.                    |
| [`DFly2TargetFeatureProvider`](#nemo_automodel-components-speculative-dfly2-target-DFly2TargetFeatureProvider) | Target model that exposes the attention state its paired DFly2 draft layers read. |
| [`DFly2TargetModel`](#nemo_automodel-components-speculative-dfly2-target-DFly2TargetModel)                     | Run a frozen target that implements `DFly2TargetFeatureProvider`.                 |
| [`ModelOwnedDFly2Provider`](#nemo_automodel-components-speculative-dfly2-target-ModelOwnedDFly2Provider)       | Target config that owns construction of its architecture-specific DFly2 draft.    |
| [`_DFly2DraftOptions`](#nemo_automodel-components-speculative-dfly2-target-_DFly2DraftOptions)                 | Recipe options consumed by model-owned DFly2 draft constructors.                  |

### API

```python
class nemo_automodel.components.speculative.dfly2.target.DFly2TargetBatch(
    features: nemo_automodel.components.speculative.dfly2.common.DFly2TargetFeatures,
    input_ids: torch.Tensor,
    loss_mask: torch.Tensor
)
```

Dataclass

Target features and the batch tensors the DFly2 trainer reads.

**`features`** `DFly2TargetFeatures`

Frozen target state, documented by `DFly2TargetFeatures`.

---

**`input_ids`** `Tensor`

Integer tensor of shape \[batch, sequence].

---

**`loss_mask`** `Tensor`

Tensor of shape \[batch, sequence] selecting supervised tokens.

---

```python
class nemo_automodel.components.speculative.dfly2.target.DFly2TargetFeatureProvider()
```

Protocol

Target model that exposes the attention state its paired DFly2 draft layers read.

```python
nemo_automodel.components.speculative.dfly2.target.DFly2TargetFeatureProvider.dfly2_target_features(
    input_ids: torch.Tensor,
    attention_mask: torch.Tensor,
    layer_ids: collections.abc.Sequence[int]
) -> nemo_automodel.components.speculative.dfly2.common.DFly2TargetFeatures
```

Run the frozen forward and return the paired layers' keys and key lists.

**Parameters:**

**`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]`

Target layers paired with the draft layers, in draft-layer order.

---

```python
class nemo_automodel.components.speculative.dfly2.target.DFly2TargetModel(
    model: torch.nn.Module,
    target_layer_ids: collections.abc.Sequence[int]
)
```

Run a frozen target that implements `DFly2TargetFeatureProvider`.

**`model`** `= model.eval()`

---

**`target_layer_ids`** `= [(int(layer_id)) for layer_id in target_layer_ids]`

---

```python
nemo_automodel.components.speculative.dfly2.target.DFly2TargetModel.generate_batch(
    input_ids: torch.Tensor,
    attention_mask: torch.Tensor,
    loss_mask: torch.Tensor
) -> nemo_automodel.components.speculative.dfly2.target.DFly2TargetBatch
```

Run the target once and collect the DFly2 features.

**Parameters:**

**`input_ids`** `torch.Tensor`

Integer tensor of shape \[batch, sequence].

---

**`attention_mask`** `torch.Tensor`

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

---

**`loss_mask`** `torch.Tensor`

Tensor of shape \[batch, sequence] selecting supervised tokens.

---

**Returns:** `DFly2TargetBatch`

The batch with the features of `DFly2TargetFeatureProvider.dfly2_target_features`.

```python
nemo_automodel.components.speculative.dfly2.target.DFly2TargetModel.get_input_embeddings() -> torch.nn.Module
```

Return the target's input embedding.

```python
nemo_automodel.components.speculative.dfly2.target.DFly2TargetModel.get_output_embeddings() -> torch.nn.Module
```

Return the target's LM head.

```python
class nemo_automodel.components.speculative.dfly2.target.ModelOwnedDFly2Provider()
```

Protocol

Target config that owns construction of its architecture-specific DFly2 draft.

```python
nemo_automodel.components.speculative.dfly2.target.ModelOwnedDFly2Provider.build_dfly2_draft(
    options: nemo_automodel.components.speculative.dfly2.target._DFly2DraftOptions
) -> torch.nn.Module
```

Build a draft from the recipe's declarative options.

```python
class nemo_automodel.components.speculative.dfly2.target._DFly2DraftOptions()
```

Protocol

Recipe options consumed by model-owned DFly2 draft constructors.

**`attn_backend`** `str`

---

**`block_size`** `int`

---

**`confidence_head_stop_gradient`** `bool`

---

**`enable_confidence_head`** `bool`

---

**`mask_token_id`** `int`

---

**`num_anchors`** `int`

---

**`target_layer_ids`** `list[int]`

---