Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nav:
- user_guide/algorithms/index.md
- Eagle3: user_guide/algorithms/eagle3.md
- Dflash: user_guide/algorithms/dflash.md
- DFlash2: user_guide/algorithms/dflash2.md
- DSpark: user_guide/algorithms/dspark.md
- P-Eagle: user_guide/algorithms/peagle.md
- MTP: user_guide/algorithms/mtp.md
Expand Down
32 changes: 23 additions & 9 deletions docs/cli/train.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ torchrun --standalone --nproc_per_node=4 scripts/train.py \

- **`--trust-remote-code`** (flag) Allow executing code from HF Hub when loading the verifier's tokenizer.

- **`--speculator-type`** (str, default: `"eagle3"`) Type of speculator model to train. Options: `eagle3`, `dflash`, `dspark`, `peagle`, `mtp`
- **`--speculator-type`** (str, default: `"eagle3"`) Type of speculator model to train. Options: `eagle3`, `dflash`, `dflash2`, `dspark`, `peagle`, `mtp`

- **`--from-pretrained`** (str, default: `""`) Path or HF id of an existing draft checkpoint to load weights from and train — either a previously trained draft or the initialized-but-untrained checkpoint produced by `--dry-run`. May also point to a local directory containing only a `config.json`, in which case a fresh draft is initialized from that full speculator config. Takes precedence over all other model-definition options: it is mutually exclusive with `--draft-config` and the decoder-shaping flags (`--num-layers`, `--draft-arch`, `--draft-hidden-act`, `--sliding-window`, `--full-attention-indices`).

- **`--draft-config`** (str, default: `""`) HF id, directory, or JSON path of a decoder config (`LlamaConfig` for eagle3/peagle, `Qwen3Config` for dflash) used as the draft `transformer_layer_config`; the rest of the speculator is built from the other CLI args. The draft `hidden_size` must match the verifier (mismatch is not yet supported). If a full speculator config is passed, its nested `transformer_layer_config` is extracted. Mutually exclusive with `--from-pretrained` and with the decoder-shaping flags (`--num-layers`, `--draft-arch`, `--draft-hidden-act`, `--sliding-window`, `--full-attention-indices`).
- **`--draft-config`** (str, default: `""`) HF id, directory, or JSON path of a decoder config (`LlamaConfig` for eagle3/peagle, `Qwen3Config` for DFlash-family models) used as the draft `transformer_layer_config`; the rest of the speculator is built from the other CLI args. The draft `hidden_size` must match the verifier (mismatch is not yet supported). If a full speculator config is passed, its nested `transformer_layer_config` is extracted. Mutually exclusive with `--from-pretrained` and with the decoder-shaping flags (`--num-layers`, `--draft-arch`, `--draft-hidden-act`, `--sliding-window`, `--full-attention-indices`).

- **`--dry-run`** (flag) Build the speculator, initialize weights, save a checkpoint to `--save-path`, then exit before training. Useful to validate the config/weights in vLLM before launching a full run; the saved checkpoint can be fed straight back via `--from-pretrained`.

- **`--num-layers`** (int, default: `5` for dflash/dspark/dflash2, `1` otherwise) Number of transformer layers in the draft model.

- **`--draft-arch`** (str, default: `"llama"`) Architecture for the synthesized draft decoder layers. Options: `llama`, `qwen3`. Used by Eagle3 and P-EAGLE, which select the decoder layer class from this value; DFlash always uses a Qwen3-style decoder regardless. Both are supported in vLLM for inference, and the target and draft architectures do not have to match.
- **`--draft-arch`** (str, default: `"llama"`) Architecture for the synthesized draft decoder layers. Options: `llama`, `qwen3`. Used by Eagle3 and P-EAGLE, which select the decoder layer class from this value; DFlash-family models always use a Qwen3-style decoder regardless. Both are supported in vLLM for inference, and the target and draft architectures do not have to match.

- **`--draft-hidden-act`** (str, default: `"silu"`) Activation function for draft decoder layers. Setting as `None` will inherit activation function from the verifier model.

Expand Down Expand Up @@ -172,22 +172,36 @@ torchrun --standalone --nproc_per_node=4 scripts/train.py \

### Attention Backend Arguments

