nemo_automodel.recipes.speculative_decoding.train_dfly2
nemo_automodel.recipes.speculative_decoding.train_dfly2
DFly2 draft-model training recipe (DeepSeek V4.1 targets).
DFly2 (arXiv:2611.34776) is a block-parallel drafter for sparse-attention targets. Each
draft layer is paired with one target sparse-attention layer and reads that layer’s own
keys at the positions it attends from the row before the anchor, so the served drafter
shares the target’s KV cache and indexer instead of keeping its own. See
nemo_automodel.components.speculative.dfly2.
This recipe reuses every piece of the DSpark recipe — the frozen EP/FSDP target, anchor
sampling, gradient accumulation with a trailing-window flush, metrics, and checkpointing
— and swaps in the model-owned DFly2 draft, the target capture of the paired layers’
keys and key lists, and the D-PACE-weighted LK objective. target_layer_ids names the
paired target layers, one per draft layer.
Module Contents
Classes
Functions
Data
API
Bases: TrainDSparkRecipe
Recipe for DFly2 draft-model training on a colocated sparse-attention target.
Build the target package’s DFly2 draft and start its layers from their paired target layers.
Capture the paired layers’ keys and key lists instead of hidden states.
Build the DFly2 trainer wrapper (D-PACE-weighted LK plus confidence).
Shard the heads by dtype too: the corrections hold FP32 sinks and biases, the confidence head is FP32.
Run the frozen target once and train the draft on its paired layers’ keys.
Reject the DSpark options DFly2 does not support, then build everything via the DSpark recipe.
Refuse warm-start weights whose recorded DFly2 settings differ from this run’s.
The paired target layers, the block size and the mask token own no tensors, so a draft
trained with others loads cleanly and then reads the wrong keys. A released draft and an
export of this recipe record them in config.json under dfly_config.
Parameters:
The configured draft_weights_path, a directory or a .safetensors file.
Paired target layers of this run, in draft-layer order.
Draft slots per block of this run.
Mask token of this run.
Raises:
ValueError: A recorded setting differs from this run’s.
Entrypoint for TrainDFly2Recipe.