Skip to navigation

nemo_automodel.components.speculative.dfly2.core

View as MarkdownOpen in Claude

DFly2 online training wrapper.

Like DSpark’s, the draft is self-contained (anchors, key lists, backbone, corrections), so this wrapper only calls it with the frozen target features and computes the DFly2 objective. It reports DSparkStepMetrics so the DSpark recipe’s metric window, evaluation and logging apply unchanged.

Module Contents

Classes

NameDescription
DFly2TrainerModuleDFly2 online training wrapper computing the D-PACE-weighted LK objective.

API

class nemo_automodel.components.speculative.dfly2.core.DFly2TrainerModule(
draft_model: torch.nn.Module,
dpace_alpha: float = 0.5,
lk_eta: float = 3.0,
confidence_head_alpha: float = 0.0
)

Bases: Module

DFly2 online training wrapper computing the D-PACE-weighted LK objective.

confidence_head_alpha
= float(confidence_head_alpha)
dpace_alpha
= float(dpace_alpha)
lk_eta
= float(lk_eta)
nemo_automodel.components.speculative.dfly2.core.DFly2TrainerModule.forward(
input_ids: torch.Tensor,
loss_mask: torch.Tensor,
context_keys: collections.abc.Sequence[torch.Tensor],
context_indices: collections.abc.Sequence[torch.Tensor],
target_last_hidden_states: torch.Tensor

Run the draft on the target features and compute the DFly2 loss.

Parameters:

input_ids
torch.Tensor

Target-token tensor of shape [batch, sequence].

loss_mask
torch.Tensor

Supervision tensor of shape [batch, sequence].

context_keys
Sequence[torch.Tensor]

One tensor per draft layer of shape [batch, context_keys, key_dim], as in DFly2TargetFeatures.

context_indices
Sequence[torch.Tensor]

One integer tensor per draft layer of shape [batch, sequence, slots], as in DFly2TargetFeatures.

target_last_hidden_states
torch.Tensor

Tensor of shape [batch, sequence, hidden].

Returns: DSparkStepMetrics

Step metrics. The per-position acceptance sums have block_size entries,