- **`--draft-attn-impl`** (str, default: `"simple_flex_attention"`) Attention implementation for draft layers. Options: `simple_flex_attention`, `sdpa`, `eager`. Use `sdpa` or `eager` on hardware where flex attention is unavailable (e.g. Ascend NPU). Applies to Eagle3, P-EAGLE, and DFlash. Not supported for MTP.
- **`--draft-attn-impl`** (str, default: `"simple_flex_attention"`) Attention implementation for draft layers. Options: `simple_flex_attention`, `sdpa`, `eager`. Use `sdpa` or `eager` on hardware where flex attention is unavailable (e.g. Ascend NPU). Applies to Eagle3, P-EAGLE, and DFlash-family models. Not supported for MTP.

### DFlash-Specific Arguments

- **`--block-size`** (int, default: `16` for dflash, `8` for dspark) Block size for DFlash model.
- **`--block-size`** (int, default: `16` for dflash, `8` otherwise) Block size for DFlash-family models.

- **`--sample-from-anchor`** / **`--no-sample-from-anchor`** (bool, default: algorithm-specific) Whether to sample from the anchor position. `True`: sample from anchor and all mask positions (default for dspark, produces block_size tokens). `False`: anchor is bonus token (default for dflash, produces block_size-1 tokens).
- **`--sample-from-anchor`** / **`--no-sample-from-anchor`** (bool, default: algorithm-specific) Whether to sample from the anchor position. `True`: sample from anchor and all mask positions (default for dspark, produces block_size tokens). `False`: anchor is bonus token (default for dflash/dflash2, produces block_size-1 tokens).

- **`--max-anchors`** (int, default: `3072`) Maximum anchor positions for DFlash, DSpark, and P-EAGLE training.
- **`--max-anchors`** (int, default: `512`) Maximum anchor positions for DFlash-family and P-EAGLE training.

- **`--dflash-decay-gamma`** (float, default: `4.0`) Decay gamma for DFlash loss weighting.
- **`--dflash-decay-gamma`** (float, default: `4.0`) Decay gamma for DFlash-family loss weighting.

- **`--per-position-loss-weight`** (str, default: `"dpace"` for dflash, `"fixed-exp-decay"` for dspark) Per-position loss weighting scheme. Options: `fixed-exp-decay`, `dpace`. Applies to DFlash and DSpark. `dpace` requires `--loss-fn ce`.
- **`--per-position-loss-weight`** (str, default: `"dpace"` for dflash, `"fixed-exp-decay"` otherwise) Per-position loss weighting scheme. Options: `fixed-exp-decay`, `dpace`. Applies to DFlash-family models. `dpace` requires `--loss-fn ce`.

- **`--dpace-alpha`** (float, default: `0.5`) Confidence smoothing constant for the D-PACE loss. Only used with `--per-position-loss-weight dpace`.

### DFlash2-Specific Arguments

DFlash2 builds on DFlash, so all DFlash-specific arguments apply as well. It defaults to five draft layers, block size 8, and KL loss.

- **`--conv-kernel-size`** (int, default: `2`) Local convolution kernel size.

- **`--conv-group-size`** (int, default: `16`) Channel group size for local convolution.

- **`--selector-rank`** (int, default: `256`) Low-rank dimension of the candidate selector.

- **`--selector-top-k`** (int, default: `16`) Number of candidates retained per position.

- **`--selector-loss-alpha`** (float, default: `1.0`) Weight of the candidate-selector K-way cross-entropy term.

### DSpark-Specific Arguments

DSpark builds on DFlash, so all DFlash-specific arguments apply as well.
Expand Down
25 changes: 14 additions & 11 deletions docs/user_guide/algorithms/decision_guide.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Algorithm Decision Guide

Speculators currently supports five speculative decoding algorithms: **Eagle-3**, **P-EAGLE**, **DFlash**, **DSpark**, and **MTP**. All are lossless -- they produce output from the same distribution as the target model.
Speculators currently supports six speculative decoding algorithms: **Eagle-3**, **P-EAGLE**, **DFlash**, **DFlash2**, **DSpark**, and **MTP**. All are lossless -- they produce output from the same distribution as the target model.

## How They Differ

Expand All @@ -10,32 +10,35 @@ Speculators currently supports five speculative decoding algorithms: **Eagle-3**

**DFlash** predicts all draft tokens in a single forward pass using block-based prediction with anchor points.

**DFlash2** extends DFlash with local dynamic convolutions and a low-rank candidate selector. Its current training objective is experimental because the public inference implementation does not include training code.

**DSpark** extends DFlash with a Markov head, so positions inside a block depend on earlier ones, plus a confidence head that predicts per-position acceptance.

**MTP** finetunes the model's native multi-token prediction head on domain-specific data. Unlike the other algorithms, MTP does not train from scratch -- it starts from pre-existing MTP layers and is only available for models with native MTP support.

