Train a DFly2 Drafter for Speculative Decoding
This guide shows you how to train a DFly2 speculative-decoding drafter for DeepSeek-V4.1-Flash with NeMo AutoModel.
What Is DFly2?
DFly2 is a block-parallel drafter for sparse-attention targets. Each draft layer is paired with one of the target’s sparse-attention layers and owns no context projection of its own:
- KV sharing: The draft layer reads the keys its paired target layer attends over, so the served drafter keeps no KV cache of its own.
- Index sharing: It reads them at the positions that layer attends from the row before the block’s anchor, so the drafter runs no indexer and its context read has a fixed size at any context length.
On DeepSeek-V4.1-Flash, the paired layers are the ratio-1 layers 28, 32, and 36.
Each one attends over its own 128-token sliding window plus the shared global
latents at its indexer’s top-512 picks. Around the backbone, the target’s final
hidden state is fused into the anchor slot, and a hidden correction (a SwiGLU
plus an attentive correction over the last layer’s context and the block’s
prefix) adjusts every slot before the frozen LM head. A block of block_size
slots holds the anchor and drafts block_size - 1 tokens.
The draft shares and freezes the target’s embedding and LM head. The recipe,
TrainDFly2Recipe, reuses the DSpark recipe’s frozen EP and FSDP2 target, anchor
sampling, gradient accumulation, metrics, and checkpointing.
Objective
Each drafted slot is trained toward the target’s distribution at the token before its label:
The logs report the corpus cross-entropy (ce), the TV term (tv), the
per-position acceptance accept_rate@k, and the expected accepted block length
tau.
As in the DSpark recipe, a block is supervised up to its first unsupervised label, and the D-PACE weights ignore slots past the end of the sequence.
Data
Use a chat dataset of OpenAI-format messages rows with the responses
regenerated by the target model, as for DSpark: training is teacher-forced, and
regenerating avoids a training and inference distribution mismatch. Point
recipe_args.train_data_path at the dataset and set chat_template to the
target’s training template.
Train
The example configuration follows the released
AngelSlim/DS-V4.1-Flash-DFly2-B6
layout. Launch the same command on every node, varying --node-rank:
The key settings in recipe_args are:
Without draft_weights_path, each draft layer’s attention, norms, mHC mixes, and
shared expert start from its paired target layer. The routed experts and the router
start fresh, where the paper draws 128 of the paired layer’s experts with their router
rows (its “attention only” ablation reaches 3.51 instead of 3.57 accepted tokens). A
warm start checks the paired layers, block size, and mask token recorded in the
checkpoint’s config.json against the run’s.
The example trains with AdamW and FP32 master weights at a global batch of 256
sequences. The paper uses Muon. Its learning rate is for a fresh draft: when
warm-starting from the released draft, lower it (for example, to 5.0e-6), or the
first steps move the converged draft away from its optimum.
The DFly2 path trains against a colocated text target on unpacked rows. Sequence packing, image inputs, the precomputed and remote target backends, and TP, PP, and CP are not supported.
Checkpoints
Consolidated checkpoints use the released layout (model.layers.*,
model.mtp_fusion.*, model.hidden_correction.*), so a trained draft and the
released one load the same way.