Eagle-3, P-EAGLE, DFlash, and DSpark can be paired with any supported verifier model (including quantized variants) -- the draft architecture is independent of the verifier architecture. MTP requires a model with native MTP layers (e.g. Qwen3-Next, Qwen3.5).
Eagle-3, P-EAGLE, DFlash, and DSpark can be paired with any supported verifier model (including quantized variants) -- the draft architecture is independent of the verifier architecture. DFlash2 currently requires the verifier's full, unquantized language-model head because its selector operates in the complete verifier vocabulary. MTP requires a model with native MTP layers (e.g. Qwen3-Next, Qwen3.5).
Comment thread
shanjiaz marked this conversation as resolved.
Resolved

## Current Support

| | Eagle-3 | P-EAGLE | DFlash | DSpark | MTP |
| ------------------- | ------------- | ------------------- | ------------------- | ------------------- | --------------------------- |
| **Draft layers** | Llama-style | Llama-style | Qwen3-style | Qwen3-style | Native MTP layers |
| **Verifier models** | Any supported | Any supported | Any supported | Any supported | Models with native MTP only |
| **Training mode** | From scratch | From scratch | From scratch | From scratch | Finetune existing MTP head |
| **Speculators** | Mature | Newer, growing fast | Newer, growing fast | Newer, growing fast | Newer, growing fast |
| **vLLM** | Mature | Newer, growing fast | Newer, growing fast | Newer, growing fast | Newer, growing fast |
| | Eagle-3 | P-EAGLE | DFlash | DFlash2 | DSpark | MTP |
| ------------------- | ------------- | ------------------- | ------------------- | -------------------- | ------------------- | --------------------------- |
| **Draft layers** | Llama-style | Llama-style | Qwen3-style | Qwen3-style | Qwen3-style | Native MTP layers |
| **Verifier models** | Any supported | Any supported | Any supported | Full vocabulary only | Any supported | Models with native MTP only |
| **Training mode** | From scratch | From scratch | From scratch | Experimental | From scratch | Finetune existing MTP head |
| **Speculators** | Mature | Newer, growing fast | Newer, growing fast | Experimental | Newer, growing fast | Newer, growing fast |
| **vLLM** | Mature | Newer, growing fast | Newer, growing fast | Experimental | Newer, growing fast | Newer, growing fast |

Eagle-3 has been available longer and has broader support in both Speculators and vLLM. P-EAGLE, DFlash, DSpark, and MTP were added more recently and support is improving rapidly.
Eagle-3 has been available longer and has broader support in both Speculators and vLLM. P-EAGLE, DFlash, DSpark, and MTP were added more recently and support is improving rapidly. DFlash2 is an experimental prototype pending broader training and serving evaluation.

## Which Should I Use?

If you're unsure, start with Eagle-3 -- it has the most mature tooling and documentation. If you want parallel multi-token prediction with an Eagle-3-based architecture, try P-EAGLE. If you want to experiment with DFlash's single-forward-pass block prediction approach, the training workflow is the same, and DSpark adds intra-block dependencies and confidence scheduling on top of it. If your model already has native MTP layers (e.g. Qwen3-Next, Qwen3.5), MTP finetuning lets you improve the existing MTP head on domain-specific data without training a separate draft model.
If you're unsure, start with Eagle-3 -- it has the most mature tooling and documentation. If you want parallel multi-token prediction with an Eagle-3-based architecture, try P-EAGLE. If you want to experiment with DFlash's single-forward-pass block prediction approach, the training workflow is the same. DFlash2 adds local convolution and candidate reranking, while DSpark adds intra-block dependencies and confidence scheduling. If your model already has native MTP layers (e.g. Qwen3-Next, Qwen3.5), MTP finetuning lets you improve the existing MTP head on domain-specific data without training a separate draft model.

For more details on each algorithm, see:

- [Eagle-3](eagle3.md)
- [P-EAGLE](peagle.md)
- [DFlash](dflash.md)
- [DFlash2](dflash2.md)
- [DSpark](dspark.md)
- [MTP](mtp.md)
1 change: 1 addition & 0 deletions docs/user_guide/algorithms/dflash.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ DFlash is based on research from Z Lab: [DFlash Project Page](https://z-lab.ai/p

## See Also

- [DFlash2](dflash2.md) -- Adds local convolution and candidate selection
- [DSpark](dspark.md) -- Builds on DFlash with a sequential Markov head and a confidence head
- [Train a Speculator](../tutorials/train.md) -- Step-by-step training guide (select DFlash or DSpark, then online, offline, or hybrid)
66 changes: 66 additions & 0 deletions docs/user_guide/algorithms/dflash2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# DFlash2

DFlash2 extends [DFlash](dflash.md) with local dynamic convolutions and a candidate selector. The convolution lets neighboring positions exchange local information while the draft block remains parallel. The selector then adds a low-rank, predecessor-conditioned transition score to the draft model's unary token scores.

## How It Works

### Local Convolution

Each draft layer wraps both attention and the MLP with a grouped causal convolution. A projection of the current hidden state produces two dynamic kernels: one for the sublayer input and one for its output. A learned base kernel is shared across positions, while channels in each group share the dynamic component.

Convolution never crosses an anchor-block boundary. This matters during training because Speculators flattens multiple anchored blocks into one token dimension.

### Candidate Selector

The unary draft logits first select `selector_top_k` candidates at each position. The selector scores each transition as

```text
unary(candidate)
+ dot(predecessor_codebook(previous) * hidden_projection(hidden),
successor_codebook(candidate))
```

Inference starts with the anchor token and then conditions each position on the token selected at the preceding position. This preserves one parallel draft-model forward pass: only the small selector walks the candidate path.

## Training Objective

The public DFlash2 implementation specifies inference but does not publish its training objective. The current Speculators implementation is therefore an experimental split objective:

1. The configured DFlash-family compound loss trains the unary logits.
2. A separate hard cross-entropy term trains the selector over the unary top-K candidates while teacher-forcing the previous sequence token. If the target is outside that set, training replaces the weakest unary candidate with the target so the K-way loss remains defined. Validation loss uses the same replacement; serving and strict validation candidate/path metrics do not.

`--selector-loss-alpha` controls the second term. Both terms use the configured fixed exponential or D-PACE position weighting. The selector is never trained against a full-vocabulary corrected distribution, matching the candidate set it can rerank at serving time.

Validation reports clearly separated unary candidate recall and target mass, teacher-forced selector accuracy, and an actual greedy self-conditioned path. The path begins at the verified anchor and feeds each selected token to the next edge score. Its per-position accuracy is conditioned on the earlier path being correct. The accepted-length metrics include the verified anchor and report both the realized selector path and the oracle unary-top-K path.

DFlash2 currently requires the full verifier vocabulary. Pruned draft vocabularies are rejected because current serving implementations select candidates before any draft-to-target vocabulary mapping.

This experimental implementation directly trains full-vocabulary predecessor and successor codebooks. That is an expanded free-codebook parameterization: the public checkpoint format contains materialized codebooks, but the public sources do not disclose whether those tensors were free parameters during training. In particular, this prototype should not be interpreted as reproducing the selector parameter count reported in the DFlash2 blog.

## Key Parameters

| Parameter | Default | Description |
| ----------------------- | ------: | ---------------------------------------- |
| `--conv-kernel-size` | 2 | Number of causal convolution taps |
| `--conv-group-size` | 16 | Hidden channels sharing a dynamic kernel |
| `--selector-rank` | 256 | Rank of the transition factorization |
| `--selector-top-k` | 16 | Unary candidates reranked per position |
| `--selector-loss-alpha` | 1.0 | Weight of the selector K-way CE term |

All [DFlash](dflash.md) backbone parameters also apply. DFlash2 defaults to five draft layers, block size 8, `sample_from_anchor: False`, fixed exponential position weighting, and KL divergence loss. Set all shared knobs explicitly when comparing it with another algorithm.

To train your own, see `examples/train/dflash2_qwen3_8b_sharegpt_online_5k.sh`.

## Serving

Checkpoints emitted here follow the public Z Lab weight contract but use a speculators config. They can be served in vLLM using `vllm serve ./checkpoint`.

## Research and Implementation Reference

The architecture follows Z Lab's [DFlash2 implementation](https://github.com/z-lab/dflash/blob/07ebd93db9f472af339b644bb70221ad8428328a/dflash/model.py) and the [DFlash2 technical blog](https://inco.ai/blog/dflash2/). The pinned source revision defines the inference architecture and checkpoint contract; the experimental training objective above is specific to this implementation.
Comment thread
shanjiaz marked this conversation as resolved.
Resolved

## See Also

- [DFlash](dflash.md) -- The block-parallel draft backbone
- [DSpark](dspark.md) -- Adds a Markov head and confidence scheduling
- [Train a Speculator](../tutorials/train.md) -- End-to-end training workflow
Loading
Loading